private static void AccessorTest( string navigationName, Func <MyEntity, IEnumerable <MyOtherEntity> > reader, bool initializeCollections = true) { var accessor = new ClrCollectionAccessorSource(new CollectionTypeFactory()).GetAccessor(CreateNavigation(navigationName)); var entity = new MyEntity(); var value = new MyOtherEntity(); if (initializeCollections) { entity.InitializeCollections(); } 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()); }
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()); }