[TestMethod] //Test the call of return view(), no args passed to the View function.
        public void TestCreateGetForBasketController()
        {
            BasketController basketController = new BasketController();
            ViewResult       result           = basketController.Create() as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual(string.Empty, result.ViewName);
        }
        public void Create_ShouldCall_BasketServiceCreate()
        {
            // Given
            var basketViewModel = new BasketViewModel();

            _basketService.Setup(x => x.Create()).Returns(basketViewModel);

            // When
            var result = _basketController.Create();

            // Then
            result.ShouldBe(basketViewModel);
        }
        public void Create_should_return_created_on_success()
        {
            _mockBasketService.Setup(x => x.CreateBasketForCustomer(_testCustomerId))
            .Returns(CreateBasketResult.Created);

            var mockRequest = new Mock <HttpRequest>();

            mockRequest.Setup(x => x.Scheme).Returns("http");

            var mockHttpContext = new Mock <HttpContext>();

            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);

            var fakeActionContext = new ActionContext()
            {
                HttpContext = mockHttpContext.Object
            };

            var mockUrlHelper = new Mock <IUrlHelper>();

            mockUrlHelper.Setup(x => x.ActionContext).Returns(fakeActionContext);
            mockUrlHelper.Setup(x => x.Action(It.IsAny <UrlActionContext>())).Returns("");

            _sut.Url = mockUrlHelper.Object;

            var result = _sut.Create(_testCustomerId);

            var createdResult = result as CreatedResult;

            createdResult?.StatusCode.Should().Be((int)HttpStatusCode.Created);

            var customerBasket = createdResult.Value as Basket;

            customerBasket?.CustomerId.Should().Be(_testCustomerId);
            _mockBasketService.Verify(x => x.CreateBasketForCustomer(_testCustomerId), Times.Once);
        }
Beispiel #4
0
        public async Task NewBasketItem_ShouldBeEdit_ShouldOk()
        {
            //Arrange
            var customer      = SetupStandardCustomer();
            var currentBasket = SetupProductsInBasket();
            var products      = SetupStandardProductsInStock();
            var fakeRepo      = SetupFakeRepo(customer, currentBasket, products);
            var mapper        = SetupMapper();
            var logger        = SetupLogger();
            var basketItem    = SetupStandardEditedBasketItem();
            var controller    = new BasketController(logger, fakeRepo, mapper);

            //Act
            var result = await controller.Create(basketItem);

            //Assert
            Assert.NotNull(result);
            var objResult = result as OkResult;

            Assert.NotNull(objResult);
        }
Beispiel #5
0
        public async Task NewBasketItem_RepoFailure_ShouldNotFound()
        {
            //Arrange
            var customer      = SetupStandardCustomer();
            var currentBasket = SetupProductsInBasket();
            var products      = SetupStandardProductsInStock();
            var fakeRepo      = SetupFakeRepo(customer, currentBasket, products);
            var mapper        = SetupMapper();
            var logger        = SetupLogger();
            var basketItem    = SetupStandardNewBasketItem();
            var controller    = new BasketController(logger, fakeRepo, mapper);

            fakeRepo.AcceptsBasketItems = false;

            //Act
            var result = await controller.Create(basketItem);

            //Assert
            Assert.NotNull(result);
            var objResult = result as NotFoundResult;

            Assert.NotNull(objResult);
        }
Beispiel #6
0
        public async Task NewBasketItem_NegativeQuantity_ShouldUnprocessableEntity()
        {
            //Arrange
            var customer      = SetupStandardCustomer();
            var products      = SetupStandardProductsInStock();
            var currentBasket = SetupProductsInBasket();
            var fakeRepo      = SetupFakeRepo(customer, currentBasket, products);
            var mapper        = SetupMapper();
            var logger        = SetupLogger();
            var basketItem    = SetupStandardNewBasketItem();
            var controller    = new BasketController(logger, fakeRepo, mapper);

            basketItem.Quantity = -1;

            //Act
            var result = await controller.Create(basketItem);

            //Assert
            Assert.NotNull(result);
            var objResult = result as UnprocessableEntityResult;

            Assert.NotNull(objResult);
        }