public void Dispose()
        {
            _optionsBuilder = null;

            // Cleanup any created database items.
            foreach (var aWine in _dbContext.Wines)
            {
                _dbContext.Wines.Remove(aWine);
            }
            foreach (var aVarietal in _dbContext.Varietals)
            {
                _dbContext.Varietals.Remove(aVarietal);
            }
            foreach (var aBottleSize in _dbContext.BottleSizes)
            {
                _dbContext.BottleSizes.Remove(aBottleSize);
            }
            foreach (var aWinery in _dbContext.Wineries)
            {
                _dbContext.Wineries.Remove(aWinery);
            }
            _dbContext.SaveChanges( );
            _dbContext.Dispose( );

            _controller = null;
        }
Ejemplo n.º 2
0
        public async Task CreateWineAsync_WhenCalled_CreatesAWineDtoToReturnToClient()
        {
            // 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 wineForCreationDto = new WineForCreationDto()
            {
                Name     = "Red Wine",
                Vineyard = "My Vineyard"
            };
            var actionResult = await _controller.CreateWineAsync(wineForCreationDto).ConfigureAwait(false);

            // Assert
            var result = Assert.IsType <CreatedAtRouteResult>(actionResult.Result);
            var wineDtoReturnedToClient = Assert.IsType <WineDto>(result.Value);

            Assert.Equal("Red Wine", wineDtoReturnedToClient.Name);
        }
        public WineControllerTests()
        {
            // Create inMemory database for testing.
            _optionsBuilder = new DbContextOptionsBuilder <WineCellarDBContext>( );
            _optionsBuilder.UseInMemoryDatabase("WineUnitTestInMemDB");
            _dbContext = new WineCellarDBContext(_optionsBuilder.Options);

            // Create commands controller for testing.
            _controller = new WineController(_dbContext, new NullLogger <WineController>( ));
        }
Ejemplo n.º 4
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.º 5
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);
        }
Ejemplo n.º 6
0
 public WineControllerTest() : base()
 {
     _wineController = new WineController(RavenStore);
 }