Ejemplo n.º 1
0
        public void Confirm_order_should_throw_expected_exception_if_status_is_wrong()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            controller.Cancel(1);
            Assert.ThrowsException <InvalidOperationException>(() => controller.Confirm(1));
        }
Ejemplo n.º 2
0
        public async Task Confirm_order_should_throw_expected_exception_if_status_is_wrong()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController(new Storage(), new StorageApiClientFake());

            controller.Create(inputNames);
            controller.Cancel(1);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => controller.Confirm(1));
        }
        public void Cancel_WithShoppingCartWithSupplements_ShouldReturnSuccessMessageAndReturnToDetails()
        {
            string successMessage = null;

            //Arrange
            ShoppingCart shoppingCart = new ShoppingCart()
            {
                Supplements = new List <SupplementInCartServiceModel>()
                {
                    new SupplementInCartServiceModel()
                }
            };

            byte[] shoppingCartAsByteArray = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(shoppingCart));

            Mock <ISession> session = new Mock <ISession>();

            session
            .Setup(s => s.TryGetValue(UserSessionShoppingCartKey, out shoppingCartAsByteArray))
            .Returns(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage = message as string);

            Mock <HttpContext> httpContext = new Mock <HttpContext>();

            httpContext
            .SetupGet(h => h.Session)
            .Returns(session.Object);

            OrdersController ordersController = new OrdersController(null, null, null)
            {
                TempData          = tempData.Object,
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext.Object
                }
            };

            var result = ordersController.Cancel();

            //Assert
            successMessage.Should().Be(CancelOrderSuccessMessage);

            result.Should().BeOfType <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be("Details");
        }
Ejemplo n.º 4
0
        public void Cancel_order_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            controller.Cancel(1);
            var actual = controller.Get(1);

            Assert.AreEqual(Order.OrderStatus.Cancelled, actual.Status);
        }
        public async Task CancelWithNewOrder_SetsState()
        {
            var orderStub = new Order();

            var orderServiceMock = new Mock <IOrderService>();

            orderServiceMock
            .Setup(p => p.GetByIdAsync(It.IsAny <long>()))
            .ReturnsAsync(orderStub);

            var controller = new OrdersController(orderServiceMock.Object);
            await controller.Cancel(orderId : 0);

            Assert.That(orderStub.State, Is.EqualTo(OrderState.Canceled));
        }
        public void Cancel_WithShoppingCartWithoutSupplements_ShouldReturnToHomeIndex()
        {
            //Arrange
            ShoppingCart shoppingCart = new ShoppingCart()
            {
                Supplements = new List <SupplementInCartServiceModel>()
            };

            byte[] shoppingCartAsByteArray = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(shoppingCart));

            Mock <ISession> session = new Mock <ISession>();

            session
            .Setup(s => s.TryGetValue(UserSessionShoppingCartKey, out shoppingCartAsByteArray))
            .Returns(true);

            Mock <HttpContext> httpContext = new Mock <HttpContext>();

            httpContext
            .SetupGet(h => h.Session)
            .Returns(session.Object);

            OrdersController ordersController = new OrdersController(null, null, null)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext.Object
                }
            };

            //Act
            var result = ordersController.Cancel();

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be("Index");
            result.As <RedirectToActionResult>().ControllerName.Should().Be("Home");
        }