public void TestChangeCustomerDetails() { IRepository <Customer> customerRepo = new CustomerRepository(); customerRepo.Insert(new Customer("Anthony", "Lucas")); customerRepo.Insert(new Customer("Sophia", "Rees")); customerRepo.Insert(new Customer("Thomas", "Perkins")); ISalesModel model = new SalesModel(customerRepo); model.CurrentCustomer = customerRepo.GetAll()[1]; var view = new Mock <ISalesFormView>(); view.Setup(x => x.CustomerFirstname).Returns("Victoria"); view.Setup(x => x.CustomerLastname).Returns("Briggs"); ISalesFormController controller = new SalesFormController(view.Object, model); controller.SaveChanges(); // verify that the controller notifies the view to show the customer view.Verify(x => x.ShowCustomerInfo(It.IsAny <Customer>())); // confirm that the customer is set to 'new customer' Assert.IsTrue(model.CurrentCustomer.Firstname == "Victoria"); Assert.IsTrue(model.CurrentCustomer.Surname == "Briggs"); // Verify that the model has been updated. Assert.IsTrue(model.GetAllCustomers()[1].Firstname == "Victoria"); Assert.IsTrue(model.GetAllCustomers()[1].Surname == "Briggs"); }
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"); }