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 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", pointsToPrincipal: false)); var source = new ClrCollectionAccessorSource(); Assert.Same(source.GetAccessor(navigation), source.GetAccessor(navigation)); }
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); }
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, pointsToPrincipal: true)); 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()); }