public void GetMetadataForPropertyNullOrEmptyPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.ThrowsArgument( () => provider.GetMetadataForProperty( modelAccessor: null, containerType: typeof(object), propertyName: null ), "propertyName", "The argument 'propertyName' is null or empty." ); Assert.ThrowsArgument( () => provider.GetMetadataForProperty( modelAccessor: null, containerType: typeof(object), propertyName: String.Empty ), "propertyName", "The argument 'propertyName' is null or empty." ); }
public void GetMetadataForPropertyNullOrEmptyPropertyNameThrows() { // Arrange var provider = new TestableAssociatedMetadataProvider(); // Act & Assert ExceptionAssert.ThrowsArgumentNullOrEmpty( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: typeof(object), propertyName: null), "propertyName"); ExceptionAssert.ThrowsArgumentNullOrEmpty( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: typeof(object), propertyName: String.Empty), "propertyName"); }
public void GetMetadataForPropertyNullOrEmptyPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.ThrowsArgumentNullOrEmpty( () => provider.GetMetadataForProperty(null /* model */, typeof(object), null /* propertyName */), "propertyName"); Assert.ThrowsArgumentNullOrEmpty( () => provider.GetMetadataForProperty(null, typeof(object), String.Empty), "propertyName"); }
public void GetMetadataForPropertyWithMetadataAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata( provider, typeof(PropertyModel), null, typeof(string), "MetadataAttributes" ); provider.CreateMetadataFromPrototypeReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty( null, typeof(PropertyModel), "MetadataAttributes" ); // Assert Assert.Same(metadata, result); CreateMetadataPrototypeParams parms = Assert.Single( provider.CreateMetadataPrototypeLog, parameters => parameters.PropertyName == "MetadataAttributes" ); Assert.Contains(parms.Attributes, a => a is RangeAttribute); }
public void GetMetadataForPropertyWithMixedAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata( provider, typeof(PropertyModel), null, typeof(double), "MixedAttributes" ); provider.CreateMetadataReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty( null, typeof(PropertyModel), "MixedAttributes" ); // Assert Assert.Same(metadata, result); CreateMetadataParams parms = provider.CreateMetadataLog.Single( p => p.PropertyName == "MixedAttributes" ); Assert.Contains(parms.Attributes, a => a is RequiredAttribute); Assert.Contains(parms.Attributes, a => a is RangeAttribute); }
public void MetadataAwareAttributeCanModifyPropertyMetadata() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); provider.CreateMetadataReturnValue = new ModelMetadata( provider, typeof(ClassWithAdditionalMetadata), null, typeof(int), "MyProperty" ); // Act ModelMetadata metadata = provider.GetMetadataForProperty( null, typeof(ClassWithAdditionalMetadata), "MyProperty" ); // Assert var kvp = metadata.AdditionalValues.Single(); Assert.Equal("PropertyName", kvp.Key); Assert.Equal("PropertyValue", kvp.Value); }
public void GetMetadataForPropertyWithLocalAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata( provider, typeof(PropertyModel), null, typeof(int), "LocalAttributes" ); provider.CreateMetadataReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty( null, typeof(PropertyModel), "LocalAttributes" ); // Assert Assert.Same(metadata, result); Assert.Contains( provider.CreateMetadataLog.Single().Attributes, a => a is RequiredAttribute ); }
public void GetMetadataForPropertyNullContainerTypeThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert ExceptionHelper.ExpectArgumentNullException( () => provider.GetMetadataForProperty(null /* model */, null /* containerType */, "propertyName"), "containerType"); }
public void GetMetadataForPropertyInvalidPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.Throws <ArgumentException>( () => provider.GetMetadataForProperty(null, typeof(object), "BadPropertyName"), "The property System.Object.BadPropertyName could not be found."); }
public void GetMetadataForPropertyNullContainerTypeThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.ThrowsArgumentNull( () => provider.GetMetadataForProperty(null /* model */, null /* containerType */, "propertyName"), "containerType"); }
public void ReadOnlyAttributeIsFilteredOffWhenContainerTypeIsViewUserControl() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act provider.GetMetadataForProperty(() => null, typeof(ViewUserControl<PropertyModel>), "Model"); // Assert CreateMetadataParams parms = provider.CreateMetadataLog.Single(); Assert.IsFalse(parms.Attributes.Any(a => a is ReadOnlyAttribute)); }
public void ReadOnlyAttributeIsPreservedForReadOnlyModelProperties() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act provider.GetMetadataForProperty(() => null, typeof(ModelWithReadOnlyProperty), "ReadOnlyProperty"); // Assert CreateMetadataParams parms = provider.CreateMetadataLog.Single(); Assert.IsTrue(parms.Attributes.Any(a => a is ReadOnlyAttribute)); }
public void GetMetadataForPropertyInvalidPropertyNameThrows() { // Arrange var provider = new TestableAssociatedMetadataProvider(); // Act & Assert ExceptionAssert.ThrowsArgument( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: typeof(object), propertyName: "BadPropertyName"), "propertyName", "The property System.Object.BadPropertyName could not be found."); }
public void ReadOnlyAttributeIsPreservedForReadOnlyModelProperties() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act provider.GetMetadataForProperty(() => null, typeof(ModelWithReadOnlyProperty), "ReadOnlyProperty"); // Assert CreateMetadataParams parms = provider.CreateMetadataLog.Single(); Assert.True(parms.Attributes.Any(a => a is ReadOnlyAttribute)); }
public void ReadOnlyAttributeIsFilteredOffWhenContainerTypeIsViewPage() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act provider.GetMetadataForProperty(() => null, typeof(ViewPage <PropertyModel>), "Model"); // Assert CreateMetadataParams parms = provider.CreateMetadataLog.Single(); Assert.DoesNotContain(parms.Attributes, a => a is ReadOnlyAttribute); }
public void GetMetadataForPropertyWithLocalAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata(provider, typeof(PropertyModel), null, typeof(int), "LocalAttributes"); provider.CreateMetadataFromPrototypeReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty(null, typeof(PropertyModel), "LocalAttributes"); // Assert Assert.Same(metadata, result); Assert.True(provider.CreateMetadataPrototypeLog.Single(parameters => parameters.PropertyName == "LocalAttributes").Attributes.Any(a => a is RequiredAttribute)); }
public void GetMetadataForPropertyWithMetadataAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata(provider, typeof(PropertyModel), null, typeof(string), "MetadataAttributes"); provider.CreateMetadataReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty(null, typeof(PropertyModel), "MetadataAttributes"); // Assert Assert.AreSame(metadata, result); CreateMetadataParams parms = provider.CreateMetadataLog.Single(p => p.PropertyName == "MetadataAttributes"); Assert.IsTrue(parms.Attributes.Any(a => a is RangeAttribute)); }
public void GetMetadataForPropertyWithMetadataAttributes() { // Arrange var provider = new TestableAssociatedMetadataProvider(); var metadata = new ModelMetadata(provider, typeof(PropertyModel), null, typeof(string), "MetadataAttributes"); provider.CreateMetadataFromPrototypeReturnValue = metadata; // Act var result = provider.GetMetadataForProperty(null, typeof(PropertyModel), "MetadataAttributes"); // Assert Assert.Same(metadata, result); var parmaters = provider.CreateMetadataPrototypeLog.Single(p => p.PropertyName == "MetadataAttributes"); Assert.True(parmaters.Attributes.Any(a => a is RangeAttribute)); }
public void GetMetadataForPropertyWithMixedAttributes() { // Arrange var provider = new TestableAssociatedMetadataProvider(); var metadata = new ModelMetadata(provider, typeof(PropertyModel), null, typeof(double), "MixedAttributes"); provider.CreateMetadataFromPrototypeReturnValue = metadata; // Act var result = provider.GetMetadataForProperty(null, typeof(PropertyModel), "MixedAttributes"); // Assert Assert.Same(metadata, result); var parms = Assert.Single(provider.CreateMetadataPrototypeLog, p => p.PropertyName == "MixedAttributes"); Assert.Single(parms.Attributes, a => a is RequiredAttribute); Assert.Single(parms.Attributes, a => a is RangeAttribute); }
public void GetMetadataForPropertyNullOrEmptyPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert ExceptionHelper.ExpectArgumentExceptionNullOrEmpty( () => provider.GetMetadataForProperty(null /* model */, typeof(object), null /* propertyName */), "propertyName"); ExceptionHelper.ExpectArgumentExceptionNullOrEmpty( () => provider.GetMetadataForProperty(null, typeof(object), String.Empty), "propertyName"); }
public void GetMetadataForPropertyInvalidPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.ThrowsArgument( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: typeof(object), propertyName: "BadPropertyName"), "propertyName", "The property System.Object.BadPropertyName could not be found."); }
public void GetMetadataForPropertyWithMixedAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata(provider, typeof(PropertyModel), null, typeof(double), "MixedAttributes"); provider.CreateMetadataReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty(null, typeof(PropertyModel), "MixedAttributes"); // Assert Assert.AreSame(metadata, result); CreateMetadataParams parms = provider.CreateMetadataLog.Single(p => p.PropertyName == "MixedAttributes"); Assert.IsTrue(parms.Attributes.Any(a => a is RequiredAttribute)); Assert.IsTrue(parms.Attributes.Any(a => a is RangeAttribute)); }
public void GetMetadataForPropertyWithLocalAttributes() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); ModelMetadata metadata = new ModelMetadata(provider, typeof(PropertyModel), null, typeof(int), "LocalAttributes"); provider.CreateMetadataReturnValue = metadata; // Act ModelMetadata result = provider.GetMetadataForProperty(null, typeof(PropertyModel), "LocalAttributes"); // Assert Assert.AreSame(metadata, result); Assert.IsTrue(provider.CreateMetadataLog.Single().Attributes.Any(a => a is RequiredAttribute)); }
public void GetMetadataForPropertyInvalidPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert ExceptionHelper.ExpectArgumentException( () => provider.GetMetadataForProperty(null, typeof(object), "BadPropertyName"), "The property System.Object.BadPropertyName could not be found."); }
public void GetMetadataForPropertyNullContainerTypeThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.ThrowsArgumentNull( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: null, propertyName: "propertyName"), "containerType"); }
public void GetMetadataForPropertyNullOrEmptyPropertyNameThrows() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); // Act & Assert Assert.ThrowsArgument( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: typeof(object), propertyName: null), "propertyName", "The argument 'propertyName' is null or empty."); Assert.ThrowsArgument( () => provider.GetMetadataForProperty(modelAccessor: null, containerType: typeof(object), propertyName: String.Empty), "propertyName", "The argument 'propertyName' is null or empty."); }
public void MetadataAwareAttributeCanModifyPropertyMetadata() { // Arrange TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider(); provider.CreateMetadataReturnValue = new ModelMetadata(provider, typeof(ClassWithAdditionalMetadata), null, typeof(int), "MyProperty"); // Act ModelMetadata metadata = provider.GetMetadataForProperty(null, typeof(ClassWithAdditionalMetadata), "MyProperty"); // Assert var kvp = metadata.AdditionalValues.Single(); Assert.AreEqual("PropertyName", kvp.Key); Assert.AreEqual("PropertyValue", kvp.Value); }