Ejemplo n.º 1
0
        public void ShouldDisplayIndex()
        {
            ICustomerAdapter adapter = Substitute.For <ICustomerAdapter>();

            using (KnockoutController controller = new KnockoutController(adapter))
            {
                ActionResult result = controller.Index();

                ActionResultHelper.AssertView(result, controller.Views.Index);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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();
            }
        }