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)); } }
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 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); } }
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); } }
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 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 ReturnTureIfSuchCocktailExists() { var options = TestUtilities.GetOptions(nameof(ReturnTureIfSuchCocktailExists)); var cocktail = new Cocktail { Id = 1, Name = "test", }; //act & assert using (var assertContext = new CocktailDB(options)) { var sut = new CocktailServices(assertContext); assertContext.Cocktails.Add(cocktail); assertContext.SaveChanges(); Assert.IsTrue(sut.CocktailWithThatNameExists(cocktail.Name).GetAwaiter().GetResult()); } }
public void ReturnTureIfSuchIngredientExists() { var options = TestUtilities.GetOptions(nameof(ReturnTureIfSuchIngredientExists)); var ingredient = new Ingredient { Id = 1, Name = "test", }; //act & assert using (var assertContext = new CocktailDB(options)) { var sut = new IngredientServices(assertContext); assertContext.Ingredients.Add(ingredient); assertContext.SaveChanges(); Assert.IsTrue(sut.IngredientWithThatNameExists(ingredient.Name).GetAwaiter().GetResult()); } }
public void ReturnAllTypeCocktailsByCocktailAndIngredientName() { // Arrange var options = TestUtilities.GetOptions(nameof(ReturnAllTypeCocktailsByCocktailAndIngredientName)); // 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 ingredient = new Ingredient { Name = "sugar", Type = "sweetener", }; assertContext.Ingredients.Add(ingredient); var cocktailIngredient = new CocktailIngredient { Ingredient = ingredient, IngredientID = ingredient.Id, Cocktail = cocktail, CocktailID = cocktail.Id }; assertContext.CocktailIngredients.Add(cocktailIngredient); assertContext.SaveChanges(); var cocktailName = cocktail.Name; var ingredientName = ingredient.Name; var includeOnlyAlcoholic = false; var result = sut.SearchByMultipleCriteriaAsync(cocktailName, ingredientName, includeOnlyAlcoholic).GetAwaiter().GetResult(); Assert.IsTrue(result.Count == 1 && result[0] == cocktail); } }
public void ReturnCollectionOfCorrectCocktailNames() { // Arrange var options = TestUtilities.GetOptions(nameof(ReturnCollectionOfCorrectCocktailNames)); // Act, Assert using (var assertContext = new CocktailDB(options)) { var sut = new BarServices(assertContext); var bar = new Bar { Name = "Barsy", Id = 1 }; var cocktail1 = new Cocktail { Name = "Mojito1", Id = 1 }; var cocktail2 = new Cocktail { Name = "Mojito2", Id = 2 }; var cocktail3 = new Cocktail { Name = "Mojito3", Id = 3 }; var pair1 = new BarCocktail { Bar = bar, BarID = bar.Id, Cocktail = cocktail1, CocktailID = cocktail1.Id }; var pair2 = new BarCocktail { Bar = bar, BarID = bar.Id, Cocktail = cocktail2, CocktailID = cocktail2.Id }; var pair3 = new BarCocktail { Bar = bar, BarID = bar.Id, Cocktail = cocktail3, CocktailID = cocktail3.Id }; assertContext.BarCocktail.Add(pair1); assertContext.BarCocktail.Add(pair2); assertContext.BarCocktail.Add(pair3); assertContext.SaveChanges(); var result = sut.LoadMoreCocktails(1, bar.Id).GetAwaiter().GetResult(); Assert.IsTrue(result.Count == 2 && result[0] == cocktail2.Name && result[1] == cocktail3.Name); } }