コード例 #1
0
        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."
                );
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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
                );
        }
コード例 #8
0
        public void GetMetadataForPropertyNullContainerTypeThrows() {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => provider.GetMetadataForProperty(null /* model */, null /* containerType */, "propertyName"),
                "containerType");
        }
コード例 #9
0
        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.");
        }
コード例 #10
0
        public void GetMetadataForPropertyNullContainerTypeThrows()
        {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => provider.GetMetadataForProperty(null /* model */, null /* containerType */, "propertyName"),
                "containerType");
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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.");
        }
コード例 #14
0
        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));
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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");
        }
コード例 #21
0
        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.");
        }
コード例 #22
0
        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));
        }
コード例 #23
0
        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));
        }
コード例 #24
0
        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.");
        }
コード例 #25
0
        public void GetMetadataForPropertyNullContainerTypeThrows()
        {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => provider.GetMetadataForProperty(modelAccessor: null, containerType: null, propertyName: "propertyName"),
                "containerType");
        }
コード例 #26
0
        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.");
        }
コード例 #27
0
        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);
        }