Exemplo n.º 1
0
            public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
            {
                var mockProperty = new MockPropertyInfo(typeof(List<string>), "Coll");
                mockProperty.SetupGet(p => p.CanWrite).Returns(false);

                var mockType = new MockType();
                mockType.Setup(m => m.GetProperties(It.IsAny<BindingFlags>())).Returns(new[] { mockProperty.Object });

                mockProperty.SetupGet(p => p.DeclaringType).Returns(mockType.Object);

                Assert.True(mockProperty.Object.IsValidStructuralProperty());
            }
Exemplo n.º 2
0
            public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
            {
                var mockProperty = new MockPropertyInfo(typeof(List <string>), "Coll");

                mockProperty.SetupGet(p => p.CanWrite).Returns(false);

                var mockType = new MockType();

                mockType.Setup(m => m.GetProperties(It.IsAny <BindingFlags>())).Returns(new[] { mockProperty.Object });

                mockProperty.SetupGet(p => p.DeclaringType).Returns(mockType.Object);

                Assert.True(mockProperty.Object.IsValidStructuralProperty());
            }
        public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
        {
            var mockProperty = new MockPropertyInfo(typeof(List<string>), "P");
            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.True(mockProperty.Object.IsValidStructuralProperty());
        }
        public void IsValidStructuralProperty_should_return_false_when_property_read_only()
        {
            var mockProperty = new MockPropertyInfo();
            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.False(mockProperty.Object.IsValidStructuralProperty());
        }
        public void IsValidStructuralProperty_should_return_true_when_property_read_only_collection()
        {
            var mockProperty = new MockPropertyInfo(typeof(List <string>), "P");

            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.True(mockProperty.Object.IsValidStructuralProperty());
        }
        public void IsValidStructuralProperty_should_return_false_when_property_read_only()
        {
            var mockProperty = new MockPropertyInfo();

            mockProperty.SetupGet(p => p.CanWrite).Returns(false);

            Assert.False(mockProperty.Object.IsValidStructuralProperty());
        }
        public void AddComplexProperty_ThrowsIfTypeIsDateTime(Type propertyType)
        {
            // Arrange
            MockType type = new MockType("Customer", @namespace: "Contoso");
            MockPropertyInfo property = new MockPropertyInfo(propertyType, "Birthday");
            property.SetupGet(p => p.ReflectedType).Returns(type);
            property.SetupGet(p => p.DeclaringType).Returns(type);

            Mock<StructuralTypeConfiguration> mock = new Mock<StructuralTypeConfiguration> { CallBase = true };
            StructuralTypeConfiguration configuration = mock.Object;
            mock.SetupGet(c => c.ClrType).Returns(type);

            // Act & Assert
            Assert.ThrowsArgument(
                () => configuration.AddComplexProperty(property),
                "propertyInfo",
                string.Format(
                    "The type '{0}' of property 'Birthday' in the 'Contoso.Customer' type is not a supported type.",
                    propertyType.FullName));
        }
        public void AddComplexProperty_ThrowsIfTypeIsDateTime(Type propertyType)
        {
            // Arrange
            MockType         type     = new MockType("Customer", @namespace: "Contoso");
            MockPropertyInfo property = new MockPropertyInfo(propertyType, "Birthday");

            property.SetupGet(p => p.ReflectedType).Returns(type);
            property.SetupGet(p => p.DeclaringType).Returns(type);

            Mock <StructuralTypeConfiguration> mock = new Mock <StructuralTypeConfiguration> {
                CallBase = true
            };
            StructuralTypeConfiguration configuration = mock.Object;

            mock.SetupGet(c => c.ClrType).Returns(type);

            // Act & Assert
            Assert.ThrowsArgument(
                () => configuration.AddComplexProperty(property),
                "propertyInfo",
                string.Format(
                    "The type '{0}' of property 'Birthday' in the 'Contoso.Customer' type is not a supported type.",
                    propertyType.FullName));
        }