Ejemplo n.º 1
0
        public async Task GetWines_WhenCalled_ReturnsAllItems()
        {
            // Arrange
            var wineList = new List <Wine>()
            {
                new Wine()
                {
                    Id = "5da3ab6639977d41082450c2", Name = "Mind Blowing Merlot", Notes = "Just goes great with everything.", Year = 2008
                },
                new Wine()
                {
                    Id = "5da3ad0ef351f857309400ff", Name = "Marvelous Malbec", Notes = "A wine for a quiet evening.", Year = 2011
                },
                new Wine()
                {
                    Id = "5da3b1d4f351f85730940101", Name = "Shining Shiraz", Notes = "This will get the party going.", Year = 2017
                }
            };

            IWineRepository         wineService         = GetWineServiceStub(wineList);
            IWinePurchaseRepository winePurchaseService = GetWinePurchaseServiceStub();


            var response    = Substitute.For <HttpResponse>();
            var httpContext = Substitute.For <HttpContext>();

            httpContext.Items.Add("response", response);

            var factory = new LoggerFactory();
            var logger  = factory.CreateLogger <WineController>();

            _controller = new WineController(logger, wineService, winePurchaseService, _mapper);
            _controller.ControllerContext.HttpContext = httpContext;
            _controller.Url = Substitute.For <IUrlHelper>();

            // Act
            var actionResult = await _controller.GetWinesAsync();;

            // Assert
            var result = Assert.IsType <OkObjectResult>(actionResult.Result);
            var wines  = Assert.IsType <List <WineDto> >(result.Value);

            Assert.Equal(3, wines.Count);
        }
Ejemplo n.º 2
0
        public async Task GetWines_WhenCalled_ReturnsOkResult()
        {
            // Arrange
            IWineRepository         wineService         = GetWineServiceStub();
            IWinePurchaseRepository winePurchaseService = GetWinePurchaseServiceStub();
            var response    = Substitute.For <HttpResponse>();
            var httpContext = Substitute.For <HttpContext>();

            httpContext.Items.Add("response", response);

            var factory = new LoggerFactory();
            var logger  = factory.CreateLogger <WineController>();

            _controller = new WineController(logger, wineService, winePurchaseService, _mapper);
            _controller.ControllerContext.HttpContext = httpContext;
            _controller.Url = Substitute.For <IUrlHelper>();

            // Act
            var actionResult = await _controller.GetWinesAsync();

            // Assert
            Assert.IsType <OkObjectResult>(actionResult.Result);
        }