public void ShouldDisplayIndex()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            using (KnockoutController controller = new KnockoutController(adapter))
            {
                ActionResult result = controller.Index();

                ActionResultHelper.AssertView(result, controller.Views.Index);
            }
        }
        public void ShouldDeleteCustomer()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            using (KnockoutController controller = new KnockoutController(adapter))
            {
                string customerId = Guid.NewGuid().ToString("N");
                ActionResult result = controller.Delete(customerId);

                ActionResultHelper.AssertHttpStatusCode(result, HttpStatusCode.OK);

                adapter.Received().RemoveCustomer(customerId);
            }
        }
        public void ShouldLoadCustomers()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            IEnumerable<CustomerData> data = new List<CustomerData>() { new CustomerData() };
            adapter.GetCustomers().Returns(data);
            using (KnockoutController controller = new KnockoutController(adapter))
            {
                ActionResult result = controller.Load();

                CustomerData[] model = ActionResultHelper.AssertJson<CustomerData[]>(result);
                Assert.AreEqual(1, model.Length, "There should have been one customer.");
                Assert.AreSame(data.First(), model[0], "The wrong customer was returned.");

                adapter.Received().GetCustomers();
            }
        }
        public void ShouldCreateAndReturnCustomer()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            CustomerData added = new CustomerData();
            adapter.AddCustomer(Arg.Any<CustomerData>()).Returns(added);
            using (KnockoutController controller = new KnockoutController(adapter))
            {
                CustomerData data = new CustomerData();
                ActionResult result = controller.Create(data);

                CustomerData model = ActionResultHelper.AssertJsonWithHttpStatusCode<CustomerData>(result, HttpStatusCode.Created);
                Assert.AreSame(added, model, "The added customer was not returned.");

                adapter.Received().AddCustomer(data);
            }
        }
        public void ShouldUpdateCustomer()
        {
            ICustomerAdapter adapter = Substitute.For<ICustomerAdapter>();
            using (KnockoutController controller = new KnockoutController(adapter))
            {
                CustomerData data = new CustomerData();
                ActionResult result = controller.Edit(data);

                ActionResultHelper.AssertHttpStatusCode(result, HttpStatusCode.OK);

                adapter.Received().UpdateCustomer(data);
            }
        }