예제 #1
0
        public void Navigation_back_pointer_is_fixed_up_as_navigation_is_added_and_removed()
        {
            var entityType1 = new EntityType(typeof(Customer));

            entityType1.SetKey(entityType1.AddProperty(Customer.IdProperty));
            var entityType2 = new EntityType(typeof(Customer));

            var navigation
                = new Navigation(
                      new ForeignKey(
                          entityType1.GetKey(),
                          new[] { entityType1.AddProperty(Customer.IdProperty) }), "Nav");

            entityType1.AddNavigation(navigation);

            Assert.Same(entityType1, navigation.EntityType);

            entityType2.AddNavigation(navigation);

            Assert.Same(entityType2, navigation.EntityType);
            Assert.Empty(entityType1.Navigations);

            entityType2.RemoveNavigation(navigation);

            Assert.Empty(entityType2.Navigations);
            Assert.Null(navigation.EntityType);
        }
        public void Delegate_getter_is_cached_by_type_and_property_name()
        {
            var entityType = new EntityType(typeof(MyEntity));
            var navigation = entityType.AddNavigation(new Navigation(Mock.Of <ForeignKey>(), "AsICollection"));

            var source = new ClrCollectionAccessorSource();

            Assert.Same(source.GetAccessor(navigation), source.GetAccessor(navigation));
        }
        private static Navigation CreateNavigation(string navigationName)
        {
            var entityType = new EntityType(typeof(MyEntity));
            var otherType  = new EntityType(typeof(MyOtherEntity));
            var foreignKey = otherType.GetOrAddForeignKey(
                entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true)),
                otherType.GetOrAddProperty("MyEntityId", typeof(int), shadowProperty: true));

            return(entityType.AddNavigation(new Navigation(foreignKey, navigationName, pointsToPrincipal: false)));
        }
        private static Model BuildModel()
        {
            var model = new Model();

            var entityType = new EntityType(typeof(Banana));
            var pkProperty = entityType.GetOrAddProperty("Id", typeof(int));
            var fkProperty = entityType.GetOrAddProperty("Fk", typeof(int));

            entityType.GetOrSetPrimaryKey(pkProperty);
            var fk = entityType.GetOrAddForeignKey(entityType.GetPrimaryKey(), fkProperty);

            entityType.GetOrAddProperty("Name", typeof(string));

            model.AddEntityType(entityType);

            entityType.AddNavigation(new Navigation(fk, "LesserBananas", pointsToPrincipal: false));
            entityType.AddNavigation(new Navigation(fk, "TopBanana", pointsToPrincipal: true));

            return(model);
        }
예제 #5
0
 private static void CloneNavigations(IEntityType sourceEntityType, EntityType targetEntityType)
 {
     foreach (var navigation in sourceEntityType.GetDeclaredNavigations())
     {
         var targetDependentEntityType = targetEntityType.Model.GetEntityType(navigation.ForeignKey.DeclaringEntityType.Name);
         var targetForeignKey          = targetDependentEntityType.GetForeignKey(
             navigation.ForeignKey.Properties.Select(p => targetDependentEntityType.GetProperty(p.Name)).ToList());
         var clonedNavigation = targetEntityType.AddNavigation(navigation.Name, targetForeignKey, pointsToPrincipal: navigation.PointsToPrincipal());
         navigation.Annotations.ForEach(annotation => clonedNavigation[annotation.Name] = annotation.Value);
     }
 }
예제 #6
0
        public void Can_add_navigations()
        {
            var entityType = new EntityType(typeof(Order));

            var navigation = new Navigation(new Mock <ForeignKey>().Object, "Milk");

            entityType.AddNavigation(navigation);

            Assert.Same(navigation, entityType.Navigations.Single());
            Assert.Same(entityType, navigation.EntityType);
        }
        public void Delegate_getter_is_cached_by_type_and_property_name()
        {
            var entityType = new EntityType(typeof(MyEntity));
            var otherType  = new EntityType(typeof(MyOtherEntity));
            var foreignKey = otherType.GetOrAddForeignKey(
                entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int), shadowProperty: true)),
                otherType.GetOrAddProperty("MyEntityId", typeof(int), shadowProperty: true));

            var navigation = entityType.AddNavigation(new Navigation(foreignKey, "AsICollection", pointsToPrincipal: false));

            var source = new ClrCollectionAccessorSource();

            Assert.Same(source.GetAccessor(navigation), source.GetAccessor(navigation));
        }
        private static void AccessorTest(string navigationName, Func <MyEntity, IEnumerable <Random> > reader)
        {
            var entityType = new EntityType(typeof(MyEntity));
            var navigation = entityType.AddNavigation(new Navigation(Mock.Of <ForeignKey>(), navigationName));

            var accessor = new ClrCollectionAccessorSource().GetAccessor(navigation);

            var entity = new MyEntity();
            var value  = new Random();

            Assert.False(accessor.Contains(entity, value));
            Assert.DoesNotThrow(() => accessor.Remove(entity, value));

            accessor.Add(entity, value);

            Assert.True(accessor.Contains(entity, value));
            Assert.Equal(1, reader(entity).Count());

            accessor.Remove(entity, value);

            Assert.False(accessor.Contains(entity, value));
            Assert.Equal(0, reader(entity).Count());
        }
예제 #9
0
        private static IModel BuildModel()
        {
            var model   = new Model();
            var builder = new BasicModelBuilder(model);

            builder.Annotation("ModelAnnotation1", "ModelValue1");
            builder.Annotation("ModelAnnotation2", "ModelValue2");

            var entityType1 = new EntityType(typeof(KoolEntity1));
            var property    = entityType1.GetOrAddProperty("Id1", typeof(int));

            entityType1.GetOrSetPrimaryKey(property);
            entityType1.GetOrAddProperty("Id2", typeof(Guid));
            entityType1.GetOrAddProperty("KoolEntity2Id", typeof(int));
            model.AddEntityType(entityType1);

            var entityType2 = new EntityType(typeof(KoolEntity2));

            entityType2.GetOrAddProperty("KoolEntity1Id1", typeof(int));
            entityType2.GetOrAddProperty("KoolEntity1Id2", typeof(Guid));
            entityType2.GetOrAddProperty("KoolEntity3Id", typeof(int));
            model.AddEntityType(entityType2);

            var entityType3 = new EntityType(typeof(KoolEntity3));

            entityType3.GetOrAddProperty("KoolEntity4Id", typeof(int));
            model.AddEntityType(entityType3);

            var entityType4 = new EntityType(typeof(KoolEntity4));

            model.AddEntityType(entityType4);

            var entityType5 = new EntityType(typeof(KoolEntity5));

            model.AddEntityType(entityType5);

            var entityType6 = new EntityType(typeof(KoolEntity6));

            entityType6.GetOrAddProperty("Kool5Id", typeof(int));
            model.AddEntityType(entityType6);

            for (var i = 7; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                Assert.NotNull(type);

                model.AddEntityType(new EntityType(type));
            }

            for (var i = 2; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);
                var id         = entityType.GetOrAddProperty(entityType.Type.GetProperty("Id"));
                entityType.GetOrSetPrimaryKey(id);
            }

            for (var i = 1; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);

                entityType.Annotations.Add(new Annotation("Annotation1", "Value1"));
                entityType.Annotations.Add(new Annotation("Annotation2", "Value2"));

                var foo = entityType.GetOrAddProperty(entityType.Type.GetProperty("Foo" + i));

                foo.Annotations.Add(new Annotation("Foo" + i + "Annotation1", "Foo" + i + "Value1"));
                foo.Annotations.Add(new Annotation("Foo" + i + "Annotation2", "Foo" + i + "Value2"));

                var goo = entityType.GetOrAddProperty(entityType.Type.GetProperty("Goo" + i));
            }

            var fk11 = entityType1.GetOrAddForeignKey(entityType2.GetPrimaryKey(), new[] { entityType1.GetProperty("KoolEntity2Id") });
            var fk21 = entityType2.GetOrAddForeignKey(entityType1.GetPrimaryKey(), new[] { entityType2.GetProperty("KoolEntity1Id1") });
            var fk22 = entityType2.GetOrAddForeignKey(entityType3.GetPrimaryKey(), new[] { entityType2.GetProperty("KoolEntity3Id") });
            var fk31 = entityType3.GetOrAddForeignKey(entityType4.GetPrimaryKey(), new[] { entityType3.GetProperty("KoolEntity4Id") });
            var fk61 = entityType6.GetOrAddForeignKey(entityType5.GetPrimaryKey(), new[] { entityType6.GetProperty("Kool5Id") });

            entityType1.AddNavigation(new Navigation(fk11, "NavTo2", pointsToPrincipal: true));
            entityType1.AddNavigation(new Navigation(fk21, "NavTo2s", pointsToPrincipal: false));
            entityType2.AddNavigation(new Navigation(fk21, "NavTo1", pointsToPrincipal: true));
            entityType2.AddNavigation(new Navigation(fk11, "NavTo1s", pointsToPrincipal: false));
            entityType2.AddNavigation(new Navigation(fk22, "NavTo3", pointsToPrincipal: true));
            entityType3.AddNavigation(new Navigation(fk22, "NavTo2s", pointsToPrincipal: false));
            entityType3.AddNavigation(new Navigation(fk31, "NavTo4", pointsToPrincipal: true));
            entityType4.AddNavigation(new Navigation(fk31, "NavTo3s", pointsToPrincipal: false));
            entityType5.AddNavigation(new Navigation(fk61, "Kool6s", pointsToPrincipal: false));
            entityType6.AddNavigation(new Navigation(fk61, "Kool5", pointsToPrincipal: true));

            return(model);
        }
예제 #10
0
        public void Navigations_are_ordered_by_name()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var customerForeignKeyProperty = orderType.AddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.AddForeignKey(customerForeignKeyProperty, customerKey);

            var specialOrderType = new EntityType(typeof(SpecialOrder), new Model());
            var specialCustomerForeignKeyProperty = specialOrderType.AddProperty(Order.CustomerIdProperty);
            var specialCustomerForeignKey = specialOrderType.AddForeignKey(specialCustomerForeignKeyProperty, customerKey);

            var navigation2 = customerType.AddNavigation("Orders", customerForeignKey, pointsToPrincipal: false);
            var navigation1 = customerType.AddNavigation("DerivedOrders", specialCustomerForeignKey, pointsToPrincipal: false);

            Assert.True(new[] { navigation1, navigation2 }.SequenceEqual(customerType.Navigations));
        }
        private static Model BuildModel()
        {
            var model = new Model();

            var entityType = new EntityType(typeof(Banana));
            var pkProperty = entityType.AddProperty("Id", typeof(int));
            var fkProperty = entityType.AddProperty("Fk", typeof(int));

            entityType.SetKey(pkProperty);
            var fk = entityType.AddForeignKey(entityType.GetKey(), fkProperty);

            entityType.AddProperty("Name", typeof(string));

            model.AddEntityType(entityType);

            entityType.AddNavigation(new Navigation(fk, "LesserBananas", pointsToPrincipal: false));
            entityType.AddNavigation(new Navigation(fk, "TopBanana", pointsToPrincipal: true));

            return model;
        }
예제 #12
0
        public void Can_add_and_remove_navigations()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
            Assert.Null(orderType.RemoveNavigation(new Navigation("Customer", customerForeignKey, pointsToPrincipal: true)));

            var customerNavigation = orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true);
            var ordersNavigation = customerType.AddNavigation("Orders", customerForeignKey, pointsToPrincipal: false);

            Assert.Equal("Customer", customerNavigation.Name);
            Assert.Same(orderType, customerNavigation.EntityType);
            Assert.Same(customerForeignKey, customerNavigation.ForeignKey);
            Assert.True(customerNavigation.PointsToPrincipal);
            Assert.False(customerNavigation.IsCollection());
            Assert.Same(customerType, customerNavigation.GetTargetType());
            Assert.Same(customerNavigation, customerForeignKey.GetNavigationToPrincipal());

            Assert.Equal("Orders", ordersNavigation.Name);
            Assert.Same(customerType, ordersNavigation.EntityType);
            Assert.Same(customerForeignKey, ordersNavigation.ForeignKey);
            Assert.False(ordersNavigation.PointsToPrincipal);
            Assert.True(ordersNavigation.IsCollection());
            Assert.Same(orderType, ordersNavigation.GetTargetType());
            Assert.Same(ordersNavigation, customerForeignKey.GetNavigationToDependent());

            Assert.Same(customerNavigation, orderType.Navigations.Single());
            Assert.Same(ordersNavigation, customerType.Navigations.Single());

            Assert.Same(customerNavigation, orderType.RemoveNavigation(customerNavigation));
            Assert.Null(orderType.RemoveNavigation(customerNavigation));
            Assert.Empty(orderType.Navigations);

            Assert.Same(ordersNavigation, customerType.RemoveNavigation(new Navigation("Orders", customerForeignKey, pointsToPrincipal: false)));
            Assert.Empty(customerType.Navigations);
        }
예제 #13
0
        public void Adding_a_navigation_that_belongs_to_a_different_type_throws()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            Assert.Equal(
                Strings.NavigationAlreadyOwned("Customer", typeof(Customer).FullName, typeof(Order).FullName),
                Assert.Throws<InvalidOperationException>(() => customerType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true)).Message);
        }
예제 #14
0
        private static IModel BuildModel()
        {
            var model = new Model();
            var builder = new ModelBuilder(model);

            builder.Annotation("ModelAnnotation1", "ModelValue1");
            builder.Annotation("ModelAnnotation2", "ModelValue2");

            var entityType1 = new EntityType(typeof(KoolEntity1));
            var property = entityType1.AddProperty("Id1", typeof(int));
            entityType1.SetKey(property);
            entityType1.AddProperty("Id2", typeof(Guid));
            entityType1.AddProperty("KoolEntity2Id", typeof(int));
            model.AddEntityType(entityType1);

            var entityType2 = new EntityType(typeof(KoolEntity2));
            entityType2.AddProperty("KoolEntity1Id1", typeof(int));
            entityType2.AddProperty("KoolEntity1Id2", typeof(Guid));
            entityType2.AddProperty("KoolEntity3Id", typeof(int));
            model.AddEntityType(entityType2);

            var entityType3 = new EntityType(typeof(KoolEntity3));
            entityType3.AddProperty("KoolEntity4Id", typeof(int));
            model.AddEntityType(entityType3);

            var entityType4 = new EntityType(typeof(KoolEntity4));
            model.AddEntityType(entityType4);

            var entityType5 = new EntityType(typeof(KoolEntity5));
            model.AddEntityType(entityType5);

            var entityType6 = new EntityType(typeof(KoolEntity6));
            entityType6.AddProperty("Kool5Id", typeof(int));
            model.AddEntityType(entityType6);

            for (var i = 7; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                Assert.NotNull(type);

                model.AddEntityType(new EntityType(type));
            }

            for (var i = 2; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);
                var id = entityType.AddProperty(entityType.Type.GetProperty("Id"));
                entityType.SetKey(id);
            }

            for (var i = 1; i <= 20; i++)
            {
                var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);

                var entityType = model.GetEntityType(type);

                entityType.Annotations.Add(new Annotation("Annotation1", "Value1"));
                entityType.Annotations.Add(new Annotation("Annotation2", "Value2"));

                var foo = entityType.AddProperty(entityType.Type.GetProperty("Foo" + i));

                foo.Annotations.Add(new Annotation("Foo" + i + "Annotation1", "Foo" + i + "Value1"));
                foo.Annotations.Add(new Annotation("Foo" + i + "Annotation2", "Foo" + i + "Value2"));

                var goo = entityType.AddProperty(entityType.Type.GetProperty("Goo" + i));
            }

            var fk11 = entityType1.AddForeignKey(entityType2.GetKey(), new[] { entityType1.GetProperty("KoolEntity2Id") });
            var fk21 = entityType2.AddForeignKey(entityType1.GetKey(), new[] { entityType2.GetProperty("KoolEntity1Id1") });
            var fk22 = entityType2.AddForeignKey(entityType3.GetKey(), new[] { entityType2.GetProperty("KoolEntity3Id") });
            var fk31 = entityType3.AddForeignKey(entityType4.GetKey(), new[] { entityType3.GetProperty("KoolEntity4Id") });
            var fk61 = entityType6.AddForeignKey(entityType5.GetKey(), new[] { entityType6.GetProperty("Kool5Id") });

            entityType1.AddNavigation(new Navigation(fk11, "NavTo2", pointsToPrincipal: true));
            entityType1.AddNavigation(new Navigation(fk21, "NavTo2s", pointsToPrincipal: false));
            entityType2.AddNavigation(new Navigation(fk21, "NavTo1", pointsToPrincipal: true));
            entityType2.AddNavigation(new Navigation(fk11, "NavTo1s", pointsToPrincipal: false));
            entityType2.AddNavigation(new Navigation(fk22, "NavTo3", pointsToPrincipal: true));
            entityType3.AddNavigation(new Navigation(fk22, "NavTo2s", pointsToPrincipal: false));
            entityType3.AddNavigation(new Navigation(fk31, "NavTo4", pointsToPrincipal: true));
            entityType4.AddNavigation(new Navigation(fk31, "NavTo3s", pointsToPrincipal: false));
            entityType5.AddNavigation(new Navigation(fk61, "Kool6s", pointsToPrincipal: false));
            entityType6.AddNavigation(new Navigation(fk61, "Kool5", pointsToPrincipal: true));

            return model;
        }
예제 #15
0
        public void Navigation_back_pointer_is_fixed_up_as_navigation_is_added_and_removed()
        {
            var entityType1 = new EntityType(typeof(Customer));
            entityType1.SetKey(entityType1.AddProperty(Customer.IdProperty));
            var entityType2 = new EntityType(typeof(Customer));

            var navigation
                = new Navigation(
                    new ForeignKey(
                        entityType1.GetKey(),
                        new[] { entityType1.AddProperty(Customer.IdProperty) }), "Nav", pointsToPrincipal: true);

            entityType1.AddNavigation(navigation);

            Assert.Same(entityType1, navigation.EntityType);

            entityType2.AddNavigation(navigation);

            Assert.Same(entityType2, navigation.EntityType);
            Assert.Empty(entityType1.Navigations);

            entityType2.RemoveNavigation(navigation);

            Assert.Empty(entityType2.Navigations);
            Assert.Null(navigation.EntityType);
        }
예제 #16
0
        public void Multiple_sets_of_navigations_using_the_same_foreign_key_are_not_allowed()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            customerType.AddNavigation("EnumerableOrders", customerForeignKey, pointsToPrincipal: false);

            Assert.Equal(
                Strings.MultipleNavigations("Orders", "EnumerableOrders", typeof(Customer).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => customerType.AddNavigation("Orders", customerForeignKey, pointsToPrincipal: false)).Message);
        }
예제 #17
0
        public void Reference_navigation_properties_must_be_of_the_target_type()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            Assert.Equal(
                Strings.NavigationSingleWrongClrType("OrderCustomer", typeof(Order).FullName, typeof(Order).FullName, typeof(Customer).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => orderType.AddNavigation("OrderCustomer", customerForeignKey, pointsToPrincipal: true)).Message);

            Assert.Equal(
                Strings.NavigationSingleWrongClrType("DerivedCustomer", typeof(Order).FullName, typeof(SpecialCustomer).FullName, typeof(Customer).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => orderType.AddNavigation("DerivedCustomer", customerForeignKey, pointsToPrincipal: true)).Message);
        }
예제 #18
0
        public void Collection_navigation_properties_must_be_IEnumerables_of_the_target_type()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            Assert.Equal(
                Strings.NavigationCollectionWrongClrType("NotCollectionOrders", typeof(Customer).FullName, typeof(Order).FullName, typeof(Order).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => customerType.AddNavigation("NotCollectionOrders", customerForeignKey, pointsToPrincipal: false)).Message);

            Assert.Equal(
                Strings.NavigationCollectionWrongClrType("DerivedOrders", typeof(Customer).FullName, typeof(IEnumerable<SpecialOrder>).FullName, typeof(Order).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => customerType.AddNavigation("DerivedOrders", customerForeignKey, pointsToPrincipal: false)).Message);
        }
예제 #19
0
        public void Adding_a_navigation_that_doesnt_match_a_CLR_property_throws()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            Assert.Equal(
                Strings.NoClrNavigation("Snook", typeof(Order).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => orderType.AddNavigation("Snook", customerForeignKey, pointsToPrincipal: true)).Message);
        }
예제 #20
0
        public void Adding_a_navigation_pointing_to_a_shadow_entity_type_throws()
        {
            var customerType = new EntityType("Customer", new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty("CustomerId", typeof(int), shadowProperty: true);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            Assert.Equal(
                Strings.NavigationToShadowEntity("Customer", typeof(Order).FullName, "Customer"),
                Assert.Throws<InvalidOperationException>(
                    () => orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true)).Message);
        }
예제 #21
0
        public void Can_add_navigations()
        {
            var entityType = new EntityType(typeof(Order));

            var navigation = new Navigation(new Mock<ForeignKey>().Object, "Milk", pointsToPrincipal: true);

            entityType.AddNavigation(navigation);

            Assert.Same(navigation, entityType.Navigations.Single());
            Assert.Same(entityType, navigation.EntityType);
        }
예제 #22
0
        public void Adding_a_new_navigation_with_a_name_that_already_exists_throws()
        {
            var customerType = new EntityType(typeof(Customer), new Model());
            var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));

            var orderType = new EntityType(typeof(Order), new Model());
            var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
            var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);

            orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true);

            Assert.Equal(
                Strings.DuplicateNavigation("Customer", typeof(Order).FullName),
                Assert.Throws<InvalidOperationException>(
                    () => orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true)).Message);
        }