public void ValidateUpdateWineModel_ShouldReturnErrors_WhenInvalidYearAndRatingProvided()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id         = 50,
                Vintage    = 20500,
                YearBought = 202,
                DrinkFrom  = 20305,
                DrinkTo    = 42015,
                Rating     = 921,
                BottleSize = 100000
            };

            using var context = new DataContext(ContextOptions);
            var sut = new ValidateWineRepository(context);

            // __ Act __
            var result = sut.ValidateWineModel(model).ToList();

            // __ Assert __
            result.Should().Contain(x => x == "Vintage is not a valid year");
            result.Should().Contain(x => x == "Year bought is not a valid year");
            result.Should().Contain(x => x == "Drink from is not a valid year");
            result.Should().Contain(x => x == "Drink to is not a valid year");
            result.Should().Contain(x => x == "Rating is not between 1 and 100");
            result.Should().Contain(x => x == "Bottle size is invalid");
        }
        public void ValidateUpdateWineModel_ShouldReturnErrors_WhenMissingFkEntries()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id         = 50,
                RegionId   = 3,
                Region     = "Black valley",
                WineTypeId = 4,
                WineType   = "Chardonnay",
                VineyardId = 5,
                Vineyard   = "Steve's vineyard"
            };

            using var context = new DataContext(ContextOptions);
            var sut = new ValidateWineRepository(context);

            // __ Act __
            var result = sut.ValidateWineModel(model).ToList();

            // __ Assert __
            result.Should()
            .Contain(x => x.Contains("Vineyard id") && x.Contains("5") && x.Contains(CouldNotFindMessage));
            result.Should().Contain(x =>
                                    x.Contains("Wine type id") && x.Contains("4") && x.Contains(CouldNotFindMessage));
            result.Should().Contain(x => x.Contains("Region id") && x.Contains("3") && x.Contains(CouldNotFindMessage));
        }
Beispiel #3
0
        public void UpdateWine_ShouldReturnFalse_WhenGivenRequestModelInvalidId()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id        = 21,
                WineName  = "Sample",
                Region    = "Hunter Valley",
                Locations = new List <Location>
                {
                    new Location {
                        BoxNo = 2, Qty = 1
                    },
                }
            };

            using var context = new DataContext(ContextOptions);
            var sut = new CreateUpdateWineRepository(context);

            // __ Act __
            var result = sut.UpdateWine(model);

            // __ Assert __
            result.Should().BeFalse();
        }
Beispiel #4
0
        public void UpdateWine_ShouldUpdateWine_WhenGivenExistingRegionVineyardAndWineTypeAsDuplicates()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id       = 50,
                WineName = "Sample",
                Vineyard = "Mark's vineyard",
                Region   = "Yarra valley",
                WineType = "Shiraz"
            };

            using var context = new DataContext(ContextOptions);
            var sut = new CreateUpdateWineRepository(context);

            // __ Act __
            var result = sut.UpdateWine(model);

            // __ Assert __
            result.Should().BeTrue();
            var vineyard = context.Vineyards.Find(1);
            var region   = context.Regions.Find(1);
            var wineType = context.Winetypes.Find(1);
            var wine     = context.Winelists.First(x => x.Winename == "Sample");

            wine.Regionid.Should().Be(1);
            region.Region1.Should().Be("Yarra valley");
            wine.Vineyardid.Should().Be(1);
            vineyard.Vineyard1.Should().Be("Mark's vineyard");
            wine.Winetypeid.Should().Be(1);
            wineType.Winetype1.Should().Be("Shiraz");
        }
Beispiel #5
0
        public void UpdateWine_ShouldUpdateWine_WhenGivenValidRequestModelWithLocations()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id             = 50,
                WineName       = "Sample",
                PercentAlcohol = 14.5f,
                PricePaid      = 20.99m,
                Notes          = "These are my notes",
                Vintage        = 2000,
                Region         = "Hunter Valley",
                Locations      = new List <Location>
                {
                    new Location {
                        BoxNo = 55, Qty = 2
                    },
                    new Location {
                        BoxNo = 2, Qty = 1
                    },
                    new Location {
                        Qty = 3
                    }
                }
            };

            using var context = new DataContext(ContextOptions);
            var sut = new CreateUpdateWineRepository(context);

            // __ Act __
            var result = sut.UpdateWine(model);

            // __ Assert __
            result.Should().BeTrue();
            var region = context.Regions.Single(x => x.Region1 == "Hunter Valley");
            var wine   = context.Winelists.First(x => x.Winename == "Sample");

            wine.Winename.Should().Be("Sample");
            wine.Notes.Should().Be("These are my notes");
            wine.Vintage.Should().Be(2000);
            wine.Regionid.Should().Be(region.Id);
            region.Region1.Should().Be("Hunter Valley");

            var locations = context.Locations.Where(x => x.Wineid == wine.Id).ToList();

            wine.Locations.Select(x => x.Id).Should().BeEquivalentTo(locations.Select(x => x.Id));
            locations.Should().HaveCount(2);
            locations.Should().Contain(x => x.Box == 55 && x.No == 2);
            locations.Should().Contain(x => x.Box == 2 && x.No == 1);
            locations.Should().NotContain(x => x.No == 3);
        }
Beispiel #6
0
        public void UpdateWine_ShouldUpdateWine_WhenGivenValidRequestModel()
        {
            // __Arrange __
            var model = new UpdateWineRequest()
            {
                Id             = 50,
                WineName       = "Sample",
                PercentAlcohol = 14.5f,
                PricePaid      = 20.99m,
                Notes          = "These are my notes",
                Vintage        = 2000,
                YearBought     = 2002,
                DrinkFrom      = 2005,
                DrinkTo        = 2015,
                Rating         = 92,
                BottleSize     = 750,
                Region         = "Hunter Valley",
                Vineyard       = "Dave's place",
                WineType       = "Chardonnay"
            };

            using var context = new DataContext(ContextOptions);
            var sut = new CreateUpdateWineRepository(context);

            // __ Act __
            var result = sut.UpdateWine(model);

            // __ Assert __
            result.Should().BeTrue();
            var vineyard = context.Vineyards.Single(x => x.Vineyard1 == "Dave's place");
            var region   = context.Regions.Single(x => x.Region1 == "Hunter Valley");
            var wineType = context.Winetypes.Single(x => x.Winetype1 == "Chardonnay");
            var wine     = context.Winelists.First(x => x.Winename == "Sample");

            wine.Winename.Should().Be("Sample");
            wine.Percentalcohol.Should().Be(14.5f);
            wine.Pricepaid.Should().Be(20.99m);
            wine.Notes.Should().Be("These are my notes");
            wine.Vintage.Should().Be(2000);
            wine.Yearbought.Should().Be(2002);
            wine.Drinkrangefrom.Should().Be(2005);
            wine.Drinkrangeto.Should().Be(2015);
            wine.Rating.Should().Be(92);
            wine.Bottlesize.Should().Be(750);
            wine.Regionid.Should().Be(region.Id);
            region.Region1.Should().Be("Hunter Valley");
            wine.Vineyardid.Should().Be(vineyard.Id);
            vineyard.Vineyard1.Should().Be("Dave's place");
            wine.Winetypeid.Should().Be(wineType.Id);
            wineType.Winetype1.Should().Be("Chardonnay");
        }
Beispiel #7
0
        public IActionResult Put([FromBody] UpdateWineRequest wine)
        {
            var updated    = _createUpdateWineService.UpdateWine(wine, out var errors);
            var errorsList = errors.ToList();

            if (errorsList.Any())
            {
                return(BadRequest(new
                {
                    Errors = errorsList
                }));
            }

            return(updated ? (IActionResult)Ok() : Conflict(new { Error = "Cannot create wine" }));
        }
        public void ValidateUpdateWineModel_ShouldNotReturnErrors_WhenValidYearAndRatingProvided()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id         = 50,
                Vintage    = 2000,
                YearBought = 2002,
                DrinkFrom  = 2005,
                DrinkTo    = 2015,
                Rating     = 92,
                BottleSize = 750
            };

            using var context = new DataContext(ContextOptions);
            var sut = new ValidateWineRepository(context);

            // __ Act __
            var result = sut.ValidateWineModel(model);

            // __ Assert __
            result.Should().BeEmpty();
        }
        public void ValidateUpdateWineModel_ShouldNotReturnErrors_WhenFksExistsInDb()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id         = 50,
                RegionId   = 1,
                Region     = "Yarra valley",
                WineTypeId = 1,
                WineType   = "Shiraz",
                VineyardId = 1,
                Vineyard   = "Mark's vineyard"
            };

            using var context = new DataContext(ContextOptions);
            var sut = new ValidateWineRepository(context);

            // __ Act __
            var result = sut.ValidateWineModel(model);

            // __ Assert __
            result.Should().BeEmpty();
        }
        public void ValidateUpdateWineModel_ShouldReturnErrors_WhenWineListDoesNotExist()
        {
            // __Arrange __
            var model = new UpdateWineRequest
            {
                Id         = 30,
                RegionId   = 5,
                Region     = "Yarra valley 2",
                WineTypeId = 1,
                WineType   = "Shiraz",
                VineyardId = 1,
                Vineyard   = "Mark's vineyard"
            };

            using var context = new DataContext(ContextOptions);
            var sut = new ValidateWineRepository(context);

            // __ Act __
            var result = sut.ValidateWineModel(model);

            // __ Assert __
            result.Should().Contain(x =>
                                    x.Contains("Wine id") && x.Contains("30") && x.Contains(CouldNotFindMessage));
        }