Example #1
0
        public void BindsTo_ExtensionData(BindDelegate @delegate)
        {
            var binder = new JsonBinder();

            var keyValuePairs = new[]
            {
                new KeyValuePair <string, string>("ComplexProperty:value", "123"),
                new KeyValuePair <string, string>("ComplexProperty:AutoProperty:value", "456"),
                new KeyValuePair <string, string>("something", "1123"),
                new KeyValuePair <string, string>("somethingelse:value", "1456"),
                new KeyValuePair <string, string>("ComplexProperty:something", "2123"),
                new KeyValuePair <string, string>("ComplexProperty:somethingelse:value", "2456"),
            };
            var result = (ExtraProperties)@delegate(binder, typeof(ExtraProperties), JsonBinder.DefaultSerializer, keyValuePairs);

            result.ComplexProperty.Value.Should().Be("123");
            result.ComplexProperty.AutoProperty.Value.Should().Be("456");
            result.ComplexProperty.CustomFields["something"].ToString().Should().Be("2123");
            result.ComplexProperty.CustomFields["somethingelse"]["value"].ToString().Should().Be("2456");

            result.CustomFields.Should().NotBeEmpty();
            result.CustomFields["something"].ToString().Should().Be("1123");
            result.CustomFields["somethingelse"]["value"].ToString().Should().Be("1456");

            Logger.LogInformation(JsonConvert.SerializeObject(result.CustomFields));

            binder.From(result)
            .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
            .Should().BeEquivalentTo(
                keyValuePairs
                .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
                );
        }
Example #2
0
        public void BindsTo_ListProperties(BindDelegate @delegate)
        {
            var binder        = new JsonBinder();
            var keyValuePairs = new[]
            {
                new KeyValuePair <string, string>("Values:0:value", "123"),
                new KeyValuePair <string, string>("Values:1:value", "456"),
                new KeyValuePair <string, string>("Values:2:value", "789")
            };
            var result = (ListProperties)@delegate(binder, typeof(ListProperties), JsonBinder.DefaultSerializer, keyValuePairs);

            result.Values.Should().BeEquivalentTo(new[]
            {
                new AutoProperty {
                    Value = "123"
                },
                new AutoProperty {
                    Value = "456"
                },
                new AutoProperty {
                    Value = "789"
                }
            });

            binder.From(result)
            .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
            .Should().BeEquivalentTo(
                keyValuePairs
                .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
                );
        }
Example #3
0
        public void BindsTo_PrivateSetterProperty(BindDelegate @delegate)
        {
            var binder = new JsonBinder();

            var keyValuePairs = new[]
            {
                new KeyValuePair <string, string>("value", "123")
            };
            var result = (PrivateSetterProperty)@delegate(binder, typeof(PrivateSetterProperty), JsonBinder.DefaultSerializer, keyValuePairs);

            result.Value.Should().Be("123");

            binder.From(result)
            .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
            .Should().BeEquivalentTo(
                keyValuePairs
                .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
                );
        }
Example #4
0
        public void BindsTo_SimpleArrayProperties(BindDelegate @delegate)
        {
            var binder        = new JsonBinder();
            var keyValuePairs = new[]
            {
                new KeyValuePair <string, string>("Values:0", "123"),
                new KeyValuePair <string, string>("Values:1", "456"),
                new KeyValuePair <string, string>("Values:2", "789")
            };
            var result = (SimpleArrayProperties)@delegate(binder, typeof(SimpleArrayProperties), JsonBinder.DefaultSerializer, keyValuePairs);

            result.Values.Should().BeEquivalentTo("123", "456", "789");

            binder.From(result)
            .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
            .Should().BeEquivalentTo(
                keyValuePairs
                .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
                );
        }
Example #5
0
        public void BindsTo_ComplexProperties_Null(BindDelegate @delegate)
        {
            var binder = new JsonBinder();

            var keyValuePairs = new[]
            {
                new KeyValuePair <string, string>("value", "123")
            };
            var result = (ComplexProperty)@delegate(binder, typeof(ComplexProperty), JsonBinder.DefaultSerializer, keyValuePairs);

            result.Value.Should().Be("123");
            result.AutoProperty.Should().BeNull();

            binder.From(result)
            .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
            .Should().Contain(
                keyValuePairs
                .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
                );
        }
Example #6
0
        public void BindsTo_ComplexProperties_CustomSep(BindDelegate @delegate)
        {
            var binder = new JsonBinder("__");

            var keyValuePairs = new[]
            {
                new KeyValuePair <string, string>("value", "123"),
                new KeyValuePair <string, string>("AutoProperty__value", "456")
            };
            var result = (ComplexProperty)@delegate(binder, typeof(ComplexProperty), JsonBinder.DefaultSerializer, keyValuePairs);

            result.Value.Should().Be("123");
            result.AutoProperty.Value.Should().Be("456");

            binder.From(result)
            .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
            .Should().BeEquivalentTo(
                keyValuePairs
                .Select(x => new KeyValuePair <string, string>(x.Key.ToLower(), x.Value))
                );
        }