Example #1
0
        public async Task InvokeAsync_BasketExists_ReturnsBasket(
            [Frozen] Mock <IBasketService> mockBasketService,
            [Greedy] CartList sut,
            Basket basket,
            ApplicationUser user
            )
        {
            //Arrange
            mockBasketService.Setup(_ => _.GetBasketAsync <Basket>(It.IsAny <string>()))
            .ReturnsAsync(basket);

            //Act
            var result = await sut.InvokeAsync(user);

            //Assert
            var viewResult = result.Should().BeAssignableTo <ViewViewComponentResult>().Subject;
            var viewModel  = viewResult.ViewData.Model.Should().Be(basket);
        }
Example #2
0
        public async Task InvokeAsync_Exception_ReturnsBasket(
            [Frozen] Mock <IBasketService> mockBasketService,
            [Greedy] CartList sut,
            ApplicationUser user
            )
        {
            //Arrange
            mockBasketService.Setup(_ => _.GetBasketAsync <Basket>(It.IsAny <string>()))
            .Throws <Exception>();

            //Act
            var result = await sut.InvokeAsync(user);

            //Assert
            var viewResult = result.Should().BeAssignableTo <ViewViewComponentResult>().Subject;
            var viewModel  = viewResult.ViewData.Model.Should().BeOfType <Basket>();
            var msg        = viewResult.ViewData["BasketInoperativeMsg"].Should().BeAssignableTo <string>().Subject;

            msg.Should().Match(_ => _.StartsWith("Basket Service is inoperative"));
        }