public void debug_print_json_writer() { var testObject = new TestObject() { Id = "MY_ID_HERE", Name = "MY_NAME_HERE", SomeNumber = 123, Tags = new[] { "tag1", "tag2", "tag3" }, Children = new[] { new TestObject { Name = "ArrayC1" } }, ChildrenList = new List <TestObject> { new TestObject() { Name = "ListC2" } }, ChildrenIList = new List <TestObject> { new TestObject() { Name = "ListC3" } } }; var datum = DatumConvert.SerializeObject(testObject); Console.WriteLine(datum.ToDebugString()); }
public void ser_deser_a_datetimeoffset() { var obj = new ADateTimeOffset() { Id = "my_id", TheDateTimeOffset = DateTimeOffset.Parse("30 Oct 2013 4:12:02 PM -07:00") }; var truth = new Datum { type = Datum.DatumType.R_OBJECT }; truth.r_object.Add(new Datum.AssocPair { key = "Id", val = new Datum { type = Datum.DatumType.R_STR, r_str = "my_id" } }); truth.r_object.Add(new Datum.AssocPair { key = "TheDateTimeOffset", val = new Datum { type = Datum.DatumType.R_OBJECT, r_object = { new Datum.AssocPair { key = "$reql_type$", val = new Datum{ type = Datum.DatumType.R_STR, r_str = "TIME" } }, new Datum.AssocPair { key = "epoch_time", val = new Datum{ type = Datum.DatumType.R_NUM, r_num = 1383174722 } }, new Datum.AssocPair { key = "timezone", val = new Datum{ type = Datum.DatumType.R_STR, r_str = "-07:00" } }, } } }); //ser test var ser = DatumConvert.SerializeObject(obj); ser.ShouldBeEquivalentTo(truth); //deser test var newtonObj = DatumConvert.DeserializeObject <ADateTimeOffset>(truth); newtonObj.ShouldBeEquivalentTo(obj); }
public void ser_deser_datetimenullable_dateset() { var obj = new DateTimeNullable() { Id = "my_id", NullableDateTime = DateTime.Parse("10/30/2013 4:55 PM") }; var truth = new Datum { type = Datum.DatumType.R_OBJECT }; truth.r_object.Add(new Datum.AssocPair { key = "Id", val = new Datum { type = Datum.DatumType.R_STR, r_str = "my_id" } }); truth.r_object.Add(new Datum.AssocPair { key = "NullableDateTime", val = new Datum { type = Datum.DatumType.R_OBJECT, r_object = { new Datum.AssocPair { key = "$reql_type$", val = new Datum{ type = Datum.DatumType.R_STR, r_str = "TIME" } }, new Datum.AssocPair { key = "epoch_time", val = new Datum{ type = Datum.DatumType.R_NUM, r_num = 1383152100 } }, new Datum.AssocPair { key = "timezone", val = new Datum{ type = Datum.DatumType.R_STR, r_str = "+00:00" } }, } } }); //ser test var ser = DatumConvert.SerializeObject(obj); ser.ShouldBeEquivalentTo(truth); //deser test var newtonObj = DatumConvert.DeserializeObject <DateTimeNullable>(truth); newtonObj.ShouldBeEquivalentTo(obj); }
public void serialize_datetimeobject() { var obj = GetDefaultObject(); var datum = DatumConvert.SerializeObject(obj); var truth = GetDefaultDatum(); truth.ShouldBeEquivalentTo(datum); }
public void ser_deser_a_datetime() { var obj = new ADateTime { Id = "my_id_value", TheDate = DateTime.Parse("10/30/2013 4:55 PM") }; var truth = new Datum { type = Datum.DatumType.R_OBJECT }; truth.r_object.Add(new Datum.AssocPair { key = "Id", val = new Datum { type = Datum.DatumType.R_STR, r_str = "my_id_value" } }); truth.r_object.Add(new Datum.AssocPair { key = "TheDate", val = new Datum { type = Datum.DatumType.R_OBJECT, r_object = { new Datum.AssocPair { key = "$reql_type$", val = new Datum{ type = Datum.DatumType.R_STR, r_str = "TIME" } }, new Datum.AssocPair { key = "epoch_time", val = new Datum{ type = Datum.DatumType.R_NUM, r_num = 1383152100 } }, new Datum.AssocPair { key = "timezone", val = new Datum{ type = Datum.DatumType.R_STR, r_str = "+00:00" } }, } } }); var newtonDatum = DatumConvert.SerializeObject(obj); truth.ShouldBeEquivalentTo(newtonDatum); var newtonObject = DatumConvert.DeserializeObject <ADateTime>(truth); newtonObject.ShouldBeEquivalentTo(obj); }
//Quick test to show the equivalence of Newton's serialization and the native driver's DataContract serialization. public void native_and_newton_basic_comparison_test1() { var testObject = TestObjectWithTestData(); var nativeDatum = Native.RootFactory.Get <TestObject>().ConvertObject(testObject); var newtonDatum = DatumConvert.SerializeObject(testObject); newtonDatum.ShouldBeEquivalentTo(nativeDatum); }
public void serialize_complex_object() { var obj = NewObjectWithDefaults(); var newtonDatum = DatumConvert.SerializeObject(obj, new TimeSpanConverter()); var truthDatum = GetDatum_InlineOrder(); truthDatum.ShouldBeEquivalentTo(newtonDatum); }
//Converting an object to and from a datum should be the same. public void newton_datum_regurgitation_should_be_equivlant() { var objIn = TestObjectWithTestData(); var newtonDatum = DatumConvert.SerializeObject(objIn); var objOut = DatumConvert.DeserializeObject <TestObject>(newtonDatum); var newtonDatum2 = DatumConvert.SerializeObject(objOut); newtonDatum.ShouldBeEquivalentTo(newtonDatum2); newtonDatum.r_object.Count.Should().Be(9); // sanity check }
public void should_be_able_to_serialize_timespan_to_floatseconds() { var span = new TimeSpan(days: 1, hours: 2, minutes: 3, seconds: 4, milliseconds: 5); var truth = new Datum() { type = Datum.DatumType.R_NUM, r_num = span.TotalSeconds }; var datum = DatumConvert.SerializeObject(span, new TimeSpanConverter()); truth.ShouldBeEquivalentTo(datum); }
// TestObject and TestObjectNewton are the same, but shows the difference between the attributing style and elegance. public void similar_object_models_with_different_attributing_should_be_equivalent() { var withAttributes = TestObjectWithTestData(); var withoutAttributes = TestObjectNewtonWithTestData(); var datumFromContractAttributes = Native.RootFactory.Get <TestObject>().ConvertObject(withAttributes); var jsonSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var datumFromNewton = DatumConvert.SerializeObject(withoutAttributes, jsonSettings); datumFromContractAttributes.ShouldBeEquivalentTo(datumFromNewton); }
public void ser_deser_datetimeoffsetnullable_nullset() { var obj = new DateTimeOffsetNullable() { Id = "my_id", TheDateTimeOffset = null }; var truth = new Datum { type = Datum.DatumType.R_OBJECT }; truth.r_object.Add(new Datum.AssocPair { key = "Id", val = new Datum { type = Datum.DatumType.R_STR, r_str = "my_id" } }); truth.r_object.Add(new Datum.AssocPair { key = "TheDateTimeOffset", val = new Datum { type = Datum.DatumType.R_NULL, } }); //ser test var ser = DatumConvert.SerializeObject(obj); ser.ShouldBeEquivalentTo(truth); //deser test var newtonObj = DatumConvert.DeserializeObject <DateTimeOffsetNullable>(truth); newtonObj.ShouldBeEquivalentTo(obj); }
public void debug_print_json_reader() { var objIn = new TestObject() { Id = "MY_ID_HERE", Name = "MY_NAME_HERE", SomeNumber = 123, Tags = new[] { "tag1", "tag2", "tag3" }, Children = new[] { new TestObject { Name = "ArrayC1" } }, ChildrenList = new List <TestObject> { new TestObject() { Name = "ListC2" } }, ChildrenIList = new List <TestObject> { new TestObject() { Name = "ListC3" } } }; var datum = DatumConvert.SerializeObject(objIn); Console.WriteLine(datum.ToDebugString()); var objOut = DatumConvert.DeserializeObject <TestObject>(datum); objIn.ShouldBeEquivalentTo(objOut); }
public override Datum ConvertObject(T value) { return(DatumConvert.SerializeObject(value, ConfigurationAssembler.DefaultJsonSerializerSettings)); }