Ejemplo n.º 1
0
        public void GetAllProducts()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <OnlineFishShopDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            Product product1 = new Product();

            product1.Name = "First";
            Product product2 = new Product();

            product2.Name = "Second";
            Product product3 = new Product();

            product3.Name = "Third";


            // Act
            using (var context = new OnlineFishShopDbContext(options))
            {
                context.Database.EnsureDeleted();
                var service = new GenericDataService <Product>(context);
                service.Add(product1);
                service.Add(product2);
                service.Add(product3);
            }

            // Assert
            using (var context = new OnlineFishShopDbContext(options))
            {
                var service = new GenericDataService <Product>(context);

                var allProds = service.GetAllAsync().Result;

                Assert.Equal(3, allProds.Count);
                Assert.NotNull(allProds.Find(p => p.Name == "First"));
                Assert.NotNull(allProds.Find(p => p.Name == "Second"));
                Assert.NotNull(allProds.Find(p => p.Name == "Third"));
            }
        }
Ejemplo n.º 2
0
        public void ShouldGetAll()
        {
            var db = VashiteKinti.Tests.Tests.GetDatabase();

            var item1 = new Bank()
            {
                Name = "ProCreditBank",
            };

            var item2 = new Bank()
            {
                Name = "DSK",
            };

            var items = new GenericDataService <Bank>(db);

            db.Banks.Add(item1);
            db.SaveChanges();

            var result = items.GetAllAsync();

            Assert.NotNull(result);
        }