public void Initialization_for_navigation_without_parameterless_constructor_throws() { var accessor = new ClrCollectionAccessorFactory().Create(CreateNavigation("AsMyUnavailableCollection")); Assert.Equal( CoreStrings.NavigationCannotCreateType( "AsMyUnavailableCollection", typeof(MyEntity).Name, typeof(MyUnavailableCollection).Name), Assert.Throws <InvalidOperationException>( () => accessor.Add(new MyEntity(false), new MyOtherEntity(), forMaterialization: false)).Message); }
private static void AccessorTest( string navigationName, Func <MyEntity, IEnumerable <MyOtherEntity> > reader, bool initializeCollections = true) { var accessor = new ClrCollectionAccessorFactory().Create(CreateNavigation(navigationName)); var entity = new MyEntity(initializeCollections); var value = new MyOtherEntity(); Assert.False(accessor.Contains(entity, value)); 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()); }