public void Can_set_entity_type() { var navigation = new Navigation(new Mock<ForeignKey>().Object, "TheBattle", pointsToPrincipal: true); var entityType = new Mock<EntityType>().Object; navigation.EntityType = entityType; Assert.Same(entityType, navigation.EntityType); Assert.Same(entityType, ((INavigation)navigation).EntityType); }
public void Can_create_navigation() { var foreignKey = CreateForeignKey(); var navigation = new Navigation("Deception", foreignKey); Assert.Same(foreignKey, navigation.ForeignKey); Assert.Equal("Deception", navigation.Name); Assert.Same(foreignKey.DeclaringEntityType, navigation.DeclaringEntityType); }
public void Can_create_navigation_to_collection_of_dependents() { var foreignKey = CreateForeignKey(); foreignKey.IsUnique = false; var navigation = new Navigation("Deception", foreignKey, pointsToPrincipal: false); Assert.Same(foreignKey, navigation.ForeignKey); Assert.Equal("Deception", navigation.Name); Assert.NotNull(navigation.EntityType); Assert.False(navigation.PointsToPrincipal); Assert.True(navigation.IsCollection()); }
private void CheckNavigation(Navigation value, Navigation otherNavigation) { if (value != null) { if (value.ForeignKey != this) { throw new InvalidOperationException( Strings.NavigationForWrongForeignKey(value.Name, value.EntityType.DisplayName(), this, value.ForeignKey)); } if (value == otherNavigation) { throw new InvalidOperationException(Strings.NavigationToSelfDuplicate(value.Name)); } } }
public void Can_create_navigation_to_collection_of_dependents() { var keyMock = new Mock<ForeignKey>(); keyMock.Setup(m => m.IsUnique).Returns(false); var foreignKey = keyMock.Object; var navigation = new Navigation(foreignKey, "Deception", pointsToPrincipal: false); Assert.Same(foreignKey, navigation.ForeignKey); Assert.Equal("Deception", navigation.Name); Assert.Null(navigation.EntityType); Assert.False(navigation.PointsToPrincipal); Assert.True(navigation.IsCollection()); Assert.Same(foreignKey, ((INavigation)navigation).ForeignKey); Assert.Null(((INavigation)navigation).EntityType); }
public void Throws_setting_same_navigation_to_dependent_as_is_set_to_principal() { var foreignKey = CreateSelfRefFK(); var navigation = new Navigation("Deception", foreignKey, pointsToPrincipal: true); Assert.Equal( Strings.NavigationToSelfDuplicate("Deception"), Assert.Throws<InvalidOperationException>(() => foreignKey.PrincipalToDependent = navigation).Message); }
public void Throws_setting_navigation_to_dependent_on_wrong_FK() { var foreignKey1 = CreateOneToManyFK(); var foreignKey2 = CreateSelfRefFK(); var navigation = new Navigation("Deception", foreignKey1, pointsToPrincipal: false); Assert.Equal( Strings.NavigationForWrongForeignKey("Deception", "OneToManyPrincipal", foreignKey2, foreignKey1), Assert.Throws<InvalidOperationException>(() => foreignKey2.PrincipalToDependent = navigation).Message); }
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); }
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); }