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())); }
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)); }
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); }
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); }
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); }
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); }
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)); }
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())); }