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 TestDeleteCustomerConfirmPrompt()
        {
            IRepository <Customer> repo = new CustomerRepository();

            repo.Insert(new Customer()
            {
                Firstname = "Delete", Surname = "Me"
            });
            repo.Insert(new Customer()
            {
                Firstname = "Don't Delete", Surname = "Me"
            });
            ISalesModel model = new SalesModel(repo);

            model.CurrentCustomer = model.GetAllCustomers()[0];

            // setup the view, so that the displayed question to confirm to delete
            // the custoemr is confirmed.
            var view = new Mock <ISalesFormView>();

            view.Setup(x => x.DisplayQuestion(It.IsAny <string>())).Returns(true);

            ISalesFormController controller = new SalesFormController(view.Object, model);

            controller.DeleteCustomer();

            // verify the view was notified for confirmation to delete the customer
            view.Verify(x => x.DisplayQuestion(It.IsAny <string>()), Times.Once);
            view.Verify(x => x.ClearCustomerInfo(), Times.AtLeastOnce);

            // confirm there is only one customer in the repository now.

            Assert.IsTrue(model.GetAllCustomers().Count == 1);
        }
        public void TestDeleteCustomerDeclinePrompt()
        {
            IRepository <Customer> repo = new CustomerRepository();

            repo.Insert(new Customer()
            {
                Firstname = "Delete", Surname = "Me"
            });
            ISalesModel model = new SalesModel(repo);

            model.CurrentCustomer = model.GetAllCustomers()[0];

            var view = new Mock <ISalesFormView>();

            view.Setup(x => x.DisplayQuestion(It.IsAny <string>())).Returns(false);

            ISalesFormController controller = new SalesFormController(view.Object, model);

            controller.DeleteCustomer();
            view.Verify(x => x.DisplayQuestion(It.IsAny <string>()), Times.Once);

            Assert.IsTrue(model.GetAllCustomers().Count == 1);
        }
        public void TestDeleteCustomerEnabledWithSelection()
        {
            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);
            var         view  = new Mock <ISalesFormView>();

            model.CurrentCustomer = model.GetAllCustomers()[0];

            ISalesFormController controller = new SalesFormController(view.Object, model);

            view.Verify(x => x.EnableDeleteCustomer(It.Is <bool>(y => y == true)));
        }