public void GetMetadataForPropertiesCreatesMetadataForAllPropertiesOnModelWithPropertyValues() {
            // Arrange
            PropertyModel model = new PropertyModel { LocalAttributes = 42, MetadataAttributes = "hello", MixedAttributes = 21.12 };
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act
            provider.GetMetadataForProperties(model, typeof(PropertyModel)).ToList();   // Call ToList() to force the lazy evaluation to evaluate

            // Assert
            CreateMetadataParams local =
                provider.CreateMetadataLog.Single(m => m.ContainerType == typeof(PropertyModel) &&
                                                       m.PropertyName == "LocalAttributes");
            Assert.AreEqual(typeof(int), local.ModelType);
            Assert.AreEqual(42, local.Model);
            Assert.IsTrue(local.Attributes.Any(a => a is RequiredAttribute));

            CreateMetadataParams metadata =
                provider.CreateMetadataLog.Single(m => m.ContainerType == typeof(PropertyModel) &&
                                                       m.PropertyName == "MetadataAttributes");
            Assert.AreEqual(typeof(string), metadata.ModelType);
            Assert.AreEqual("hello", metadata.Model);
            Assert.IsTrue(metadata.Attributes.Any(a => a is RangeAttribute));

            CreateMetadataParams mixed =
                provider.CreateMetadataLog.Single(m => m.ContainerType == typeof(PropertyModel) &&
                                                       m.PropertyName == "MixedAttributes");
            Assert.AreEqual(typeof(double), mixed.ModelType);
            Assert.AreEqual(21.12, mixed.Model);
            Assert.IsTrue(mixed.Attributes.Any(a => a is RequiredAttribute));
            Assert.IsTrue(mixed.Attributes.Any(a => a is RangeAttribute));
        }
        public void GetMetadataForPropertiesNullContainerTypeThrows() {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                () => provider.GetMetadataForProperties(new Object(), null),
                "containerType");
        }
        public void GetMetadataForPropertiesNullContainerTypeThrows()
        {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => provider.GetMetadataForProperties(new Object(), containerType: null),
                "containerType");
        }
        public void GetMetadataForPropertyWithNullContainerReturnsMetadataWithNullValuesForProperties() {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act
            provider.GetMetadataForProperties(null, typeof(PropertyModel)).ToList();   // Call ToList() to force the lazy evaluation to evaluate

            // Assert
            Assert.IsTrue(provider.CreateMetadataLog.Any());
            foreach (var parms in provider.CreateMetadataLog) {
                Assert.IsNull(parms.Model);
            }
        }
        public void GetMetadataForPropertyWithNullContainerReturnsMetadataWithNullValuesForProperties()
        {
            // Arrange
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act
            provider.GetMetadataForProperties(null, typeof(PropertyModel)).ToList(); // Call ToList() to force the lazy evaluation to evaluate

            // Assert
            Assert.True(provider.CreateMetadataFromPrototypeLog.Any());
            foreach (var parms in provider.CreateMetadataFromPrototypeLog)
            {
                Assert.Null(parms.Model);
            }
        }
Exemplo n.º 6
0
        public void GetMetadataForPropertiesCreatesMetadataForAllPropertiesOnModelWithPropertyValues()
        {
            // Arrange
            PropertyModel model = new PropertyModel
            {
                LocalAttributes    = 42,
                MetadataAttributes = "hello",
                MixedAttributes    = 21.12
            };
            TestableAssociatedMetadataProvider provider = new TestableAssociatedMetadataProvider();

            // Act
            provider.GetMetadataForProperties(model, typeof(PropertyModel)).ToList(); // Call ToList() to force the lazy evaluation to evaluate

            // Assert
            CreateMetadataParams local = provider.CreateMetadataLog.Single(
                m => m.ContainerType == typeof(PropertyModel) && m.PropertyName == "LocalAttributes"
                );

            Assert.Equal(typeof(int), local.ModelType);
            Assert.Equal(42, local.Model);
            Assert.Contains(local.Attributes, a => a is RequiredAttribute);

            CreateMetadataParams metadata = provider.CreateMetadataLog.Single(
                m =>
                m.ContainerType == typeof(PropertyModel) &&
                m.PropertyName == "MetadataAttributes"
                );

            Assert.Equal(typeof(string), metadata.ModelType);
            Assert.Equal("hello", metadata.Model);
            Assert.Contains(metadata.Attributes, a => a is RangeAttribute);

            CreateMetadataParams mixed = provider.CreateMetadataLog.Single(
                m => m.ContainerType == typeof(PropertyModel) && m.PropertyName == "MixedAttributes"
                );

            Assert.Equal(typeof(double), mixed.ModelType);
            Assert.Equal(21.12, mixed.Model);
            Assert.Contains(mixed.Attributes, a => a is RequiredAttribute);
            Assert.Contains(mixed.Attributes, a => a is RangeAttribute);
        }