public async Task GetProductById_Returns_Correct_Product() { //Arrange Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >(); SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object); Product newProduct1 = new Product { DeliveryPrice = 20, Description = "Test Desc", Name = "Test Product", Price = 1000 }; await sqliteProductRepository.CreateProduct(newProduct1); var products = await sqliteProductRepository.GetAllProducts(); //Act var result = await sqliteProductRepository.GetProductById(products[0].Id); //Assert Assert.Equal(newProduct1.Name, result.Name); Assert.Equal(newProduct1.Description, result.Description); Assert.Equal(newProduct1.Price, result.Price); Assert.Equal(newProduct1.DeliveryPrice, result.DeliveryPrice); }
public async Task UpdateProduct_Updates_Product_Correctly() { //Arrange Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >(); SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object); Product newProduct1 = new Product { DeliveryPrice = 20, Description = "Test Desc", Name = "Test Product", Price = 1000 }; await sqliteProductRepository.CreateProduct(newProduct1); var products = await sqliteProductRepository.GetAllProducts(); Product updatedProduct = new Product { Id = products[0].Id, DeliveryPrice = 200, Description = "Test Desc 1", Name = "Test Product 1", Price = 3000 }; //Act await sqliteProductRepository.UpdateProduct(updatedProduct); var result = await sqliteProductRepository.GetProductById(updatedProduct.Id); //Assert Assert.Equal(updatedProduct.Id, result.Id); Assert.Equal(updatedProduct.Name, result.Name); Assert.Equal(updatedProduct.Description, result.Description); Assert.Equal(updatedProduct.Price, result.Price); Assert.Equal(updatedProduct.DeliveryPrice, result.DeliveryPrice); }