public void Add_AddSingleProduct(string productName) { //Arrange var options = new DbContextOptionsBuilder <OnlineFishShopDbContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; Product product = new Product(); product.Name = productName; // Act using (var context = new OnlineFishShopDbContext(options)) { context.Database.EnsureDeleted(); var service = new GenericDataService <Product>(context); service.Add(product); } // Assert using (var context = new OnlineFishShopDbContext(options)) { Assert.Equal(1, context.Products.Count()); Assert.Equal(productName, context.Products.Single().Name); } }
public void ShouldUpdateItems() { var db = VashiteKinti.Tests.Tests.GetDatabase(); var item1 = new Bank() { Name = "ProCreditBank", }; var item2 = new Bank() { Name = "DSK", }; var items = new GenericDataService <Bank>(db); items.Add(item1, item2); item1.Name = "Updated"; items.Update(item1); var editItem = db.Banks.FirstOrDefault(x => x.Name == item1.Name); Assert.Equal(item1.Name, editItem.Name); }
public void Add_AddMultipleProductsOneByOne() { //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)) { Product first = context.Products.Where(p => p.Name == "First").FirstOrDefault(); Product second = context.Products.Where(p => p.Name == "Second").FirstOrDefault(); Product third = context.Products.Where(p => p.Name == "Third").FirstOrDefault(); Assert.Equal(3, context.Products.Count()); Assert.NotNull(first); Assert.NotNull(second); Assert.NotNull(third); } }
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")); } }
public void GetAllWithName() { //Arrange var options = new DbContextOptionsBuilder <OnlineFishShopDbContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; Product product1 = new Product(); product1.Name = "SomeName"; Product product2 = new Product(); product2.Name = "SomeName"; Product product3 = new Product(); product3.Name = "AName"; // 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 getWithName = service.GetListAsync(p => p.Name == "SomeName").Result; Assert.Equal(2, getWithName.Count); Assert.True(getWithName.First().Name == "SomeName"); } }
public void AddMethodShouldAddItems() { var db = VashiteKinti.Tests.Tests.GetDatabase(); var item1 = new Bank() { Name = "ProCreditBank", }; var item2 = new Bank() { Name = "DSK", }; var items = new GenericDataService <Bank>(db); items.Add(item1, item2); var result = db.Banks.ToArray().Count(); Assert.Equal(2, result); }