public Product CreateProduct(Product product) { if (product.CategoryID.HasValue && GetCategory(product.CategoryID.Value) == null) { throw new ApplicationException("Invalid category relation"); } return(_productRepository.Create(product)); }
public void Create_Product_ShouldAddProduct() { //arrange SqlProductRepository productRepository = new SqlProductRepository(connectionString); Product product = new Product("p11", "Hammer", 2.20); //act bool created = productRepository.Create(product); //assert Assert.True(created); Assert.Contains(product, productRepository.SelectAll()); }
public async Task AddProductTest() { using (var contex = new ApplicationDbContext(_options)) { var repository = new SqlProductRepository(contex); await repository.Create(new Domain.Product() { Title = "test", Model = "a", Price = 10 }); var result = repository.GetList(); Assert.True(await result.CountAsync() > 0); } }