Exemple #1
0
        public async Task AllAsyncShouldReturnCorrectDrinksByPageWithoutCategory()
        {
            var db = DbInfrastructure.GetDatabase();

            // 270 drinks with 1 categories
            await this.SeedData(db, 270, 1);

            var drinkService = new DrinkService(db);

            const string Search = "0";

            for (var i = 0; i < 3; i++)
            {
                var drinks = await drinkService.AllAsync(i + 1, null, Search);

                drinks
                .Should()
                .HaveCount(WebConstants.DrinksPerPage);

                drinks
                .Should()
                .BeInAscendingOrder(d => d.Name);

                foreach (var drink in drinks)
                {
                    drink
                    .Name
                    .ToLower()
                    .Should()
                    .Contain(Search.ToLower());
                }
            }
        }
Exemple #2
0
        public void AllAsyncShouldThrowExceptionIfCategoryIsNotFound()
        {
            var db = DbInfrastructure.GetDatabase();

            var drinkService = new DrinkService(db);

            Func <Task> func = async() => await drinkService.AllAsync(1, "Invalid CateGorY", null);

            func
            .Should()
            .Throw <InvalidOperationException>()
            .WithMessage("Category Invalid CateGorY is not found.");
        }
Exemple #3
0
        public async Task AllAsyncShouldReturnCorrectDrinksByPageWithoutSearch()
        {
            var db = DbInfrastructure.GetDatabase();

            var category = new Category
            {
                Name = "Some Category"
            };

            await db.AddAsync(category);

            await db.SaveChangesAsync();

            await this.SeedDataByCategory(db, 180, category.Id);

            var drinkService = new DrinkService(db);

            for (var i = 0; i < 20; i++)
            {
                var drinks = await drinkService.AllAsync(i + 1, category.Name, null);

                drinks
                .Should()
                .HaveCount(WebConstants.DrinksPerPage);

                drinks
                .Should()
                .BeInAscendingOrder(d => d.Name);

                foreach (var drink in drinks)
                {
                    var drinkFromDb = await db
                                      .Drinks
                                      .FindAsync(drink.Id);

                    drinkFromDb.CategoryId.Should().Be(category.Id);
                }
            }
        }
Exemple #4
0
        public async Task AllAsyncShouldReturnCorrectDrinksByPageWithoutCategoryAndSearch()
        {
            var db = DbInfrastructure.GetDatabase();

            // 90 drinks with 5 categories
            await this.SeedData(db, 90, 5);

            var drinkService = new DrinkService(db);

            for (var i = 0; i < 10; i++)
            {
                var drinks = await drinkService.AllAsync(i + 1, null, null);

                drinks
                .Should()
                .HaveCount(WebConstants.DrinksPerPage);

                drinks
                .Should()
                .BeInAscendingOrder(d => d.Name);
            }
        }
Exemple #5
0
        public async Task AllAsyncShouldReturnCorrectDrinksByPageWithCategoryAndSearch()
        {
            var db = DbInfrastructure.GetDatabase();

            var categories = new List <Category>();

            for (var i = 0; i < 10; i++)
            {
                var newCategory = new Category
                {
                    Name = $"Some Category {i}"
                };

                await db.AddAsync(newCategory);

                categories.Add(newCategory);
            }

            for (var i = 0; i < 270; i++)
            {
                await db.AddAsync(new Drink
                {
                    Name       = $"Some Drink",
                    CategoryId = categories[this.random.Next(0, categories.Count)].Id,
                });
            }

            await db.SaveChangesAsync();

            var category = new Category
            {
                Name = "Custom category"
            };

            await db.AddAsync(category);

            await db.SaveChangesAsync();

            await this.SeedDataByCategory(db, 504, category.Id);

            var drinkService = new DrinkService(db);

            const string Search = "0";

            for (var i = 0; i < 10; i++)
            {
                var drinks = await drinkService.AllAsync(i + 1, category.Name, Search);

                drinks
                .Should()
                .HaveCount(WebConstants.DrinksPerPage);

                drinks
                .Should()
                .BeInAscendingOrder(d => d.Name);

                foreach (var drink in drinks)
                {
                    var drinkFromDb = await db
                                      .Drinks
                                      .FindAsync(drink.Id);

                    drinkFromDb
                    .Name
                    .ToLower()
                    .Should()
                    .Contain(Search.ToLower());

                    drinkFromDb
                    .CategoryId
                    .Should()
                    .Be(category.Id);
                }
            }
        }