示例#1
0
        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");
        }
示例#2
0
        public void ViewAllCustomersShowingAllAvailable()
        {
            //setup
            Mock <DatabaseContext> mockContext = DataCreation.CreateDataContext();
            CustomerController     controller  = new CustomerController(mockContext.Object);

            //Act
            ViewResult      result    = controller.ListCustomer() as ViewResult;
            List <Customer> modelList = result.Model as List <Customer>;

            //verify
            Assert.AreEqual(modelList.Count, 8);
            Assert.AreEqual(result.TempData.Values.Count, 0);
        }
示例#3
0
        public void VerifyOldestFiveArePresentAndCorrect()
        {
            //setup
            Mock <DatabaseContext> mockContext = DataCreation.CreateDataContext();
            HomeController         controller  = new HomeController(mockContext.Object);

            //Act
            ViewResult result = controller.Index() as ViewResult;

            List <Customer> modelList = result.Model as List <Customer>;

            //Verify model contains the correct number of customers and no error messages
            Assert.AreEqual(modelList.Count, 5);
            Assert.AreEqual(result.TempData.Values.Count, 0);

            //Verify model is in correct order
            Assert.IsTrue(modelList.FindIndex(x => x.PersonId == 4).Equals(0));
            Assert.IsTrue(modelList.FindIndex(x => x.PersonId == 3).Equals(1));
            Assert.IsTrue(modelList.FindIndex(x => x.PersonId == 8).Equals(2));
            Assert.IsTrue(modelList.FindIndex(x => x.PersonId == 5).Equals(3));
            Assert.IsTrue(modelList.FindIndex(x => x.PersonId == 6).Equals(4));
        }
示例#4
0
        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");
        }