public void Delete02Test() { var orderRepository = new TestOrderRepository(); CartController target = new CartController(orderRepository, new TestProductRepository()); ControllerContext context = new ControllerContext(new MockHttpContext(), new RouteData(), target); context.HttpContext.Session["TxID"] = "1"; target.ControllerContext = context; int beforeNum = orderRepository.GetByTxID("1").OrderDetails.Count; int detailID = -100; int expectedNum = beforeNum; RedirectToRouteResult actual = target.Delete(detailID) as RedirectToRouteResult; int actualNum = orderRepository.GetByTxID("1").OrderDetails.Count; //Assert.AreEqual(expectedNum, actualNum); //Assert.IsNotNull(actual); Assert.Fail("想定された例外 System.ArgumentNullException が発生しません"); }
public void IndexPOST02Test() { CartController target = new CartController(new TestOrderRepository(), new TestProductRepository()); ControllerContext context = new ControllerContext(new MockHttpContext(), new RouteData(), target); context.HttpContext.Session["TxID"] = "aaaaaaaaa"; target.ControllerContext = context; FormCollection collection = null; string expectedAction = "Sorry"; string expectedController = "Result"; RedirectToRouteResult actual; actual = target.Index(collection) as RedirectToRouteResult; Assert.AreEqual(expectedAction, actual.RouteValues["action"]); Assert.AreEqual(expectedController, actual.RouteValues["controller"]); }
public void IndexGETTest1() { CartController target = new CartController(new TestOrderRepository(), new TestProductRepository()); ControllerContext context = new ControllerContext(new MockHttpContext(), new RouteData(), target); context.HttpContext.Session["TxID"] = "dummy"; target.ControllerContext = context; string expectedAction = "Empty"; string expectedController = null; RedirectToRouteResult actual; actual = target.Index() as RedirectToRouteResult; Assert.AreEqual(expectedAction, actual.RouteValues["action"]); Assert.AreEqual(expectedController, actual.RouteValues["controller"]); }
public void IndexGETTest2() { CartController target = new CartController(new TestOrderRepository(), new TestProductRepository()); ControllerContext context = new ControllerContext(new MockHttpContext(), new RouteData(), target); context.HttpContext.Session["TxID"] = "1"; target.ControllerContext = context; ViewResult actual; actual = target.Index() as ViewResult; Assert.IsNotNull(actual.ViewData.Model); Assert.IsNotNull(actual.ViewData["TotalMoney"]); }
public void EmptyTest() { CartController target = new CartController(new TestOrderRepository(), new TestProductRepository()); string expectedViewname = string.Empty; ViewResult actual; actual = target.Empty() as ViewResult; Assert.IsNotNull(actual); Assert.AreEqual(expectedViewname, actual.ViewName); }