public void CreateCustomerCreateCustomerSuccessful() { //setup Mock <DatabaseContext> mockContext = DataCreation.CreateDataContext(); CustomerController controller = new CustomerController(mockContext.Object); //create a new customer Customer newCustomer = new Customer() { FirstName = "Han", LastName = "Solo", DateOfBirth = new System.DateTime(1994, 1, 20), Email = "*****@*****.**", PersonId = 10 }; newCustomer.CustCode = DataCreation.CreateCustomerCode( newCustomer.FirstName, newCustomer.LastName, newCustomer.DateOfBirth); //Act RedirectToRouteResult result = controller.CreateCustomer(newCustomer) as RedirectToRouteResult; //verify Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["controller"], "Home"); }
public void CreateCustomerCreateCustomerAlreadyExists() { //setup Mock <DatabaseContext> mockContext = DataCreation.CreateDataContext(); CustomerController controller = new CustomerController(mockContext.Object); Customer newCustomer = new Customer() { FirstName = "George", LastName = "Hammond", DateOfBirth = new System.DateTime(2000, 04, 20), Email = "*****@*****.**", PersonId = 10 }; newCustomer.CustCode = DataCreation.CreateCustomerCode( newCustomer.FirstName, newCustomer.LastName, newCustomer.DateOfBirth); //Act ViewResult result = controller.CreateCustomer(newCustomer) as ViewResult; //verify Assert.AreEqual(result.TempData["message"], "Customer Already Exists"); }