コード例 #1
0
            public void WhenValueIsNotNull_ThenCanReset()
            {
                var property = new Mock <PropertyDescriptor>("foo", new Attribute[0]);

                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());
                property.Setup(x => x.GetValue(It.IsAny <object>())).Returns("{ }");

                var descriptor = new StringCollectionPropertyDescriptor <Model>(property.Object);

                Assert.True(descriptor.CanResetValue(new object()));
            }
コード例 #2
0
            public void WhenResettingValue_ThenSetsItToNull()
            {
                var property = new Mock <PropertyDescriptor>("foo", new Attribute[0]);

                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());
                property.Setup(x => x.GetValue(It.IsAny <object>())).Returns("{ }");

                var descriptor = new StringCollectionPropertyDescriptor <Model>(property.Object);

                descriptor.ResetValue(new object());

                property.Verify(x => x.SetValue(It.IsAny <object>(), null));
            }
コード例 #3
0
            public void WhenSettingValue_ThenSerializesToJson()
            {
                var property = new Mock <PropertyDescriptor>("foo", new Attribute[0]);

                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());

                string serializedValue = null;

                property
                .Setup(x => x.SetValue(It.IsAny <object>(), It.IsAny <object>()))
                .Callback <object, object>((component, value) => serializedValue = (string)value);

                var descriptor = new StringCollectionPropertyDescriptor <Model>(property.Object);

                descriptor.SetValue(new object(), this.models);

                var conditions = BindingSerializer.Deserialize <Collection <Model> >(serializedValue);

                Assert.Equal(2, conditions.Count);
            }
コード例 #4
0
            public void WhenSettingValue_ThenCanRoundtrip()
            {
                var property = new Mock<PropertyDescriptor>("foo", new Attribute[0]);
                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());

                string serializedValue = null;
                property
                    .Setup(x => x.SetValue(It.IsAny<object>(), It.IsAny<object>()))
                    .Callback<object, object>((component, value) => serializedValue = (string)value);
                property
                    .Setup(x => x.GetValue(It.IsAny<object>()))
                    .Returns(() => serializedValue);

                var descriptor = new StringCollectionPropertyDescriptor<Model>(property.Object);

                descriptor.SetValue(new object(), this.models);

                var actual = (Collection<Model>)descriptor.GetValue(new object());

                Assert.Equal(this.models.Count, actual.Count);
            }
コード例 #5
0
            public void WhenSettingValue_ThenCanRoundtrip()
            {
                var property = new Mock <PropertyDescriptor>("foo", new Attribute[0]);

                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());

                string serializedValue = null;

                property
                .Setup(x => x.SetValue(It.IsAny <object>(), It.IsAny <object>()))
                .Callback <object, object>((component, value) => serializedValue = (string)value);
                property
                .Setup(x => x.GetValue(It.IsAny <object>()))
                .Returns(() => serializedValue);

                var descriptor = new StringCollectionPropertyDescriptor <Model>(property.Object);

                descriptor.SetValue(new object(), this.models);

                var actual = (Collection <Model>)descriptor.GetValue(new object());

                Assert.Equal(this.models.Count, actual.Count);
            }
コード例 #6
0
            public void WhenSettingValue_ThenSerializesToJson()
            {
                var property = new Mock<PropertyDescriptor>("foo", new Attribute[0]);
                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());

                string serializedValue = null;
                property
                    .Setup(x => x.SetValue(It.IsAny<object>(), It.IsAny<object>()))
                    .Callback<object, object>((component, value) => serializedValue = (string)value);

                var descriptor = new StringCollectionPropertyDescriptor<Model>(property.Object);

                descriptor.SetValue(new object(), this.models);

                var conditions = BindingSerializer.Deserialize<Collection<Model>>(serializedValue);

                Assert.Equal(2, conditions.Count);
            }
コード例 #7
0
            public void WhenResettingValue_ThenSetsItToNull()
            {
                var property = new Mock<PropertyDescriptor>("foo", new Attribute[0]);
                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());
                property.Setup(x => x.GetValue(It.IsAny<object>())).Returns("{ }");

                var descriptor = new StringCollectionPropertyDescriptor<Model>(property.Object);

                descriptor.ResetValue(new object());

                property.Verify(x => x.SetValue(It.IsAny<object>(), null));
            }
コード例 #8
0
            public void WhenValueIsNotNull_ThenCanReset()
            {
                var property = new Mock<PropertyDescriptor>("foo", new Attribute[0]);
                property.Setup(x => x.Name).Returns("Property");
                property.Setup(x => x.Attributes).Returns(new AttributeCollection());
                property.Setup(x => x.GetValue(It.IsAny<object>())).Returns("{ }");

                var descriptor = new StringCollectionPropertyDescriptor<Model>(property.Object);

                Assert.True(descriptor.CanResetValue(new object()));
            }