public void TestAddNewCustomer() { var view = new Mock <ISalesFormView>(); ISalesModel model = new SalesModel(new CustomerRepository()); ISalesFormController controller = new SalesFormController(view.Object, model); // Press the new-customer button controller.NewCustomer(); // verify that the controller notifies the view to show the customer view.Verify(x => x.ShowCustomerInfo(It.IsAny <Customer>())); view.Verify(x => x.FocusCustomerEditFields(), Times.Once); // confirm that the customer is set to 'new customer' Assert.IsTrue(model.CurrentCustomer.Firstname == "New"); Assert.IsTrue(model.CurrentCustomer.Surname == "Customer"); }
public void TestDeleteDisableWithNewCustomerSelected() { IRepository <Customer> customerRepo = new CustomerRepository(); ISalesModel model = new SalesModel(customerRepo); var view = new Mock <ISalesFormView>(); bool? deleteCustomerEnabled = null; // Setup the view to monitor what parameters have been passed to the view mock view.Setup(x => x.EnableDeleteCustomer(It.IsAny <bool>())) .Callback <bool>((b) => deleteCustomerEnabled = b); ISalesFormController controller = new SalesFormController(view.Object, model); controller.NewCustomer(); // verify that the EnableDeleteCustomer was called on the view and the last state was false // to reflect that the new customer cannot be deleted from the database view.Verify(x => x.EnableDeleteCustomer(It.Is <bool>(y => y == false)), Times.AtLeastOnce); Assert.IsTrue(deleteCustomerEnabled == false, "Delete Customer Button is enabled for new customer"); }
public void TestAddNewCustomerAndSave() { var view = new Mock <ISalesFormView>(); ISalesModel model = new SalesModel(new CustomerRepository()); view.Setup(x => x.CustomerFirstname).Returns("Anthony"); view.Setup(x => x.CustomerLastname).Returns("Taylor"); ISalesFormController controller = new SalesFormController(view.Object, model); controller.NewCustomer(); view.Verify(x => x.ShowCustomerInfo(It.IsAny <Customer>())); // Hit the save changes button controller.SaveChanges(); // confirm that we have saves a new customer with the expected name Customer c = model.FindCustomerById(model.CurrentCustomer.Id); Assert.IsTrue(c.Firstname == "Anthony"); Assert.IsTrue(c.Surname == "Taylor"); }