public void ToObjectEnumPropertyFromString() { var dict = new Dictionary<string, object>() { { "EnumProperty", "One" }, }; var value = dict.ToObject<ClassType>(); Assert.Equal(EnumType.One, value.EnumProperty); }
public void ToObjectPrimitiveProperties() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); }
public void AsObjectUnknownProperty() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "UnknownProperty", "u" } }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); }
public void ToObjectUnknownProperty() { var dict = new Dictionary <string, object> { { "StringProperty", "a" }, { "IntProperty", 1 }, { "UnknownProperty", "u" } }; var value = dict.ToObject <ClassType>(TypeCache); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); }
public void Single() { // Arrange var dict = new Dictionary <string, string>() { { "Id", "366f4bd3-6717-4b14-9c79-70515296df7e" } }; // Act var actual = dict.ToObject <SingleData>(); // Assert Assert.AreEqual(new Guid("366f4bd3-6717-4b14-9c79-70515296df7e"), actual.Id); }
public void ToObjectSpatialV4() { CustomConverters.RegisterTypeConverter(typeof(SpatialV4.GeographyPoint), V4.Adapter.TypeConverters.CreateGeographyPoint); var dict = new Dictionary <string, object>() { { "PointV4", SpatialV4.GeographyPoint.Create(SpatialV4.CoordinateSystem.Geography(100), 1, 2, null, null) }, }; var value = dict.ToObject <ClassType>(); Assert.Equal(100, value.PointV4.CoordinateSystem.EpsgId); Assert.Equal(1d, value.PointV4.Latitude); Assert.Equal(2d, value.PointV4.Longitude); }
public void ToObjectDynamicODataEntry() { var _ = ODataDynamic.Expression; var dict = new Dictionary <string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, }; dynamic value = dict.ToObject <ODataEntry>(null, true); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); }
public void ToObjectBaseType_Type() { var dict = new Dictionary <string, object> { { FluentCommand.AnnotationsLiteral, new ODataEntryAnnotations { TypeName = "Northwind.Transport" } }, { "TransportID", 1 }, }; var value = dict.ToObject <Transport>(_typeCache); Assert.Equal(1, value.TransportID); }
public void AsObjectField() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "StringField", "f" } }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); Assert.Equal(null, value.StringField); }
public void AsObjectPrivateSetter() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "StringPropertyPrivateSetter", "p" } }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); Assert.Equal("p", value.StringPropertyPrivateSetter); }
public void ToObjectField() { var dict = new Dictionary <string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "StringField", "f" } }; var value = dict.ToObject <ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); Assert.Null(value.StringField); }
public void converts_property_names_to_camel_case() { var d = new Dictionary <string, object> () { { "a", "1" }, { "ab", "2" }, { "abCd", "3" }, }; var o = d.ToObject <GoodNames> (); Assert.AreEqual("1", o.A); Assert.AreEqual("2", o.Ab); Assert.AreEqual("3", o.AbCd); }
public void DifferentTypes() { // Arrange var dict = new Dictionary <string, string>() { { "Id", "11" }, // Should be a Guid { "Date", "1999-01-01" }, { "Enum", "One" }, { "Array", "1,2,3" }, { "Text", "eleven" }, }; // Act dict.ToObject <RecursiveData>(); }
public void MissingProperty() { // Arrange var dict = new Dictionary <string, string>() { { "Id", "366f4bd3-6717-4b14-9c79-70515296df7e" }, { "Date", "1999-01-01" }, { "Enum", "One" }, { "Text", "eleven" }, { "Integer", "11" }, // There's no Integer }; // Act dict.ToObject <RecursiveData>(); }
public void DifferentTypes() { // Arrange var dict = new Dictionary<string, object>() { { "Id", 11 }, // Should be a Guid { "Date", new DateTime(1999, 1, 1) }, { "Enum", Enumeration.One }, { "Array", new[] { 1, 2, 3, } }, { "Text", "eleven" }, }; // Act dict.ToObject<RecursiveData>(); }
public void ToObjectPrivateSetter() { var dict = new Dictionary <string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "StringPropertyPrivateSetter", "p" } }; var value = dict.ToObject <ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); Assert.Equal("p", value.StringPropertyPrivateSetter); }
public void DifferentTypes() { // Arrange var dict = new Dictionary<string, string>() { { "Id", "11" }, // Should be a Guid { "Date", "1999-01-01" }, { "Enum", "One" }, { "Array", "1,2,3" }, { "Text", "eleven" }, }; // Act dict.ToObject<RecursiveData>(); }
public void DifferentTypes() { // Arrange var dict = new Dictionary <string, object>() { { "Id", 11 }, // Should be a Guid { "Date", new DateTime(1999, 1, 1) }, { "Enum", Enumeration.One }, { "Array", new[] { 1, 2, 3, } }, { "Text", "eleven" }, }; // Act dict.ToObject <RecursiveData>(); }
public void UsesNeo4jPropertyAttribute_WhenSettingProperties() { var dictionary = new Dictionary <string, object> { { "StringProperty", "a string" }, { "stringPropertyWithAttribute", "stringWithAttribute" }, { nameof(Foo.StringPropertyIgnored), "ignored" } }; var foo = dictionary.ToObject <Foo>(); foo.StringProperty.Should().Be("a string"); foo.StringPropertyWithAttribute.Should().Be("stringWithAttribute"); foo.StringPropertyIgnored.Should().BeNull(); }
public void MissingProperty() { // Arrange var dict = new Dictionary <string, object>() { { "Id", new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") }, { "Date", new DateTime(1999, 1, 1) }, { "Enum", Enumeration.One }, { "Text", "eleven" }, { "Array", new[] { 1, 2, 3, } }, { "Integer", 11 }, // There's no Integer }; // Act dict.ToObject <RecursiveData>(); }
public void ADictionary_Returns_ANewObject() { // Arrange var dictionary = new Dictionary <string, object> { { "Name", "Name of the car" } }; // Act var result = dictionary.ToObject <Car>(); // Assert Assert.Equal("Name of the car", result.Name); Assert.Null(result.Color); Assert.Null(result.Owner); }
public void IgnoresExtraValuesInTheDictionary() { var dictionary = new Dictionary <string, object> { { "StringProperty", "a string" }, { "stringPropertyWithAttribute", "stringWithAttribute" }, { nameof(Foo.StringPropertyIgnored), "ignored" }, { "Extra Value", "FooBar" } }; var foo = dictionary.ToObject <Foo>(); foo.StringProperty.Should().Be("a string"); foo.StringPropertyWithAttribute.Should().Be("stringWithAttribute"); foo.StringPropertyIgnored.Should().BeNull(); }
public DotaPermanentBuffs[] LoadPermanentBuffs() { string resultString; using (var streamReader = new StreamReader(assembly.GetManifestResourceStream("OpenDotaApi.ref.permanent_buffs.json"))) { resultString = streamReader.ReadToEnd(); } if (resultString != null) { return(JObject.Parse(resultString)["permanent_buffs"] .Children() .Select(permanentBuffs => permanentBuffs.ToObject <DotaPermanentBuffs>()) .ToArray()); } return(null); }
public void ToObjectSpatialV3() { var dict = new Dictionary <string, object> { { "PointV3", SpatialV3.GeographyPoint.Create(SpatialV3.CoordinateSystem.Geography(100), 1, 2, null, null) }, }; var typeCache = TypeCaches.Global; typeCache.Converter.RegisterTypeConverter(typeof(SpatialV3.GeographyPoint), V3.Adapter.TypeConverters.CreateGeographyPoint); var value = dict.ToObject <ClassType>(typeCache); Assert.Equal(100, value.PointV3.CoordinateSystem.EpsgId); Assert.Equal(1d, value.PointV3.Latitude); Assert.Equal(2d, value.PointV3.Longitude); }
public void Should_serialize_array() { var doc = new Dictionary <string, object>() .Array("PrimitiveStringArray", new[] { "one", "two", "three" }) .Array("PrimitiveIntArray", new[] { 1, 2, 3 }) .Array("GenericObjectArray", new[] { new Dummy { Foo = "one", Bar = 1 }, new Dummy { Foo = "two", Bar = 2 }, new Dummy { Foo = "three", Bar = 3 } }); var entity = doc.ToObject <ArrayEntity>(); // string array Assert.AreEqual(doc.Size("PrimitiveStringArray"), entity.PrimitiveStringArray.Length); for (int i = 0; i < doc.Size("PrimitiveStringArray"); i++) { Assert.AreEqual(doc.Object <string[]>("PrimitiveStringArray")[i], entity.PrimitiveStringArray[i]); } // int array Assert.AreEqual(doc.Size("PrimitiveIntArray"), entity.PrimitiveIntArray.Length); for (int i = 0; i < doc.Size("PrimitiveIntArray"); i++) { Assert.AreEqual(doc.Object <int[]>("PrimitiveIntArray")[i], entity.PrimitiveIntArray[i]); } // generic object array Assert.AreEqual(doc.Size("GenericObjectArray"), entity.GenericObjectArray.Length); for (int i = 0; i < doc.Size("GenericObjectArray"); i++) { var dummy = doc.Object <Dummy[]>("GenericObjectArray")[i]; Assert.AreEqual(dummy.Foo, entity.GenericObjectArray[i].Foo); Assert.AreEqual(dummy.Bar, entity.GenericObjectArray[i].Bar); } }
public void Single() { // Arrange var expected = new SingleData { Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") }; var dict = new Dictionary <string, object>() { { "Id", new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") }, }; // Act var actual = dict.ToObject <SingleData>(); // Assert Assert.AreEqual(expected.Id, actual.Id); }
public void Should_deserialize_document_to_generic_object_custom_attributes() { var doc = new Dictionary <string, object>() .String("Foo", "foo string value") .String("myCustomField", "string value") .String("IngnoredPropety", "should not be there") .Object("NullProperty", null) .String("NotNullProperty", "some string"); var dummy = doc.ToObject <Dummy>(); Assert.AreEqual("foo string value", dummy.Foo); Assert.AreEqual("string value", dummy.PropertyToBeAliased); Assert.AreEqual("string value", dummy.PropertyToBeAliased); Assert.AreEqual(null, dummy.NullProperty); Assert.AreEqual("some string", dummy.NotNullProperty); Assert.AreEqual(null, dummy.IngnoredPropety); }
public void ToObjectStringArray() { var dict = new Dictionary <string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "StringArrayProperty", new [] { "x", "y", "z" } } }; var value = dict.ToObject <ClassType>(new StaticTypeCache()); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); for (var index = 0; index < 3; index++) { Assert.Equal((dict["StringArrayProperty"] as IList <string>)[index], value.StringArrayProperty[index]); } }
public void ToObjectBaseType_SubType() { var dict = new Dictionary <string, object> { { FluentCommand.AnnotationsLiteral, new ODataEntryAnnotations { TypeName = "Northwind.Ship" } }, { "TransportID", 1 }, { "ShipName", "Sloop John B" }, }; var value = dict.ToObject <Transport>(_typeCache); var ship = value as Ship; Assert.NotNull(ship); Assert.Equal(1, ship.TransportID); Assert.Equal("Sloop John B", ship.ShipName); }
public void ToObjectCompoundProperty() { var dict = new Dictionary <string, object> { { "StringProperty", "a" }, { "IntProperty", 1 }, { "CompoundProperty", new Dictionary <string, object> { { "StringProperty", "z" }, { "IntProperty", 0 } } } }; var value = dict.ToObject <ClassType>(_typeCache); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); Assert.Equal("z", value.CompoundProperty.StringProperty); Assert.Equal(0, value.CompoundProperty.IntProperty); }
public void ToObjectDynamicODataEntry() { var _ = ODataDynamic.Expression; var dict = new Dictionary <string, object> { { "StringProperty", "a" }, { "IntProperty", 1 }, }; var typeCache = TypeCaches.Global; typeCache.Register <ODataEntry>(); dynamic value = dict.ToObject <ODataEntry>(typeCache, true); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); }
public void ToObjectIntCollection() { var dict = new Dictionary <string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "IntCollectionProperty", new [] { 1, 2, 3 } } }; var value = dict.ToObject <ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); for (var index = 0; index < 3; index++) { Assert.Equal((dict["IntCollectionProperty"] as IList <int>)[index], value.IntCollectionProperty[index]); } }
public void ToObject_GivenDictionary_ShouldReturnObject() { // Arrange var data = new Dictionary <string, object> { { "Id", 1 }, { "Name", "Name Value" }, { "Discarded", "Discarded" } }; // Act var result = data.ToObject <TestType>(); // Assert Assert.NotNull(result); Assert.IsType <TestType>(result); Assert.Equal((int)data["Id"], result.Id); Assert.Equal(data["Name"].ToString(), result.Name); }
public void Test_Dictionary_ToObject() { // Arrange var dictionary = new Dictionary <string, object> { { "PropA", "test" }, { "PropB", 1 }, { "PropC", true }, { "PropD", new SubItem { PropE = "PropE", PropF = new List <int> { 1, 2, 3 } } } }; var objToDictionary = new Test { PropA = "test", PropB = 1, PropC = true, PropD = new SubItem { PropE = "PropE", PropF = new List <int> { 1, 2, 3 } } }; // Act var objTest = dictionary.ToObject <Test>(); var dict = objToDictionary.AsDictionary(); // Assert objTest.PropA.Should().Be("test"); objTest.PropB.Should().Be(1); objTest.PropC.Should().BeTrue(); dict.Keys.Contains("PropA").Should().BeTrue(); }
public void ADictionary_Returns_ANewComplexObject() { // Arrange var owner = new Owner { FirstName = "Freddy", LastName = "Mercury" }; var dictionary = new Dictionary <string, object> { { "Name", "Name of the car" }, { "Owner", owner } }; // Act var result = dictionary.ToObject <Car>(); // Assert Assert.Equal("Name of the car", result.Name); Assert.Null(result.Color); Assert.Same(owner, result.Owner); }
public void Single() { // Arrange var dict = new Dictionary<string, string>() { { "Id", "366f4bd3-6717-4b14-9c79-70515296df7e" } }; // Act var actual = dict.ToObject<SingleData>(); // Assert Assert.AreEqual(new Guid("366f4bd3-6717-4b14-9c79-70515296df7e"), actual.Id); }
public void MissingProperty() { // Arrange var dict = new Dictionary<string, string>() { { "Id", "366f4bd3-6717-4b14-9c79-70515296df7e" }, { "Date", "1999-01-01" }, { "Enum", "One" }, { "Text", "eleven" }, { "Integer", "11" }, // There's no Integer }; // Act dict.ToObject<RecursiveData>(); }
public void NestedDictionary() { var expected = new RecursiveData { Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e"), Date = new DateTime(1999, 1, 1), Enum = Enumeration.One, Text = "level 1", Array = new[] { 1, 2, 3, }, Nested = new RecursiveData { Id = new Guid("e591be31-289f-4a99-ba67-288ea24b7d7e"), Date = new DateTime(1999, 2, 2), Enum = Enumeration.Two, Text = "level 2", Array = new[] { 4, 5, 6, }, Nested = null, }, }; var dict = new Dictionary<string, object>() { // 1st level { "Id", expected.Id }, { "Date", expected.Date }, { "Enum", expected.Enum }, { "Text", expected.Text }, { "Array", expected.Array }, // 2nd level { "Nested", new Dictionary<string, object> { { "Id", expected.Nested.Id }, { "Date", expected.Nested.Date }, { "Enum", expected.Nested.Enum }, { "Text", expected.Nested.Text }, { "Array", expected.Nested.Array }, { "Nested", expected.Nested.Nested }, } } }; var actual = dict.ToObject<RecursiveData>(); // 1st level Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.Date, actual.Date); Assert.AreEqual(expected.Enum, actual.Enum); Assert.AreEqual(expected.Text, actual.Text); CollectionAssert.AreEqual(expected.Array, actual.Array); // 2nd level Assert.AreEqual(expected.Nested.Id, actual.Nested.Id); Assert.AreEqual(expected.Nested.Date, actual.Nested.Date); Assert.AreEqual(expected.Nested.Enum, actual.Nested.Enum); Assert.AreEqual(expected.Nested.Text, actual.Nested.Text); CollectionAssert.AreEqual(expected.Nested.Array, actual.Nested.Array); }
public void MissingProperty() { // Arrange var dict = new Dictionary<string, object>() { { "Id", new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") }, { "Date", new DateTime(1999, 1, 1) }, { "Enum", Enumeration.One }, { "Text", "eleven" }, { "Array", new[] { 1, 2, 3, } }, { "Integer", 11 }, // There's no Integer }; // Act dict.ToObject<RecursiveData>(); }
public void ToObjectCompoundProperty() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "CompoundProperty", new Dictionary<string, object>() { { "StringProperty", "z" }, { "IntProperty", 0 } } } }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); Assert.Equal("z", value.CompoundProperty.StringProperty); Assert.Equal(0, value.CompoundProperty.IntProperty); }
public void Single() { // Arrange var expected = new SingleData { Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") }; var dict = new Dictionary<string, object>() { { "Id", new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") }, }; // Act var actual = dict.ToObject<SingleData>(); // Assert Assert.AreEqual(expected.Id, actual.Id); }
/// <summary> /// Initializes a new instance of the <see cref="BaseCaseTermStrategy"/> class. /// </summary> /// <param name="userConnection">The user connection.</param> /// <param name="args">The arguments.</param> protected BaseCaseTermStrategy(UserConnection userConnection, Dictionary <string, object> args) : this(userConnection) { BaseStrategyDataItem = args.ToObject <BaseStrategyData>(); }
public void MapsFromDictionaryNonGeneric() { var dictionary = new Dictionary<string, object> { { "PublicProperty", "Public Property" }, { "IgnoreMe", "la la la" } }; var testClass = dictionary.ToObject(typeof(TestClass)) as TestClass; Assert.AreEqual("Public Property", testClass.PublicProperty); }
public void MapsFromDictionary() { var dictionary = new Dictionary<string, object> { { "PublicProperty", "Public Property" }, { "IgnoreMe", "la la la"} }; var testClass = dictionary.ToObject<TestClass>(); Assert.AreEqual("Public Property", testClass.PublicProperty); }
public void ToObjectClassWithoutDefaultCtor() { var dict = new Dictionary<string, object>() { { "Data", new ClassNoDefaultConstructor("test") }, }; Assert.Throws<InvalidOperationException>(() => dict.ToObject<ClassNoDefaultConstructor>()); }
public void ToObjectDynamicODataEntry() { var _ = ODataDynamic.Expression; var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, }; dynamic value = dict.ToObject<ODataEntry>(true); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); }
public void ToObjectODataEntry() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, }; var value = dict.ToObject<ODataEntry>(false); Assert.Equal("a", value["StringProperty"]); Assert.Equal(1, value["IntProperty"]); }
public void ToObjectCompoundCollectionProperty() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "CompoundCollectionProperty", new[] { new Dictionary<string, object>() { { "StringProperty", "x" }, { "IntProperty", 1 } }, new Dictionary<string, object>() { { "StringProperty", "y" }, { "IntProperty", 2 } }, new Dictionary<string, object>() { { "StringProperty", "z" }, { "IntProperty", 3 } }, } } }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); for (var index = 0; index < 3; index++) { var kv = (dict["CompoundCollectionProperty"] as IList<IDictionary<string, object>>)[index]; Assert.Equal(kv["StringProperty"], value.CompoundCollectionProperty[index].StringProperty); Assert.Equal(kv["IntProperty"], value.CompoundCollectionProperty[index].IntProperty); } }
/// <summary> /// Initializes a new instance of the <see cref="CaseTermStrategyByPriority"/> class. /// </summary> /// <param name="userConnection">The user connection.</param> /// <param name="args">The arguments.</param> protected CaseTermStrategyByPriority(UserConnection userConnection, Dictionary <string, object> args) : base(userConnection) { StrategyDataItem = args.ToObject <StrategyData>(); }
public void LengthyTest() { var expected = new RecursiveData { Id = new Guid("366f4bd3-6717-4b14-9c79-70515296df7e"), Date = new DateTime(1999, 1, 1), Enum = Enumeration.One, Text = "level 1", Array = new[] { 1, 2, 3, }, Nested = new RecursiveData { Id = new Guid("e591be31-289f-4a99-ba67-288ea24b7d7e"), Date = new DateTime(1999, 2, 2), Enum = Enumeration.Two, Text = "level 2", Array = new[] { 4, 5, 6, }, Nested = new RecursiveData { Id = null, Date = null, Enum = null, Text = null, Nested = new RecursiveData { Id = new Guid("3bfdd62f-8b31-4aa2-931d-46535f291b0e"), Date = new DateTime(1999, 4, 4), Enum = Enumeration.Four, Text = "level 4", Array = new[] { 10, 11, 12, }, Nested = null, }, }, }, }; var dict = new Dictionary<string, object>() { // 1st level { "Id", expected.Id }, { "Date", expected.Date }, { "Enum", expected.Enum }, { "Text", expected.Text }, { "Array", expected.Array }, // 2nd level { "Nested.Id", expected.Nested.Id }, { "Nested.Date", expected.Nested.Date }, { "Nested.Enum", expected.Nested.Enum }, { "Nested.Text", expected.Nested.Text }, { "Nested.Array", expected.Nested.Array }, // 3rd level { "Nested.Nested.Id", expected.Nested.Nested.Id }, { "Nested.Nested.Date", expected.Nested.Nested.Date }, { "Nested.Nested.Enum", expected.Nested.Nested.Enum }, { "Nested.Nested.Text", expected.Nested.Nested.Text }, { "Nested.Nested.Array", expected.Nested.Nested.Array }, // 4th level { "Nested.Nested.Nested.Id", expected.Nested.Nested.Nested.Id }, { "Nested.Nested.Nested.Date", expected.Nested.Nested.Nested.Date }, { "Nested.Nested.Nested.Enum", expected.Nested.Nested.Nested.Enum }, { "Nested.Nested.Nested.Text", expected.Nested.Nested.Nested.Text }, { "Nested.Nested.Nested.Array", expected.Nested.Nested.Nested.Array }, // 5th level { "Nested.Nested.Nested.Nested.Id", null }, { "Nested.Nested.Nested.Nested.Date", null }, { "Nested.Nested.Nested.Nested.Enum", null }, { "Nested.Nested.Nested.Nested.Text", null }, { "Nested.Nested.Nested.Nested.Array", null }, }; var actual = dict.ToObject<RecursiveData>(); // 1st level Assert.AreEqual(expected.Id, actual.Id); Assert.AreEqual(expected.Date, actual.Date); Assert.AreEqual(expected.Enum, actual.Enum); Assert.AreEqual(expected.Text, actual.Text); CollectionAssert.AreEqual(expected.Array, actual.Array); // 2nd level Assert.AreEqual(expected.Nested.Id, actual.Nested.Id); Assert.AreEqual(expected.Nested.Date, actual.Nested.Date); Assert.AreEqual(expected.Nested.Enum, actual.Nested.Enum); Assert.AreEqual(expected.Nested.Text, actual.Nested.Text); CollectionAssert.AreEqual(expected.Nested.Array, actual.Nested.Array); // 3rd level Assert.AreEqual(expected.Nested.Nested.Id, actual.Nested.Nested.Id); Assert.AreEqual(expected.Nested.Nested.Date, actual.Nested.Nested.Date); Assert.AreEqual(expected.Nested.Nested.Enum, actual.Nested.Nested.Enum); Assert.AreEqual(expected.Nested.Nested.Text, actual.Nested.Nested.Text); CollectionAssert.AreEqual(expected.Nested.Nested.Array, actual.Nested.Nested.Array); // 4th level Assert.AreEqual(expected.Nested.Nested.Nested.Id, actual.Nested.Nested.Nested.Id); Assert.AreEqual(expected.Nested.Nested.Nested.Date, actual.Nested.Nested.Nested.Date); Assert.AreEqual(expected.Nested.Nested.Nested.Enum, actual.Nested.Nested.Nested.Enum); Assert.AreEqual(expected.Nested.Nested.Nested.Text, actual.Nested.Nested.Nested.Text); CollectionAssert.AreEqual(expected.Nested.Nested.Nested.Array, actual.Nested.Nested.Nested.Array); // 5th level Assert.AreEqual(null, actual.Nested.Nested.Nested.Nested); }
public void ToObjectCombinedEnumPropertyFromInt() { var dict = new Dictionary<string, object>() { { "EnumProperty", EnumType.One | EnumType.Two }, }; var value = dict.ToObject<ClassType>(); Assert.Equal(EnumType.Three, value.EnumProperty); }
public void ToObjectIntCollection() { var dict = new Dictionary<string, object>() { { "StringProperty", "a" }, { "IntProperty", 1 }, { "IntCollectionProperty", new [] {1, 2, 3} } }; var value = dict.ToObject<ClassType>(); Assert.Equal("a", value.StringProperty); Assert.Equal(1, value.IntProperty); for (var index = 0; index < 3; index++) { Assert.Equal((dict["IntCollectionProperty"] as IList<int>)[index], value.IntCollectionProperty[index]); } }
public void ToObjectSpatialV4() { CustomConverters.RegisterTypeConverter(typeof(SpatialV4.GeographyPoint), V4.Adapter.TypeConverters.CreateGeographyPoint); var dict = new Dictionary<string, object>() { { "PointV4", SpatialV4.GeographyPoint.Create(SpatialV4.CoordinateSystem.Geography(100), 1, 2, null, null) }, }; var value = dict.ToObject<ClassType>(); Assert.Equal(100, value.PointV4.CoordinateSystem.EpsgId); Assert.Equal(1d, value.PointV4.Latitude); Assert.Equal(2d, value.PointV4.Longitude); }
public void ToObject_WhenDictionaryContainsDataWhichCannotBeMatched2_MustThrowInvalidOperationException() { var dictionary = new Dictionary<string, object> { { "Name", "Marbach" }, { "Street", "Elsewhere" }}; Assert.Throws<InvalidOperationException>(() => dictionary.ToObject<Input>()); }