public async Task ThrowNullExc_If_BeerAlreadyExists()
        {
            var options      = TestUtils.GetOptions(nameof(ThrowNullExc_If_BeerAlreadyExists));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var beer = new Beer
            {
                Name = "Ariana"
            };

            var beerDTO = new BeerDTO
            {
                Name = "Ariana"
            };

            using (var arrangeContext = new BeeroverflowContext(options))
            {
                await arrangeContext.Beers.AddAsync(beer);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut = new BeerService(assertContext, mockDateTime.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.CreateBeerAsync(beerDTO));
            }
        }
Ejemplo n.º 2
0
        private void AddSalesToViewList()
        {
            var viewListData = new ObservableCollection <SalesGrid>();

            viewListData = BeerService.ShowAllSales();
            this.ListViewSales.ItemsSource = viewListData;
        }
Ejemplo n.º 3
0
        public void GetBeerFilterSearch_CorrectPaging()
        {
            // arrange
            var beer1 = new Beer {
                ID = 1
            };
            var beer2 = new Beer {
                ID = 2
            };

            beerDatabase.Add(beer1.ID, beer1);
            beerDatabase.Add(beer2.ID, beer2);

            var expected = new List <Beer>()
            {
                beer1, beer2
            };
            int expectedSize = expected.Count;

            Filter filter = new Filter {
                CurrentPage = 1, ItemsPrPage = 2
            };
            BeerService service = new BeerService(repoMock.Object, repoBrandMock.Object, repoTypeMock.Object, validatorMock.Object);

            // act
            var result = service.GetBeerFilterSearch(filter);

            // assert
            Assert.Equal(expected, result.List);
            Assert.Equal(expectedSize, result.totalItems);
            repoMock.Verify(repo => repo.ReadBeersFilterSearch(It.Is <Filter>(f => f == filter)), Times.Once);
        }
Ejemplo n.º 4
0
        public void RemoveBeer_BeerDoesNotExist_ExpectArgumentException()
        {
            // arrange

            BeerService service = new BeerService(repoMock.Object, repoBrandMock.Object, repoTypeMock.Object, validatorMock.Object);

            Beer beer = new Beer()
            {
                ID          = 1,
                Name        = "FimusBryg",
                Description = "Kobberfarvet",
                Price       = 56,
                Percentage  = 6.6,
                IBU         = 2.2,
                EBC         = 1.1,
                Stock       = 22,
                ImageURL    = "x.png"
            };

            // act + assert
            var ex = Assert.Throws <InvalidOperationException>(() => service.DeleteBeer(beer.ID));

            // assert
            Assert.Equal("No beer with such ID found", ex.Message);
            repoMock.Verify(repo => repo.ReadBeerById(It.Is <int>(ID => ID == beer.ID)), Times.Once);
            repoMock.Verify(repo => repo.DeleteBeerInRepo(It.Is <int>(ID => ID == beer.ID)), Times.Never);
        }
Ejemplo n.º 5
0
        public void GetBeerFilterSearch_IndexOutOfBounds_ExpectInvalidDataException()
        {
            // arrange
            repoMock.Setup(repo => repo.ReadBeersFilterSearch(It.IsAny <Filter>())).Returns(() => throw new InvalidDataException("Index out of bounds"));

            var beer1 = new Beer {
                ID = 1
            };
            var beer2 = new Beer {
                ID = 2
            };

            beerDatabase.Add(beer1.ID, beer1);
            beerDatabase.Add(beer2.ID, beer2);

            Filter filter = new Filter {
                CurrentPage = 2, ItemsPrPage = 2
            };
            BeerService service = new BeerService(repoMock.Object, repoBrandMock.Object, repoTypeMock.Object, validatorMock.Object);

            // act
            var ex = Assert.Throws <InvalidDataException>(() => service.GetBeerFilterSearch(filter));

            // assert
            Assert.Equal("Index out of bounds", ex.Message);
            repoMock.Verify(repo => repo.ReadBeersFilterSearch(It.Is <Filter>(f => f == filter)), Times.Once);
        }
Ejemplo n.º 6
0
        public void GetAllBeers(int beerCount)
        {
            // arrange
            Beer beer1 = new Beer {
                ID = 1
            };
            Beer beer2 = new Beer {
                ID = 2
            };
            List <Beer> beers = new List <Beer>()
            {
                beer1, beer2
            };

            var expected = beers.GetRange(0, beerCount);

            foreach (var beer in expected)
            {
                beerDatabase.Add(beer.ID, beer);
            }

            BeerService service = new BeerService(repoMock.Object, repoBrandMock.Object, repoTypeMock.Object, validatorMock.Object);

            // act
            var result = service.GetAllBeer();

            // assert
            Assert.Equal(expected, result);
            repoMock.Verify(repo => repo.ReadBeers(), Times.Once);
        }
Ejemplo n.º 7
0
        protected async Task OnSearchAsync()
        {
            Beers = (await BeerService.GetBreweryDBData(searchTerm));

            //using (var reader = new StreamReader("wwwroot\\Assets\\beers.csv"))
            //using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
            //{
            //    var temp_csv = (csv.GetRecords<OpenBeerDB_Model>()).ToList();
            //    results_csv = temp_csv.Where(x => x.name.ToLower().Contains(searchTerm));
            //}

            //if (results_csv != null)
            //{
            //    foreach (var x in results_csv)
            //    {
            //        Beers.Add(new Beer
            //        {
            //            name = x.name,
            //            desc = x.descript,
            //            abv = x.abv,
            //            src = "CSV"
            //        });
            //    }
            //}

            //Beers.Distinct().OrderBy(x => x.name);
        }
Ejemplo n.º 8
0
        public static BeerService Beer(this UntappdClient client, int id)
        {
            BeerService service = BeerService.Instance(id);

            service.Client = client;
            return(service);
        }
Ejemplo n.º 9
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Beer   beerToUpdate   = this.DataContext as Beer;
            string newStyle       = String.Empty;
            string newDistributor = String.Empty;
            string newBrewery     = String.Empty;

            if (this.cbStyles.SelectedItem != null)
            {
                newStyle = this.cbStyles.SelectedItem.ToString();
            }
            if (this.cbDistributors.SelectedItem != null)
            {
                newDistributor = this.cbDistributors.SelectedItem.ToString();
            }
            if (this.cbBreweries.SelectedItem != null)
            {
                newBrewery = this.cbBreweries.SelectedItem.ToString();
            }

            BeerService.UpdateBeer(beerToUpdate, newStyle, newDistributor, newBrewery);
            this.Close();
            SearchEditBeerWin searchEditBeerWin = new SearchEditBeerWin();

            searchEditBeerWin.ShowDialog();
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var customerName = cbClients.SelectedItem.ToString();
            Dictionary <string, int> beersQuantity = new Dictionary <string, int>();

            foreach (var beer in _soldBeers)
            {
                if (beer.Quantity > 0)
                {
                    beersQuantity.Add(beer.Name, beer.Quantity);
                }
            }

            if (beersQuantity.Count == 0)
            {
                WarningLabel.Visibility = Visibility.Visible;
                WarningLabel.Content    = "There isn't selected beers or enough beer quantity for sale.";
                return;
            }

            BeerService.AddSale(beersQuantity, customerName);
            this.Close();
            //MainWindow mainWindow = new MainWindow();
            //mainWindow.Show();
        }
Ejemplo n.º 11
0
        public void ShouldUpdateBeer()
        {
            //Arrange
            var db = GetDatabase();


            var b1 = new Beer()
            {
                Name        = "First",
                Description = "First Description",
                Price       = 12.12m,
                ImageUrl    = "test",
                Country     = "London"
            };

            //Act

            var Beers = new BeerService(db);

            Beers.Add(b1);

            b1.Name = "UpdatedBeer";
            Beers.Update(b1);

            //Assert
            Beers.GetList(x => x.Name == "UpdatedBeer").Count.Should().Be(1);
        }
Ejemplo n.º 12
0
 public static BeerCheckinsEndpoint Checkins(this BeerService beerService)
 {
     return(new BeerCheckinsEndpoint {
         Service = beerService,
         MaxResults = 25
     });
 }
Ejemplo n.º 13
0
        public void ShouldDeleteBeer()
        {
            //Arrange
            var db = GetDatabase();
            var b1 = new Beer()
            {
                Name        = "First",
                Description = "First Description",
                Price       = 12.12m,
                ImageUrl    = "test",
                Country     = "London"
            };


            var b2 = new Beer()
            {
                Name        = "Second",
                Description = "Second Description",
                Price       = 8.99m,
                ImageUrl    = "test",
                Country     = "Bulgaria"
            };

            var Beers = new BeerService(db);

            Beers.Add(b1, b2);

            //Act

            Beers.Remove(b2);
            //Assert

            Beers.GetAll().Count.Should().Be(1);
        }
Ejemplo n.º 14
0
        public void ShouldReturnAllBeers()
        {
            //Arrange
            var db = GetDatabase();

            var b1 = new Beer()
            {
                Name        = "First",
                Description = "First Description",
                ImageUrl    = "test",
                Price       = 12.12m,
                Country     = "London"
            };

            var b2 = new Beer()
            {
                Name        = "Second",
                Description = "Second Description",
                Price       = 8.99m,
                ImageUrl    = "test",
                Country     = "Bulgaria"
            };

            var Beers = new BeerService(db);

            Beers.Add(b1, b2);

            //Act
            var result = Beers.GetAll();

            //Assert
            result.Should().BeOfType <List <Beer> >();

            result.Should().HaveCount(2);
        }
Ejemplo n.º 15
0
        public async Task AllBySearchAsyncGetCorrectResults()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstBeer = new Beer {
                Id = 1, Name = "Zagorka"
            };
            var secondBeer = new Beer {
                Id = 2, Name = "Staropramen"
            };
            var thirdBeer = new Beer {
                Id = 3, Name = "Duff"
            };

            db.Beers.AddRange(firstBeer, secondBeer, thirdBeer);
            await db.SaveChangesAsync();

            var beerService = new BeerService(db);

            // Act
            //var result = await beerService.AllBySearchAsync(1, 3, "a");

            // Assert
            var list = new List <Beer> {
                firstBeer, secondBeer, thirdBeer
            };

            list
            .Should()
            .Match(r => r.ElementAt(0).Id == 1)
            .And
            .HaveCount(3);
        }
        private void AddBeersToViewList()
        {
            var viewListDataBeers = new ObservableCollection <Beer>();

            viewListDataBeers             = BeerService.GetAllBeers();
            this.ListBoxBeers.ItemsSource = viewListDataBeers;
        }
        private void AddBreweriesToViewList()
        {
            var viewListData = new ObservableCollection <BreweryGrid>();

            viewListData = BeerService.GetAllBreweries();
            this.ListBoxBreweries.ItemsSource = viewListData;
        }
        public void CreateBeer_Success()
        {
            //Arrange
            var beerDTO = new BeerDTO
            {
                BeerName    = "Boliarka",
                BeerTypeId  = 1,
                BreweryId   = 1,
                AlcByVol    = (double)3.2,
                Description = "Stava",
            };
            var options = Utils.GetOptions(nameof(CreateBeer_Success));

            //Act & Assert
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new BeerService(assertContext);
                var result = sut.CreateBeer(beerDTO);
                Assert.AreEqual(beerDTO.BeerName, result.BeerName);
                Assert.AreEqual(beerDTO.BeerTypeId, result.BeerTypeId);
                Assert.AreEqual(beerDTO.BreweryId, result.BreweryId);
                Assert.AreEqual(beerDTO.AlcByVol, result.AlcByVol);
                Assert.AreEqual(beerDTO.Description, result.Description);
            }
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string beerName         = this.BeerName.Text;
                var    price            = decimal.Parse(this.BeerPrice.Text);
                var    quantity         = int.Parse(this.Quantity.Text);
                var    rating           = float.Parse(this.BeerRating.Text);
                string style            = this.cbStyles.SelectedItem.ToString();
                string breweryName      = this.cbBreweries.SelectedItem.ToString();
                string distributorName  = this.cbDistributors.SelectedItem.ToString();
                var    distributorPrice = decimal.Parse(this.DistributorPrice.Text);

                if (beerName == string.Empty || price <= 0 ||
                    quantity <= 0 || rating <= 0 || rating > 10 ||
                    style == string.Empty || breweryName == string.Empty ||
                    distributorName == string.Empty || distributorPrice <= 0)
                {
                    WarningLabel.Content    = "All field are required!";
                    WarningLabel.Visibility = Visibility.Visible;
                }
                else
                {
                    BeerService.AddBeer(beerName, price, quantity, rating, style, breweryName, distributorName, distributorPrice);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                WarningLabel.Visibility = Visibility.Visible;
                WarningLabel.Content    = ex.Message;
                return;
            }
        }
Ejemplo n.º 20
0
        public async Task RateBeer_When_ParamsAreValid()
        {
            var options      = TestUtils.GetOptions(nameof(RateBeer_When_ParamsAreValid));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var country = new Country
            {
                Name = "Romania"
            };
            var brewery = new Brewery
            {
                Name      = "Ariana",
                CountryId = 1
            };
            var style = new Style
            {
                Name = "Pale"
            };

            var beer = new Beer
            {
                Name      = "Zagorka",
                CountryId = 1,
                BreweryId = 1,
                StyleId   = 1,
                Abv       = 3
            };

            var user = new User
            {
                UserName = "******",
                Country  = "Bulgaristan"
            };

            using (var arrangeContext = new BeeroverflowContext(options))
            {
                await arrangeContext.Countries.AddAsync(country);

                await arrangeContext.Breweries.AddAsync(brewery);

                await arrangeContext.Styles.AddAsync(style);

                await arrangeContext.Beers.AddAsync(beer);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut = new BeerService(assertContext, mockDateTime.Object);
                await sut.RateAsync(1, 1, 4.5);

                var check = await assertContext.Ratings.Where(x => x.BeerId == 1).ToListAsync();

                Assert.AreEqual(4.5, check[0].RatingValue);
                Assert.AreEqual(1, check.Count());
            }
        }
Ejemplo n.º 21
0
        public async Task DeleteBeer_When_ParamsAreValid()
        {
            var options      = TestUtils.GetOptions(nameof(DeleteBeer_When_ParamsAreValid));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var beer = new Beer
            {
                Name = "Zagorka"
            };

            using (var arrangeContext = new BeeroverflowContext(options))
            {
                await arrangeContext.Beers.AddAsync(beer);

                await arrangeContext.SaveChangesAsync();
            }

            //Act and Assert
            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut = new BeerService(assertContext, mockDateTime.Object);
                await sut.DeleteBeerAsync(1);

                var result = assertContext.Beers.Where(x => x.Id == 1).FirstOrDefault();

                Assert.IsTrue(result.isDeleted);
            }
        }
        private void AddDistributorsToComboBox()
        {
            ObservableCollection <string> distributors = new ObservableCollection <string>();

            distributors = BeerService.GetAllDistributors();
            this.cbDistributors.SelectedIndex = 0;
            this.cbDistributors.ItemsSource   = distributors;
        }
Ejemplo n.º 23
0
        public void GetByIDShouldCallRepoGetByIDOnce()
        {
            var          repo    = new Mock <IBeerRepository>();
            IBeerService service = new BeerService(repo.Object);

            service.GetBeerByID(1);
            repo.Verify(x => x.GetByID(1), Times.Once);
        }
Ejemplo n.º 24
0
        // GET: Beer
        public ActionResult Index()
        {
            var service  = new BeerService();
            var fullList = service.GetBeers();

            //var model = service.BeerIndex();
            return(View(fullList));
        }
Ejemplo n.º 25
0
        public void GetBeersByTypeShouldCallRepoGetAllOnce()
        {
            var          repo    = new Mock <IBeerRepository>();
            IBeerService service = new BeerService(repo.Object);

            service.GetBeersByType(BeerType.Brown);
            repo.Verify(x => x.GetAll(), Times.Once);
        }
        private void AddBreweriesToComboBox()
        {
            ObservableCollection <string> breweries = new ObservableCollection <string>();

            breweries = BeerService.GetAllBreweriesNames();
            this.cbBreweries.SelectedIndex = 0;
            this.cbBreweries.ItemsSource   = breweries;
        }
Ejemplo n.º 27
0
        public void GetByIDInvalidIDThrowsException(int id)
        {
            var          repo    = new Mock <IBeerRepository>();
            IBeerService service = new BeerService(repo.Object);
            Exception    ex      = Assert.Throws <InvalidDataException>(() => service.GetBeerByID(id));

            Assert.Equal("ID must be greater than 0!", ex.Message);
        }
        private void AddStylesToComboBox()
        {
            ObservableCollection <string> stylesList = new ObservableCollection <string>();

            stylesList                = BeerService.GetAllBeerStyles();
            cbStyles.SelectedIndex    = 0;
            this.cbStyles.ItemsSource = stylesList;
        }
Ejemplo n.º 29
0
        // GET: Beer/Details/5
        public ActionResult Details(int?id)
        {
            var service = new BeerService();
            var model   = service.GetBeerByName(id);



            return(View(model));
        }
Ejemplo n.º 30
0
        public async Task FailRate_If_BeerDoesNotExist()
        {
            var options      = TestUtils.GetOptions(nameof(FailRate_If_BeerDoesNotExist));
            var mockDateTime = new Mock <IDateTimeProvider>();

            var country = new Country
            {
                Name = "Romania"
            };
            var brewery = new Brewery
            {
                Name      = "Ariana",
                CountryId = 1
            };
            var style = new Style
            {
                Name = "Pale"
            };

            var beer = new Beer
            {
                Name      = "Zagorka",
                CountryId = 1,
                BreweryId = 1,
                StyleId   = 1,
                Abv       = 3
            };

            var user = new User
            {
                UserName = "******",
                Country  = "Bulgaristan"
            };

            using (var arrangeContext = new BeeroverflowContext(options))
            {
                await arrangeContext.Countries.AddAsync(country);

                await arrangeContext.Breweries.AddAsync(brewery);

                await arrangeContext.Styles.AddAsync(style);

                await arrangeContext.Beers.AddAsync(beer);

                await arrangeContext.Users.AddAsync(user);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new BeeroverflowContext(options))
            {
                var sut = new BeerService(assertContext, mockDateTime.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.RateAsync(2, 1, 4.5));
            }
        }