예제 #1
0
        public void Valid_Order_Goes_To_Submitter_And_Displays_Completed_View()
        {
            // Arrange
            var            mockSubmitter           = new Moq.Mock <IOrderSubmitter>();
            var            mockCreditCardProcessor = new Moq.Mock <ICreditCardProcessor>();
            CartController controller = new CartController(null, mockSubmitter.Object, mockCreditCardProcessor.Object);
            var            mocks      = new ContextMocks(controller);

            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);

            var formData = new FormCollection {
                { "Name", "Steve" },
                { "Line1", "123 My Street" },
                { "Line2", "MyArea" },
                { "Line3", "" },
                { "City", "MyCity" },
                { "State", "Some State" },
                { "Zip", "123ABCDEF" },
                { "Country", "Far far away" },
                { "GiftWrap", bool.TrueString },
                { "CardNumber", "CardNumberValue" },
                { "CardholderName", "CardholderNameValue" },
                { "ExpiryDate", "expirydateValue" },
                { "SecurityCode", "SecurityCodeValue" },
            };

            // check out
            var result = controller.CheckOut(cart, formData);

            Assert.AreEqual("Completed", result.ViewName);
            mockSubmitter.Verify(x => x.SubmitOrder(cart));
            Assert.AreEqual(0, cart.Lines.Count);
        }
예제 #2
0
        public void Homepage_Recognizes_Previous_Visitor()
        {
            // Arrange
            var controller = new SimpleController();
            var mocks      = new ContextMocks(controller);

            controller.Request.Cookies.Add(new HttpCookie("HasVisitedBefore", bool.TrueString));

            // Act
            ViewResult result = controller.Homepage();

            // Assert (this time, demonstrating NUnit's alternative "constraint" syntax)
            Assert.That(result.ViewName, Is.EqualTo("HomePage") | Is.Empty);
            Assert.That((bool)result.ViewData["IsFirstVisit"], Is.False);
        }
예제 #3
0
        public void Homepage_Recognizes_New_Visitor_And_Sets_Cookie()
        {
            // Arrange
            var controller = new SimpleController();
            var mocks      = new ContextMocks(controller); // Sets up complete mock context

            // Act
            ViewResult result = controller.Homepage();

            // Assert
            Assert.IsEmpty(result.ViewName);
            Assert.IsTrue((bool)result.ViewData["IsFirstVisit"]);
            Assert.AreEqual(1, controller.Response.Cookies.Count);
            Assert.AreEqual(bool.TrueString,
                            controller.Response.Cookies["HasVisitedBefore"].Value);
        }
예제 #4
0
        public void Submitting_Empty_Shipping_Details_Displays_Default_View_With_Error()
        {
            // Arrange
            CartController controller = new CartController(null, null, null);
            var            mocks      = new ContextMocks(controller);

            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);
            // Act
            var result = controller.CheckOut(cart, new FormCollection {
                { "Name", "" }
            });

            // Assert
            Assert.IsEmpty(result.ViewName);
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }