1. Thomas Rolseth
  2. SnapDevelop
  3. Tuesday, 18 February 2020 17:08 PM UTC

I am creating a unit test (XUnit) for a service in SnapDevelop.  The service method takes a DataUnPacker object as a parameter.  This gets passed to the API from PowerBuilder using the jsonpackage object.  My question is how can I populate this in a C# unit test before calling the service?  I have the following code so far -- see below.  My idea was to insert some rows into a datastore, instantiate a new packer object, add the datastore to it and then pass it to the service (in bold).  It doesn't like the datatype however and I can't compile.  Is there a way to convert the packer object to an unpacker object?  Is there a better way to handle this situation?

Thanks, Tom


var ds = new DataStore("d_department", context);

// Inserts an empty row before the first row of datastore.
ds.SetItem(0, "action", "A");

var packer = new DataPacker();

packer.AddDataStore("Departments", ds);

var result = service.GetDepartments(packer, out errmsg);

Thomas Rolseth Accepted Answer Pending Moderation
  1. Friday, 21 February 2020 15:23 PM UTC
  2. SnapDevelop
  3. # 1


Could provide an actual code example of how to use/call DataUnpacker.DataUnpacker(string raw, DataFormat format)?

I got around the problem for one of my unit tests by doing this:

                    string json = ds.ExportJson(MappingMethod.Key);
                     string new_json = "{\"Values\":" + json + "}";

                    //put the json into an unpacker object
                    var unpacker = new DataUnpacker(new_json, DataFormat.Json);

                    //call the service
                    var result = service.HelloWorld(unpacker, out string errmsg);

I tried the same approach for another unit test and it doesn't work.  When I debug the test it gets to this point in the service method:

            var param1 = unpacker.GetValue<string>("dataobject");

When I hover over the 'unpacker' reference I see the raw json and there is a value for the dataobject.  But when I go past this line in the debugger the value of 'param1' is an empty string.  It's not extracting the value for dataobject like I would expect.

Thanks, Tom

  1. Logan Liu @Appeon
  2. Saturday, 22 February 2020 17:12 PM UTC
You don't need to combine JSON string by yourself.

I think you could call IDataPacker.AddDataStore to add a DataStore:


After converting it to IDataUnpacker, call IDataUnpacker.GetDataStore to get a DataStore:

  1. Helpful
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 19 February 2020 18:21 PM UTC
  2. SnapDevelop
  3. # 2

Hi Tom,

"Is there a way to convert the packer object to an unpacker object?"

1) Call IDataPacker.GetTextString(DataFormat format) to get a JSON string, refer to:


2) Then call DataUnpacker.DataUnpacker(string raw, DataFormat format) Constructor, refer to:


Regards, Logan

There are no comments made yet.
  • Page :
  • 1

There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.