public void PatchWrongProperty() { var patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); var json = new JsonParser().Parse(@"{ ""url"": ""http://www.example.org"" }"); Assert.Throws <BadRequestException>(() => patcher.Patch(new EntityBase <int>(), json)); }
public void JsonParserShouldNotAcceptNullValuesEvenWhenNonNullableInDictionary() { Assert.Throws <BadRequestException>(() => { var json = new JsonParser().Parse(@"{intDico: { 1: null, 2: 3 }}"); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(new ToPatch(), json); }); }
public void PatchEntityHelperShouldFailOnNonPublicGetterProperties() { var input = @"{internalintDico: { 1: 1, 2: 3 }}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); Assert.Throws <BadRequestException>(() => patcher.Patch(newPatched, json)); }
public void PatchEntityHelperShouldFailOnNonPublicInstanceProperties(string prop) { var input = @"{" + prop + ": 1 }"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); Assert.Throws <BadRequestException>(() => patcher.Patch(newPatched, json)); }
public void PatchEntityHelperShouldAcceptEnumClient() { var input = @"{days: {code: ""Tue""}}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Equal(TestEnum.Tue, newPatched.Days.Value); }
public void PatchEntityHelperShouldAcceptNullValuesOnStringDictionary() { var input = @"{stringDico: { 1: null, 2: ""test"" }}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Null(newPatched.StringDico[1]); Assert.Equal("test", newPatched.StringDico[2]); }
public void PatchEntityHelperShouldAcceptNullValuesOnNullableValueTypeInDictionary() { var input = @"{intNullableDico: { 1: null, 2: 3 }}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Null(newPatched.IntNullableDico[1]); Assert.Equal(3, newPatched.IntNullableDico[2]); }
public void PatchEntityHelperShouldAcceptNullValuesInKeyStringValueStringDico() { var input = @"{keyStringValueStringDico: { ""yo"": null, ""man"": ""test"" }}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Null(newPatched.KeyStringValueStringDico["yo"]); Assert.Equal("test", newPatched.KeyStringValueStringDico["man"]); }
public void PatchEntityHelperShouldAcceptNullValuesInDictionary() { var input = @"{customFields: { 1: null, 2: {code:""test""} }}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Null(newPatched.CustomFields[1]); Assert.Equal("test", newPatched.CustomFields[2].Code); }
public void PatchEntityHelperShouldAcceptCollection() { var input = @"{aCollection: [{mon: ""object""}, {autre: ""test""}]}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Equal(2, newPatched.ACollection.Count); Assert.Equal("object", (newPatched.ACollection.ElementAt(0) as Dictionary <string, object>)["mon"]); Assert.Equal("test", (newPatched.ACollection.ElementAt(1) as Dictionary <string, object>)["autre"]); }
public void PatchEntityHelperShouldAcceptNonNullValuesInDictionary() { var input = @"{intDico: { 1: 1, 2: 3 }, customFields: { 1: {code:""hey !""}, 2: {code:""salut""} }}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Equal(1, newPatched.IntDico[1]); Assert.Equal(3, newPatched.IntDico[2]); Assert.Equal("hey !", newPatched.CustomFields[1].Code); Assert.Equal("salut", newPatched.CustomFields[2].Code); }
public void PatchEntityHelperShouldAcceptArrays() { var input = @"{arrayOfInt: [1, 2, 3, 4]}"; var json = new JsonParser().Parse(input); var newPatched = new ToPatch(); IPatcher patcher = new ObjectPatcher(PatcherProvider, ReflectionHelper); patcher.Patch(newPatched, json); Assert.Equal(4, newPatched.ArrayOfInt.Length); Assert.Equal(1, newPatched.ArrayOfInt[0]); Assert.Equal(2, newPatched.ArrayOfInt[1]); Assert.Equal(3, newPatched.ArrayOfInt[2]); Assert.Equal(4, newPatched.ArrayOfInt[3]); }