예제 #1
0
        public void In_memory_DbSet_can_be_used_for_RemoveRange()
        {
            var products = new[] { new Product(), new Product() };
            var set      = new InMemoryDbSet <Product>(products);

            Assert.Same(products, set.RemoveRange(products));
            Assert.Empty(set);
        }
예제 #2
0
        public void In_memory_DbSet_can_be_used_for_Attach()
        {
            var set     = new InMemoryDbSet <Product>();
            var product = new Product();

            Assert.Same(product, set.Attach(product));
            Assert.Same(product, set.Single());
        }
예제 #3
0
        public void In_memory_DbSet_can_be_used_for_Remove()
        {
            var set     = new InMemoryDbSet <Product>();
            var product = new Product();

            set.Add(product);

            Assert.Same(product, set.Remove(product));
            Assert.Empty(set);
        }
예제 #4
0
        public void In_memory_DbSet_can_be_used_for_AddOrUpdate_with_expression()
        {
            DbSet <Product> set = new InMemoryDbSet <Product>();

            set.AddOrUpdate(e => e.Id, new Product {
                Id = 1
            }, new Product {
                Id = 2
            });

            Assert.Equal(new[] { 1, 2 }, set.Select(p => p.Id).OrderBy(i => i));
        }
예제 #5
0
        public void In_memory_DbSet_can_be_used_for_AddRange()
        {
            var set      = new InMemoryDbSet <Product>();
            var products = new[] { new Product {
                                       Id = 1
                                   }, new Product {
                                       Id = 2
                                   } };

            Assert.Same(products, set.AddRange(products));
            Assert.Equal(products.OrderBy(p => p.Id), set.OrderBy(p => p.Id));
        }
예제 #6
0
        public void In_memory_DbSet_can_be_used_for_FindAsync()
        {
            var product = new Product {
                Id = 1
            };
            var set = new InMemoryDbSet <Product>(
                new[] { product, new Product {
                            Id = 2
                        } },
                (d, k) => d.Single(p => p.Id == (int)k[0]));

            Assert.Same(product, set.FindAsync(1).Result);
        }