public void WhenANewProductIsCreated_ItIsAddedToTheDatabase() { int originalNum = _crud.RetrieveAll <Product>().Count; _crud.Create("newTest", 10, "testURL"); Assert.That(originalNum + 1, Is.EqualTo(_crud.RetrieveAll <Product>().Count)); Product newProduct = _crud.GetProductByName("newTest"); _crud.Delete(newProduct); }
public void OneTimeSetUp() { DbContextOptions <ProjectContext> options = new DbContextOptionsBuilder <ProjectContext>() .UseInMemoryDatabase(databaseName: "Test_DB") .Options; ProjectContext context = new ProjectContext(options); productService = new ProductService(context); _crud = new CRUDManagerProduct(productService); _crud.Create("test", 5, "testURL"); }
private void button_add_Click(object sender, RoutedEventArgs e) { (bool, decimal)priceInput = validator.CheckDecimalInput(textBox_price_value.Text); if (!priceInput.Item1) { MessageBox.Show("Price must be a numeric value"); return; } if (CrudProduct.ExistsByName(textBox_name_value.Text)) { MessageBox.Show($"Product: {textBox_name_value.Text} already exists"); return; } CrudProduct.Create(textBox_name_value.Text, priceInput.Item2, textBox_URL_value.Text); MessageBox.Show($"Product: {textBox_name_value.Text} created"); }