Exemplo n.º 1
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))
                );
        }
Exemplo n.º 2
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))
                );
        }
Exemplo n.º 3
0
 public void Bind(TextBox inputBox, TextBox outputBox)
 {
     if (ctx.InvokeRequired)
     {
         BindDelegate c = new BindDelegate(Bind);
         ctx.Invoke(c, new object[] { inputBox, outputBox });
         return;
     }
     input  = inputBox;
     output = outputBox;
 }
Exemplo n.º 4
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))
                );
        }
Exemplo n.º 5
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))
                );
        }
Exemplo n.º 6
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))
                );
        }
Exemplo n.º 7
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))
                );
        }
Exemplo n.º 8
0
 public TextureManager()
 {
     _textures = new ObservableCollection <Texture>();
     _textures.CollectionChanged += OnTextureListChanged;
     _bindCommand = new BindDelegate(FirstTimeBind);
 }
Exemplo n.º 9
0
 private void OnTextureListChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     _textureIdArray = _textures.Select(texture => texture.Id).ToArray();
     _bindCommand    = new BindDelegate(FirstTimeBind);
 }
Exemplo n.º 10
0
 ReflectionCache(MatchDelegate match, BindDelegate bind)
 {
     MatchProxy = match;
     BindProxy  = bind;
 }