예제 #1
0
        public void ReturnCollectionOfCorrectBars()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnCollectionOfCorrectBars));


            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut  = new BarServices(assertContext);
                var bar1 = new Bar
                {
                    Name = "FF1"
                };
                var bar2 = new Bar
                {
                    Name = "FF2"
                };

                assertContext.Bars.Add(bar1);
                assertContext.Bars.Add(bar2);
                assertContext.SaveChanges();

                var result = sut.GetMultipleBarsByNameAsync("F").GetAwaiter().GetResult();

                Assert.IsTrue(result.Count == 2 && result.Contains(bar1) && result.Contains(bar2));
            }
        }
예제 #2
0
        public void UpdateTheQuantityOfCocktailIngredient()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(UpdateTheQuantityOfCocktailIngredient));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailIngredientServices(assertContext);
                var cocktail = new Cocktail
                {
                    Name = "Mojito"
                };
                var ingredient = new Ingredient
                {
                    Name = "Mint"
                };
                var quantity    = 1;
                var barCocktail = sut.AddAsync(cocktail, ingredient, quantity).GetAwaiter().GetResult();
                quantity = 2;
                sut.UpdateAsync(ingredient, cocktail, quantity).GetAwaiter().GetResult();

                Assert.IsTrue(barCocktail.Quantity == 2);
            }
        }
예제 #3
0
        public void CorrectlyDeleteReview()
        {
            var options  = TestUtilities.GetOptions(nameof(CorrectlyDeleteReview));
            int resultId = -1;
            var review1  = new BarReview
            {
                Id    = resultId,
                BarId = 1,
            };
            var review2 = new BarReview
            {
                Id    = -2,
                BarId = 1,
            };
            var review3 = new BarReview
            {
                Id    = -3,
                BarId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new BarReviewServices(assertContext);
                sut.DeleteAsync(resultId).GetAwaiter();
                Assert.IsFalse(assertContext.BarReviews.Contains(review1));
            }
        }
        public void ReturnTrueIfThePairIsUpdated()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnTrueIfThePairIsUpdated));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailIngredientServices(assertContext);
                var cocktail = new Cocktail
                {
                    Name = "Mojito"
                };
                var ingredient = new Ingredient
                {
                    Name = "Mint"
                };
                var quantity           = 1;
                var cocktailIngredient = sut.AddAsync(cocktail, ingredient, quantity).GetAwaiter().GetResult();
                cocktailIngredient.Quantity = 2;
                assertContext.SaveChanges();

                Assert.IsTrue(sut.IsPairUpdatedAsync(ingredient, cocktail, 1).GetAwaiter().GetResult());
            }
        }
        public void ReturnTrueIfTheIngredientIsUsedInAnyCocktail()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnTrueIfTheIngredientIsUsedInAnyCocktail));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut        = new IngredientServices(assertContext);
                var name       = "Rum";
                var type       = "alcohol";
                var ingredient = sut.AddAsync(name, type).GetAwaiter().GetResult();

                var cocktail = new Cocktail
                {
                    Name = "Test",
                };

                var cocktailIngredient = new CocktailIngredient
                {
                    Ingredient   = ingredient,
                    IngredientID = ingredient.Id,
                    Cocktail     = cocktail,
                    CocktailID   = cocktail.Id
                };

                assertContext.CocktailIngredients.Add(cocktailIngredient);
                assertContext.SaveChanges();
                var result = sut.IsIngredientUsedAsync(ingredient.Id).GetAwaiter().GetResult();

                Assert.IsTrue(result);
            }
        }
예제 #6
0
        public void ThrowWhenIdIsNotFound()
        {
            var options  = TestUtilities.GetOptions(nameof(ThrowWhenIdIsNotFound));
            int resultId = -1;
            var review1  = new BarReview
            {
                Id    = resultId,
                BarId = 1,
            };
            var review2 = new BarReview
            {
                Id    = -2,
                BarId = 1,
            };
            var review3 = new BarReview
            {
                Id    = -3,
                BarId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new BarReviewServices(assertContext);
                Assert.ThrowsExceptionAsync <ArgumentNullException>(
                    () => sut.DeleteAsync(int.MaxValue));
            }
        }
예제 #7
0
        public void ReturnCollectionOfCorrectBars()
        {
            var options = TestUtilities.GetOptions(nameof(ReturnCollectionOfCorrectBars));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new BarServices(assertContext);
                var bar = new Bar
                {
                    Id          = 1,
                    Name        = "test",
                    Address     = "asasas",
                    PhoneNumber = "asd",
                };

                var bar1 = new Bar
                {
                    Id          = 2,
                    Name        = "test1",
                    Address     = "asasas",
                    PhoneNumber = "asd",
                };

                assertContext.Bars.Add(bar);
                assertContext.Bars.Add(bar1);
                assertContext.SaveChanges();

                var result = sut.GetCollectionAsync().GetAwaiter().GetResult();
                Assert.IsTrue(result.Count == 2 && result.Contains(bar) && result.Contains(bar1));
            }
        }
        public void CorrectlyEditBar()
        {
            var options           = TestUtils.GetOptions(nameof(CorrectlyEditBar));
            var resultName        = "test1";
            var resultAddress     = "Mill Street";
            var resultPhoneNumber = "testNumber";
            var bar = new Bar
            {
                Id          = 1,
                Name        = "asd",
                Address     = "asd",
                PhoneNumber = "add",
                IsHidden    = false,
            };

            using (var actContext = new CocktailDB(options))
            {
                var sut = new BarServices(actContext);
                actContext.Bars.AddAsync(bar).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
                sut.EditBarAsync(bar, resultName, resultAddress, resultPhoneNumber, null, true).GetAwaiter();
            }
            using (var asertContext = new CocktailDB(options))
            {
                var sut       = new BarServices(asertContext);
                var resultBar = sut.GetBarAsync(bar.Id).GetAwaiter().GetResult();
                Assert.AreEqual(resultBar.Name, resultName);
                Assert.AreEqual(resultBar.Address, resultAddress);
                Assert.AreEqual(resultBar.PhoneNumber, resultPhoneNumber);
                Assert.IsTrue(resultBar.IsHidden);
            }
        }
예제 #9
0
        public void ReturnCollectionOf10NewestBarsOrderedAscending()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnCollectionOf10NewestBarsOrderedAscending));


            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut  = new BarServices(assertContext);
                var bar1 = new Bar
                {
                    Name      = "FF1",
                    CreatedOn = DateTime.Now
                };
                var bar2 = new Bar
                {
                    Name      = "FF2",
                    CreatedOn = DateTime.Now
                };

                assertContext.Bars.Add(bar1);
                assertContext.Bars.Add(bar2);
                assertContext.SaveChanges();

                var result = sut.LoadNewestBars().GetAwaiter().GetResult();

                Assert.IsTrue(result.Count == 2 && result[0] == bar1 && result[1] == bar2);
            }
        }
예제 #10
0
        public void DeleteTheDesiredCocktailIngredient()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(DeleteTheDesiredCocktailIngredient));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailIngredientServices(assertContext);
                var cocktail = new Cocktail
                {
                    Name = "Mojito"
                };
                var ingredient = new Ingredient
                {
                    Name = "Mint"
                };
                var quantity    = 1;
                var barCocktail = sut.AddAsync(cocktail, ingredient, quantity).GetAwaiter().GetResult();
                Assert.IsTrue(assertContext.CocktailIngredients.Contains(barCocktail));

                sut.DeleteAsync(cocktail.Name, ingredient.Name).GetAwaiter().GetResult();
                Assert.IsFalse(assertContext.CocktailIngredients.Contains(barCocktail));
            }
        }
        public void ReturnNullWhenCocktailIdIsNotFound()
        {
            var options = TestUtilities.GetOptions(nameof(ReturnNullWhenCocktailIdIsNotFound));
            var review1 = new CocktailReview
            {
                Id         = -1,
                CocktailId = 1,
            };
            var review2 = new CocktailReview
            {
                Id         = -2,
                CocktailId = 1,
            };
            var review3 = new CocktailReview
            {
                Id         = -3,
                CocktailId = 2,
            };

            using (var actContext = new CocktailDB(options))
            {
                actContext.AddAsync(review1).GetAwaiter();
                actContext.AddAsync(review2).GetAwaiter();
                actContext.AddAsync(review3).GetAwaiter();
                actContext.SaveChangesAsync().GetAwaiter();
            }
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new CocktailReviewServices(assertContext);
                var result = sut.GetCocktailReviewsCollectionAsync(int.MaxValue).GetAwaiter().GetResult();
                Assert.AreEqual(0, result.Count);
            }
        }
        public void ReturnCorrectBar()
        {
            var options = TestUtils.GetOptions(nameof(ReturnCorrectBar));

            var testBar = new Bar
            {
                Id          = 1,
                Name        = "Test",
                Address     = "Test",
                PhoneNumber = "Test",
            };

            // Act
            using (var actContext = new CocktailDB(options))
            {
                var sut = new BarServices(actContext);
                actContext.Bars.Add(testBar);
                actContext.SaveChangesAsync().GetAwaiter();
            }
            // Assert
            using (var assertContext = new CocktailDB(options))
            {
                var id     = 1;
                var sut    = new BarServices(assertContext);
                var result = sut.GetBarAsync(id).GetAwaiter().GetResult();
                Assert.IsTrue(assertContext.Bars.Contains(testBar));
                Assert.AreEqual(testBar.Id, result.Id);
            }
        }
예제 #13
0
        public void ThrowWhenParametersAreNull()
        {
            var options = TestUtilities.GetOptions(nameof(ReturnFirstCorrectName));

            using (var assertContext = new CocktailDB(options))
            {
                var sut = new BarServices(assertContext);
                Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetAsync(null));
            }
        }
예제 #14
0
        public void ReturnFalseIfSuchIngredientDoesntExist()
        {
            var options = TestUtilities.GetOptions(nameof(ReturnFalseIfSuchIngredientDoesntExist));

            //act & assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new IngredientServices(assertContext);
                Assert.IsFalse(sut.IngredientWithThatNameExists("test").GetAwaiter().GetResult());
            }
        }
        public void ThrowWhenBarIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowWhenBarIsNull));

            using (var assertContext = new CocktailDB(options))
            {
                var sut = new BarServices(assertContext);
                Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.CreateBarAsync(null)
                                                                    );
            }
        }
예제 #16
0
        public void ReturnEmptyCollectionIfNoBarsExist()
        {
            var options = TestUtilities.GetOptions(nameof(ReturnEmptyCollectionIfNoBarsExist));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new BarServices(assertContext);
                var result = sut.GetCollectionAsync().GetAwaiter().GetResult();
                Assert.IsTrue(result.Count == 0);
            }
        }
예제 #17
0
        public void CreateNewInstanceOfCocktail()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(CreateNewInstanceOfCocktail));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailServices(assertContext);
                var name     = "Rums and Dreams";
                var cocktail = sut.AddAsync(name, null).GetAwaiter().GetResult();
                Assert.IsInstanceOfType(cocktail, typeof(Cocktail));
            }
        }
예제 #18
0
        public void ReturnEmptyCollectionIfThereAreNoBars()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnEmptyCollectionIfThereAreNoBars));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new BarServices(assertContext);
                var result = sut.LoadNewestBars().GetAwaiter().GetResult();

                Assert.IsTrue(result.Count == 0);
            }
        }
예제 #19
0
        public void ReturnOnlyAlcoholicCocktailsByIngredientNameWhenThereAreAny()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnOnlyAlcoholicCocktailsByIngredientNameWhenThereAreAny));


            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailServices(assertContext);
                var name     = "Rums and Dreams";
                var cocktail = sut.AddAsync(name, null).GetAwaiter().GetResult();
                name = "Rums and Dreams2";
                var cocktail2 = sut.AddAsync(name, null).GetAwaiter().GetResult();
                name = "Rums and Dreams3";
                var cocktail3  = sut.AddAsync(name, null).GetAwaiter().GetResult();
                var ingredient = new Ingredient
                {
                    Name = "Rum",
                    Type = "alcohol",
                };
                assertContext.Ingredients.Add(ingredient);

                var cocktailIngredient = new CocktailIngredient
                {
                    Ingredient   = ingredient,
                    IngredientID = ingredient.Id,
                    Cocktail     = cocktail2,
                    CocktailID   = cocktail2.Id
                };
                assertContext.CocktailIngredients.Add(cocktailIngredient);

                var cocktailIngredient1 = new CocktailIngredient
                {
                    Ingredient   = ingredient,
                    IngredientID = ingredient.Id,
                    Cocktail     = cocktail3,
                    CocktailID   = cocktail3.Id
                };
                assertContext.CocktailIngredients.Add(cocktailIngredient1);
                assertContext.SaveChanges();

                var ingredientName       = ingredient.Name;
                var includeOnlyAlcoholic = true;
                var result = sut.SearchByMultipleCriteriaAsync(null, ingredientName, includeOnlyAlcoholic).GetAwaiter().GetResult();

                Assert.AreEqual(2, result.Count);
            }
        }
        public void ReturnEmptyCollectionIfNoCocktailsAreFound()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnEmptyCollectionIfNoCocktailsAreFound));


            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new CocktailServices(assertContext);
                var result = sut.GetMultipleCocktailsByNameAsync("u").GetAwaiter().GetResult();

                Assert.IsTrue(result.Count == 0);
            }
        }
        public void ShouldReturnEmptyCollectionIfNoIngredientsAreFound()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ShouldReturnEmptyCollectionIfNoIngredientsAreFound));


            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut    = new IngredientServices(assertContext);
                var result = sut.SearchIngredientsAsync("e").GetAwaiter().GetResult();

                Assert.IsTrue(result.Count == 0);
            }
        }
        public void CreateNewInstanceOfIngredient()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(CreateNewInstanceOfIngredient));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut        = new IngredientServices(assertContext);
                var name       = "Rum";
                var type       = "alcohol";
                var ingredient = sut.AddAsync(name, type).GetAwaiter().GetResult();
                Assert.IsInstanceOfType(ingredient, typeof(Ingredient));
            }
        }
        public void ThrowWhenCocktailIsNull()
        {
            var options = TestUtilities.GetOptions(nameof(ThrowWhenCocktailIsNull));
            var user    = new User
            {
                Id = "asd",
            };

            using (var assertContext = new CocktailDB(options))
            {
                var sut = new CocktailReviewServices(assertContext);
                Assert.ThrowsExceptionAsync <ArgumentNullException>(() =>
                                                                    sut.CreateCocktailReviewAsync(2, "134", null, user));
            }
        }
예제 #24
0
        public void AddTheCocktailToTheDBSetCOrrectly()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(AddTheCocktailToTheDBSetCOrrectly));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailServices(assertContext);
                var name     = "Rums and Dreams";
                var cocktail = sut.AddAsync(name, null).GetAwaiter().GetResult();

                Assert.IsTrue(assertContext.Cocktails.Contains(cocktail));
            }
        }
        public void ReturnFalseIfTheIngredientIsNotUsedInAnyCocktail()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnFalseIfTheIngredientIsNotUsedInAnyCocktail));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut        = new IngredientServices(assertContext);
                var name       = "Rum";
                var type       = "alcohol";
                var ingredient = sut.AddAsync(name, type).GetAwaiter().GetResult();
                var result     = sut.IsIngredientUsedAsync(ingredient.ID).GetAwaiter().GetResult();

                Assert.IsFalse(result);
            }
        }
예제 #26
0
        public void DeleteTheDesiredIngredient()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(DeleteTheDesiredIngredient));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut        = new IngredientServices(assertContext);
                var name       = "Rum";
                var type       = "alcohol";
                var ingredient = sut.AddAsync(name, type).GetAwaiter().GetResult();
                sut.DeleteAsync(ingredient.Id).GetAwaiter().GetResult();

                Assert.IsNull(assertContext.Ingredients.Find(ingredient.Id));
            }
        }
        public void AddTheIngredientToTheDBSetCOrrectly()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(AddTheIngredientToTheDBSetCOrrectly));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new IngredientServices(assertContext);

                var name       = "Rum";
                var type       = "alcohol";
                var ingredient = sut.AddAsync(name, type).GetAwaiter().GetResult();

                Assert.IsTrue(assertContext.Ingredients.Contains(ingredient));
            }
        }
예제 #28
0
        public void HideTheDesiredCocktail()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(HideTheDesiredCocktail));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailServices(assertContext);
                var name     = "Rums and Dreams";
                var cocktail = sut.AddAsync(name, null).GetAwaiter().GetResult();
                sut.HideAsync(cocktail.Id).GetAwaiter().GetResult();


                Assert.IsTrue(cocktail.IsHidden == true);
            }
        }
예제 #29
0
        public void ReturnCorrectCocktailByName()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnCorrectCocktailByName));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut = new CocktailServices(assertContext);

                var name     = "Rums and Dreams";
                var cocktail = sut.AddAsync(name, null).GetAwaiter().GetResult();
                var result   = sut.GetAsync(cocktail.Name).GetAwaiter().GetResult();

                Assert.AreEqual(cocktail, result);
            }
        }
        public void ReturnCollectionWithCocktails()
        {
            // Arrange
            var options = TestUtilities.GetOptions(nameof(ReturnCollectionWithCocktails));

            // Act, Assert
            using (var assertContext = new CocktailDB(options))
            {
                var sut      = new CocktailServices(assertContext);
                var name     = "Rums and Dreams";
                var cocktail = sut.AddAsync(name, null).GetAwaiter().GetResult();
                name = "Rums and Dreams2";
                var cocktail2 = sut.AddAsync(name, null).GetAwaiter().GetResult();
                var result    = sut.GetCollectionAsync().GetAwaiter().GetResult().ToArray();

                Assert.IsTrue(result.Length == 2 && result[0] == cocktail && result[1] == cocktail2);
            }
        }