public void testInitSDJWithObject() { object nullObj = null; var sdj = new SelfDescribingJson("iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4", nullObj); Assert.AreEqual(@"{""schema"":""iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4""}", sdj.ToString()); object dictObj = new Dictionary <string, object> { { "hello", "world" } }; sdj.SetData(dictObj); Assert.AreEqual(@"{""schema"":""iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4"",""data"":{""hello"":""world""}}", sdj.ToString()); }
public void TestInitWithSdj() { Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("demo", 5); SelfDescribingJson data = new SelfDescribingJson("iglu:acme.com/demo_app/jsonschema/1-0-0", dict); SelfDescribingJson sdj = new SelfDescribingJson("iglu:acme.com/demo/jsonschema/1-0-0", data); Assert.NotNull(sdj); Assert.AreEqual(126, sdj.GetByteSize()); CollectionAssert.AreEquivalent(JSON.Deserialize <Dictionary <string, object> >("{\"data\":{\"data\":{\"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-0\"}, \"schema\":\"iglu:acme.com/demo/jsonschema/1-0-0\"}"), JSON.Deserialize <Dictionary <string, object> >(sdj.ToString())); dict.Add("app", "hello"); data.SetData(dict); sdj.SetData(data); CollectionAssert.AreEquivalent(JSON.Deserialize <Dictionary <string, object> >("{\"data\":{\"data\":{\"app\":\"hello\", \"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-0\"}, \"schema\":\"iglu:acme.com/demo/jsonschema/1-0-0\"}"), JSON.Deserialize <Dictionary <string, object> >(sdj.ToString())); }
public void TestInitWithObject() { Dictionary <string, object> dict = new Dictionary <string, object> (); dict.Add("demo", 5); SelfDescribingJson sdj = new SelfDescribingJson("iglu:acme.com/demo_app/jsonschema/1-0-0", dict); Assert.NotNull(sdj); Assert.AreEqual(71, sdj.GetByteSize()); Assert.AreEqual("{\"data\":{\"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-0\"}", sdj.ToString()); sdj.SetSchema("iglu:acme.com/demo_app/jsonschema/1-0-1"); Assert.AreEqual("{\"data\":{\"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-1\"}", sdj.ToString()); dict.Add("app", "hello"); sdj.SetData(dict); Assert.AreEqual("{\"data\":{\"app\":\"hello\", \"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-1\"}", sdj.ToString()); }