コード例 #1
0
        public void ShouldUpdateCustomerAndRedirectToIndex()
        {
            ICustomerAdapter adapter = Substitute.For <ICustomerAdapter>();

            using (ClassicController controller = new ClassicController(adapter))
            {
                CustomerData data   = new CustomerData();
                ActionResult result = controller.Edit(data);

                adapter.Received().UpdateCustomer(data);

                ActionResultHelper.AssertRedirected(result, controller.Name, controller.ActionNames.Index);
            }
        }
コード例 #2
0
        public void ShouldRedisplayViewWhenEditValidationFails()
        {
            ICustomerAdapter adapter = Substitute.For <ICustomerAdapter>();

            using (ClassicController controller = new ClassicController(adapter))
            {
                controller.ModelState.AddModelError("txtName", "You must provide a name for the customer.");

                CustomerData data   = new CustomerData();
                ActionResult result = controller.Edit(data);

                CustomerData model = ActionResultHelper.AssertViewWithModel <CustomerData>(result, controller.Views.Edit);
                Assert.AreSame(data, model, "The model was not passed to the view.");
            }
        }
コード例 #3
0
        public void ShouldRetrieveCustomerForEdit()
        {
            ICustomerAdapter adapter = Substitute.For <ICustomerAdapter>();
            CustomerData     data    = new CustomerData();

            adapter.GetCustomer(Arg.Any <string>()).Returns(data);

            using (ClassicController controller = new ClassicController(adapter))
            {
                string       customerId = Guid.NewGuid().ToString("N");
                ActionResult result     = controller.Edit(customerId);

                CustomerData model = ActionResultHelper.AssertViewWithModel <CustomerData>(result, controller.Views.Edit);

                adapter.Received().GetCustomer(customerId);

                Assert.AreSame(data, model, "The customer data was not passed to the view.");
            }
        }