Exemple #1
0
        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 void Enumerable_backed_by_non_collection_throws(Action <IClrCollectionAccessor, MyEntity, MyOtherEntity> test)
        {
            var accessor = new ClrCollectionAccessorFactory().Create(CreateNavigation("AsIEnumerableNotCollection"));

            var entity = new MyEntity(initialize: true);
            var value  = new MyOtherEntity();

            Assert.Equal(
                CoreStrings.NavigationBadType(
                    "AsIEnumerableNotCollection", typeof(MyEntity).Name, typeof(MyEnumerable).Name, typeof(MyOtherEntity).Name),
                Assert.Throws <InvalidOperationException>(() => test(accessor, entity, value)).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());
        }