コード例 #1
0
        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));
        }
コード例 #2
0
 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);
     });
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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]);
        }
コード例 #7
0
        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]);
        }
コード例 #8
0
        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"]);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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"]);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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]);
        }