示例#1
0
        public void Constructor_FindsDisplayFormat_OverridingDataType()
        {
            // Arrange
            var dataType      = new DataTypeAttribute(DataType.Time); // Has a non-null DisplayFormat.
            var displayFormat = new DisplayFormatAttribute();
            var attributes    = new Attribute[] { dataType, displayFormat, };

            // Act
            var cache  = new CachedDataAnnotationsMetadataAttributes(attributes);
            var result = cache.DisplayFormat;

            // Assert
            Assert.Same(displayFormat, result);
        }
示例#2
0
        public void Constructor_FindsExpectedAttribute(
            object attribute,
            Func <CachedDataAnnotationsMetadataAttributes, object> accessor)
        {
            // Arrange
            var attributes = new[] { attribute };

            // Act
            var cache  = new CachedDataAnnotationsMetadataAttributes(attributes);
            var result = accessor(cache);

            // Assert
            Assert.Same(attribute, result);
        }
示例#3
0
        public void Constructor_FindsDisplayFormat_FromDataType()
        {
            // Arrange
            var dataType      = new DataTypeAttribute(DataType.Currency);
            var displayFormat = dataType.DisplayFormat; // Non-null for DataType.Currency.
            var attributes    = new[] { dataType, };

            // Act
            var cache  = new CachedDataAnnotationsMetadataAttributes(attributes);
            var result = cache.DisplayFormat;

            // Assert
            Assert.Same(displayFormat, result);
        }
        public void Constructor_FindsExpectedAttribute(
            Attribute attribute,
            Func<CachedDataAnnotationsMetadataAttributes, Attribute> accessor)
        {
            // Arrange
            var attributes = new[] { attribute };

            // Act
            var cache = new CachedDataAnnotationsMetadataAttributes(attributes);
            var result = accessor(cache);

            // Assert
            Assert.Same(attribute, result);
        }
示例#5
0
        public void Constructor_DefaultsAllPropertiesToNull()
        {
            // Arrange
            var attributes = Enumerable.Empty <Attribute>();

            // Act
            var cache = new CachedDataAnnotationsMetadataAttributes(attributes);

            // Assert
            Assert.Null(cache.Display);
            Assert.Null(cache.DisplayColumn);
            Assert.Null(cache.DisplayFormat);
            Assert.Null(cache.Editable);
            Assert.Null(cache.Required);
        }
        public void Constructor_DefaultsAllPropertiesToNull()
        {
            // Arrange
            var attributes = Enumerable.Empty<Attribute>();

            // Act
            var cache = new CachedDataAnnotationsMetadataAttributes(attributes);

            // Assert
            Assert.Null(cache.Display);
            Assert.Null(cache.DisplayColumn);
            Assert.Null(cache.DisplayFormat);
            Assert.Null(cache.Editable);
            Assert.Null(cache.Required);
        }
示例#7
0
        public void Constructor_FindsBinderTypeProviders()
        {
            // Arrange
            var providers = new[] { new TestBinderTypeProvider(), new TestBinderTypeProvider() };

            // Act
            var cache  = new CachedDataAnnotationsMetadataAttributes(providers);
            var result = cache.BinderTypeProviders.ToArray();

            // Assert
            Assert.Equal(providers.Length, result.Length);
            for (var index = 0; index < providers.Length; index++)
            {
                Assert.Same(providers[index], result[index]);
            }
        }
示例#8
0
        public void Constructor_SetsDefaultValuesForAllProperties()
        {
            // Arrange
            var attributes = Enumerable.Empty <Attribute>();

            // Act
            var cache = new CachedDataAnnotationsMetadataAttributes(attributes);

            // Assert
            Assert.Null(cache.DataType);
            Assert.Null(cache.Display);
            Assert.Null(cache.DisplayColumn);
            Assert.Null(cache.DisplayFormat);
            Assert.Null(cache.Editable);
            Assert.Null(cache.HiddenInput);
            Assert.Null(cache.Required);
            Assert.Null(cache.ScaffoldColumn);
            Assert.Null(cache.BinderMetadata);
            Assert.Null(cache.BinderModelNameProvider);
            Assert.Empty(cache.PropertyBindingPredicateProviders);
        }