public void Configuration_should_return_internal_configuration()
        {
            var complexTypeConfiguration = new ComplexTypeConfiguration<object>();

            Assert.NotNull(complexTypeConfiguration.Configuration);
            Assert.Equal(typeof(ComplexTypeConfiguration), complexTypeConfiguration.Configuration.GetType());
        }
        public void Configure_should_set_configuration()
        {
            var complexType = new ComplexType("C");
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object));

            complexTypeConfiguration.Configure(complexType);

            Assert.Same(complexTypeConfiguration, complexType.GetConfiguration());
        }
        public void Ignore_configures_complex_type_properties()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new ComplexTypeConfiguration(type);
            var config = new ConventionTypeConfiguration<LocalEntityType>(type, () => innerConfig, new ModelConfiguration());

            config.Ignore(t => t.Property1);

            Assert.Equal(1, innerConfig.IgnoredProperties.Count());
            Assert.True(innerConfig.IgnoredProperties.Any(p => p.Name == "Property1"));
        }
        public void Configure_should_throw_when_property_not_found()
        {
            var complexType = new ComplexType("C");
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object));
            var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
            complexTypeConfiguration.Property(new PropertyPath(new MockPropertyInfo()), () => mockPropertyConfiguration.Object);

            Assert.Equal(
                Strings.PropertyNotFound(("P"), "C"),
                Assert.Throws<InvalidOperationException>(() => complexTypeConfiguration.Configure(complexType)).Message);
        }
        public void Configure_should_configure_properties()
        {
            var complexType = new ComplexType("C");

            var property1 = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            complexType.AddMember(property1);
            var property = property1;
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(object));
            var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>();
            var mockPropertyInfo = new MockPropertyInfo();
            complexTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object);
            property.SetClrPropertyInfo(mockPropertyInfo);

            complexTypeConfiguration.Configure(complexType);

            mockPropertyConfiguration.Verify(p => p.Configure(property));
        }
        public void AddConfigurationTypesToModel_adds_complextypeconfigurations_into_model()
        {
            var complexTypeConfiguration = new ComplexTypeConfiguration(typeof(Random));

            var filter = new Mock<ConfigurationTypeFilter>();
            filter.Setup(f => f.IsEntityTypeConfiguration(It.IsAny<Type>())).Returns(false);
            filter.Setup(f => f.IsComplexTypeConfiguration(It.IsAny<Type>())).Returns(true);

            var activator = new Mock<ConfigurationTypeActivator>();
            activator.Setup(a => a.Activate<ComplexTypeConfiguration>(It.IsAny<Type>()))
                     .Returns(complexTypeConfiguration);

            var finder = new ConfigurationTypesFinder(activator.Object, filter.Object);

            var modelConfiguration = new ModelConfiguration();
            finder.AddConfigurationTypesToModel(new[] { typeof(Object) }, modelConfiguration);

            Assert.Same(complexTypeConfiguration, modelConfiguration.ComplexType(typeof(Random)));
        }
Ejemplo n.º 7
0
            public void Invokes_action_with_value_when_not_null()
            {
                var actionInvoked = false;
                object capturedValue = null;
                var value = new object();
                var convention = new TypeConventionWithHaving<object, object>(
                    Enumerable.Empty<Func<Type, bool>>(),
                    t => value,
                    (c, v) =>
                        {
                            actionInvoked = true;
                            capturedValue = v;
                        });
                var type = typeof(object);
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.True(actionInvoked);
                Assert.Same(value, capturedValue);
            }
            public void Invokes_action_when_all_predicates_true()
            {
                var actionInvoked = false;
                var convention = new TypeConvention(
                    new Func<Type, bool>[]
                        {
                            t => true,
                            t => true
                        },
                    c => actionInvoked = true);
                var type = new MockType();
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.True(actionInvoked);
            }
        internal virtual void Add(ComplexTypeConfiguration complexTypeConfiguration)
        {
            //Contract.Requires(complexTypeConfiguration != null);

            if ((_entityConfigurations.ContainsKey(complexTypeConfiguration.ClrType)
                 || _complexTypeConfigurations.ContainsKey(complexTypeConfiguration.ClrType)))
            {
                throw Error.DuplicateStructuralTypeConfiguration(complexTypeConfiguration.ClrType);
            }

            _complexTypeConfigurations.Add(complexTypeConfiguration.ClrType, complexTypeConfiguration);
        }
Ejemplo n.º 10
0
 private ComplexTypeConfiguration(ComplexTypeConfiguration source)
     : base((StructuralTypeConfiguration)source)
 {
 }
        public void Property_returns_configuration_for_complex_type_properties()
        {
            var type = typeof(AType);
            var innerConfig = new ComplexTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            config.IsComplexType();
            var result = config.Property("Property5");

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("Property5", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(decimal), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType<Properties.Primitive.DecimalPropertyConfiguration>(result.Configuration());
        }
        public virtual ComplexTypeConfiguration ComplexType(Type complexType)
        {
            //Contract.Requires(complexType != null);

            if (_entityConfigurations.ContainsKey(complexType))
            {
                throw Error.ComplexTypeConfigurationMismatch(complexType.FullName);
            }

            ComplexTypeConfiguration complexTypeConfiguration;
            if (!_complexTypeConfigurations.TryGetValue(complexType, out complexTypeConfiguration))
            {
                _complexTypeConfigurations.Add(
                    complexType, complexTypeConfiguration = new ComplexTypeConfiguration(complexType));
            }

            return complexTypeConfiguration;
        }
            public void Does_not_invoke_action_when_predicate_false_but_same_type()
            {
                var actionInvoked = false;
                var convention = new TypeConvention<LocalType1>(
                    new Func<Type, bool>[] { t => false },
                    c => actionInvoked = true);
                var type = typeof(LocalType1);
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.False(actionInvoked);
            }
 private ComplexTypeConfiguration(ComplexTypeConfiguration source)
     : base(source)
 {
 }
            public void Does_not_invoke_action_when_no_predicates_and_different_type()
            {
                var actionInvoked = false;
                var convention = new TypeConvention<LocalType1>(
                    Enumerable.Empty<Func<Type, bool>>(),
                    c => actionInvoked = true);
                var type = typeof(object);
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.False(actionInvoked);
            }
            public void Does_not_invoke_action_and_short_circuts_when_different_type()
            {
                var predicateInvoked = false;
                var actionInvoked = false;
                var convention = new TypeConvention<LocalType1>(
                    new Func<Type, bool>[] { t => predicateInvoked = true },
                    c => actionInvoked = true);
                var type = typeof(object);
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.False(predicateInvoked);
                Assert.False(actionInvoked);
            }
Ejemplo n.º 17
0
            public void Does_not_invoke_action_when_value_null()
            {
                var actionInvoked = false;
                var convention = new TypeConventionWithHaving<object, object>(
                    Enumerable.Empty<Func<Type, bool>>(),
                    t => null,
                    (c, v) => actionInvoked = true);
                var type = typeof(object);
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.False(actionInvoked);
            }
            public void Invokes_action_when_no_predicates_and_derived_type()
            {
                var actionInvoked = false;
                var convention = new TypeConvention<LocalType1>(
                    Enumerable.Empty<Func<Type, bool>>(),
                    c => actionInvoked = true);
                var type = typeof(LocalType2);
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.True(actionInvoked);
            }
Ejemplo n.º 19
0
            public void Does_not_invoke_action_when_last_predicate_false()
            {
                var actionInvoked = false;
                var convention = new TypeConvention(
                    new Func<Type, bool>[]
                        {
                            t => true,
                            t => false
                        },
                    c => actionInvoked = true);
                var type = new MockType();
                var configuration = new ComplexTypeConfiguration(type);

                convention.Apply(type, () => configuration, new ModelConfiguration());

                Assert.False(actionInvoked);
            }
Ejemplo n.º 20
0
        public virtual ComplexTypeConfiguration ComplexType(Type complexType)
        {
            Check.NotNull(complexType, "complexType");

            if (_entityConfigurations.ContainsKey(complexType))
            {
                throw Error.ComplexTypeConfigurationMismatch(complexType.FullName);
            }

            ComplexTypeConfiguration complexTypeConfiguration;
            if (!_complexTypeConfigurations.TryGetValue(complexType, out complexTypeConfiguration))
            {
                _complexTypeConfigurations.Add(
                    complexType, complexTypeConfiguration = new ComplexTypeConfiguration(complexType));
            }

            return complexTypeConfiguration;
        }
Ejemplo n.º 21
0
        internal virtual void Add(ComplexTypeConfiguration complexTypeConfiguration)
        {
            DebugCheck.NotNull(complexTypeConfiguration);

            if ((_entityConfigurations.ContainsKey(complexTypeConfiguration.ClrType)
                 || _complexTypeConfigurations.ContainsKey(complexTypeConfiguration.ClrType)))
            {
                throw Error.DuplicateStructuralTypeConfiguration(complexTypeConfiguration.ClrType);
            }

            _complexTypeConfigurations.Add(complexTypeConfiguration.ClrType, complexTypeConfiguration);
        }
Ejemplo n.º 22
0
        public void Ignore_configures_complex_type_property()
        {
            var type = new MockType()
                .Property<int>("Property1");
            var innerConfig = new ComplexTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            config.IsComplexType();
            config.Ignore("Property1");

            Assert.Equal(1, innerConfig.IgnoredProperties.Count());
            Assert.True(innerConfig.IgnoredProperties.Any(p => p.Name == "Property1"));
        }
Ejemplo n.º 23
0
 private ComplexTypeConfiguration(ComplexTypeConfiguration source)
     : base(source)
 {
 }