public void DescriptionTests() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DescriptionModel), "NoAttribute").Description);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DescriptionModel), "DescriptionNotSet").Description);
            Assert.AreEqual("Description text", provider.GetMetadataForProperty(null, typeof(DescriptionModel), "DescriptionSet").Description);
        }
        public void DataTypeInfluencedByDisplayFormatAttributeHtmlEncode() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DataTypeModel), "NoAttribute").DataTypeName);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DataTypeModel), "HtmlEncodeTrue").DataTypeName);
            Assert.AreEqual("Html", provider.GetMetadataForProperty(null, typeof(DataTypeModel), "HtmlEncodeFalse").DataTypeName);
            Assert.AreEqual("Currency", provider.GetMetadataForProperty(null, typeof(DataTypeModel), "HtmlEncodeFalseWithDataType").DataTypeName);
        }
Exemple #3
0
        public void WatermarkTests()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(WatermarkModel), "NoAttribute").Watermark);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(WatermarkModel), "PromptNotSet").Watermark);
            Assert.AreEqual("Enter stuff here", provider.GetMetadataForProperty(null, typeof(WatermarkModel), "PromptSet").Watermark);
        }
Exemple #4
0
        public void DescriptionTests()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DescriptionModel), "NoAttribute").Description);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DescriptionModel), "DescriptionNotSet").Description);
            Assert.AreEqual("Description text", provider.GetMetadataForProperty(null, typeof(DescriptionModel), "DescriptionSet").Description);
        }
Exemple #5
0
        public void ShortDisplayNameTests()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(ShortDisplayNameModel), "NoAttribute").ShortDisplayName);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(ShortDisplayNameModel), "ShortNameNotSet").ShortDisplayName);
            Assert.AreEqual("Short name", provider.GetMetadataForProperty(null, typeof(ShortDisplayNameModel), "ShortNameSet").ShortDisplayName);
        }
        public void DisplayNameTests() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "NoAttribute").DisplayName);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "DisplayAttributeNameNotSet").DisplayName);
            Assert.AreEqual("Non empty name", provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "DisplayAttributeNonEmptyName").DisplayName);
            Assert.AreEqual("Value from DisplayName", provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "BothAttributesNameNotSet").DisplayName);
            Assert.AreEqual("Value from Display", provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "BothAttributes").DisplayName);
        }
Exemple #7
0
        public void DataTypeInfluencedByDisplayFormatAttributeHtmlEncode()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DataTypeModel), "NoAttribute").DataTypeName);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DataTypeModel), "HtmlEncodeTrue").DataTypeName);
            Assert.AreEqual("Html", provider.GetMetadataForProperty(null, typeof(DataTypeModel), "HtmlEncodeFalse").DataTypeName);
            Assert.AreEqual("Currency", provider.GetMetadataForProperty(null, typeof(DataTypeModel), "HtmlEncodeFalseWithDataType").DataTypeName);
        }
Exemple #8
0
        public void ReadOnlyTests()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsFalse(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "NoAttributes").IsReadOnly);
            Assert.IsTrue(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "ReadOnlyAttribute").IsReadOnly);
            Assert.IsTrue(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "EditableAttribute").IsReadOnly);
            Assert.IsFalse(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "BothAttributes").IsReadOnly);
        }
Exemple #9
0
        public void DisplayNameTests()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "NoAttribute").DisplayName);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "DisplayAttributeNameNotSet").DisplayName);
            Assert.AreEqual("Non empty name", provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "DisplayAttributeNonEmptyName").DisplayName);
            Assert.AreEqual("Value from DisplayName", provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "BothAttributesNameNotSet").DisplayName);
            Assert.AreEqual("Value from Display", provider.GetMetadataForProperty(null, typeof(DisplayNameModel), "BothAttributes").DisplayName);
        }
Exemple #10
0
        public void MetadataAwareAttributeCanModifyPropertyMetadata()
        {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // 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);
        }
        public void MetadataAwareAttributeCanModifyPropertyMetadata() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // 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);
        }
        public void ReadOnlyTests() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsFalse(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "NoAttributes").IsReadOnly);
            Assert.IsTrue(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "ReadOnlyAttribute").IsReadOnly);
            Assert.IsTrue(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "EditableAttribute").IsReadOnly);
            Assert.IsFalse(provider.GetMetadataForProperty(null, typeof(ReadOnlyModel), "BothAttributes").IsReadOnly);
        }
        public void WatermarkTests() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(WatermarkModel), "NoAttribute").Watermark);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(WatermarkModel), "PromptNotSet").Watermark);
            Assert.AreEqual("Enter stuff here", provider.GetMetadataForProperty(null, typeof(WatermarkModel), "PromptSet").Watermark);
        }
        public void ShortDisplayNameTests() {
            // Arrange
            DataAnnotations4ModelMetadataProvider provider = new DataAnnotations4ModelMetadataProvider();

            // Act & Assert
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(ShortDisplayNameModel), "NoAttribute").ShortDisplayName);
            Assert.IsNull(provider.GetMetadataForProperty(null, typeof(ShortDisplayNameModel), "ShortNameNotSet").ShortDisplayName);
            Assert.AreEqual("Short name", provider.GetMetadataForProperty(null, typeof(ShortDisplayNameModel), "ShortNameSet").ShortDisplayName);
        }