public async Task CreateBarAsync(Bar bar) { bar.EnsureNotNull(); await _context.Bars.AddAsync(bar); await _context.SaveChangesAsync(); }
public async Task <Cocktail> AddAsync(string name, byte[] image) { var cocktail = new Cocktail { Name = name, Picture = image, }; await _context.Cocktails.AddAsync(cocktail); await _context.SaveChangesAsync(); return(cocktail); }
public async Task <Ingredient> AddAsync(string name, string type) { var ingredient = new Ingredient { Name = name, Type = type }; await this._context.Ingredients.AddAsync(ingredient); await _context.SaveChangesAsync(); return(ingredient); }
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); } }
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); } }
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 async Task <BarCocktail> CreateAsync(Bar bar, Cocktail cocktail) { var barCocktail = new BarCocktail { Bar = bar, BarID = bar.Id, Cocktail = cocktail, CocktailID = cocktail.Id }; await _context.BarCocktail.AddAsync(barCocktail); await _context.SaveChangesAsync(); return(barCocktail); }
public void ReturnCorrectBarsWithNameParam() { var options = TestUtilities.GetOptions(nameof(ReturnCorrectBarsWithNameParam)); string name = "test"; string address = "TestAddr"; string phoneNumber = "number"; var bar = new Bar { Id = -1, Name = "kon", Address = address, PhoneNumber = phoneNumber, }; var bar2 = new Bar { Id = -2, Name = name, Address = address, PhoneNumber = phoneNumber, }; using (var arrangeContext = new CocktailDB(options)) { arrangeContext.Bars.AddAsync(bar).GetAwaiter(); arrangeContext.Bars.AddAsync(bar2).GetAwaiter(); arrangeContext.SaveChangesAsync().GetAwaiter(); } using (var assertContext = new CocktailDB(options)) { var sut = new BarServices(assertContext); var collection = sut.SearchBarsByMultipleCriteriaAsync("kon", null, null, false).GetAwaiter().GetResult(); Assert.IsNotNull(collection); Assert.AreEqual(1, collection.Count); } }
public void ThrowWhenIdIsNotFound() { var options = TestUtilities.GetOptions(nameof(ThrowWhenIdIsNotFound)); int resultId = -1; var review1 = new CocktailReview { Id = resultId, 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); Assert.ThrowsExceptionAsync <ArgumentNullException>( () => sut.DeleteAsync(int.MaxValue)); } }
public void CorrectlyDeleteReview() { var options = TestUtilities.GetOptions(nameof(CorrectlyDeleteReview)); int resultId = -1; var review1 = new CocktailReview { Id = resultId, 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); sut.DeleteAsync(resultId).GetAwaiter(); Assert.IsFalse(assertContext.CocktailReviews.Contains(review1)); } }
public async Task <CocktailIngredient> AddAsync(Cocktail cocktail, Ingredient ingredient, int quantity) { var cocktailIngredient = new CocktailIngredient { CocktailID = cocktail.Id, Cocktail = cocktail, IngredientID = ingredient.Id, Ingredient = ingredient, Quantity = quantity }; await _context.CocktailIngredients.AddAsync(cocktailIngredient); await _context.SaveChangesAsync(); return(cocktailIngredient); }
public void ReturnAllBarsContainingNumberCharacter() { var options = TestUtilities.GetOptions(nameof(ReturnAllBarsContainingNumberCharacter)); string name = "test"; string address = "TestAddr"; string phoneNumber = "123"; var bar = new Bar { Id = -1, Name = name, Address = address, PhoneNumber = phoneNumber, }; var bar2 = new Bar { Id = -2, Name = name, Address = address, PhoneNumber = phoneNumber, }; var bar3 = new Bar { Id = -3, Name = name, Address = "xdr", PhoneNumber = "asd", }; using (var arrangeContext = new CocktailDB(options)) { arrangeContext.Bars.AddAsync(bar).GetAwaiter(); arrangeContext.Bars.AddAsync(bar2).GetAwaiter(); arrangeContext.Bars.AddAsync(bar3).GetAwaiter(); arrangeContext.SaveChangesAsync().GetAwaiter(); } using (var assertContext = new CocktailDB(options)) { var sut = new BarServices(assertContext); var collection = sut.SearchBarsByMultipleCriteriaAsync(null, null, "12", false).GetAwaiter().GetResult(); Assert.IsNotNull(collection); Assert.AreEqual(2, collection.Count); } }
public void ReturnFirstCorrectName() { var options = TestUtilities.GetOptions(nameof(ReturnFirstCorrectName)); string name = "test"; string address = "TestAddr"; string phoneNumber = "123"; var bar = new Bar { Id = -1, Name = name, Address = address, PhoneNumber = phoneNumber, }; var bar2 = new Bar { Id = -2, Name = name, Address = address, PhoneNumber = phoneNumber, }; var bar3 = new Bar { Id = -3, Name = name, Address = "xdr", PhoneNumber = "asd", }; using (var arrangeContext = new CocktailDB(options)) { arrangeContext.Bars.AddAsync(bar).GetAwaiter(); arrangeContext.Bars.AddAsync(bar2).GetAwaiter(); arrangeContext.Bars.AddAsync(bar3).GetAwaiter(); arrangeContext.SaveChangesAsync().GetAwaiter(); } using (var assertContext = new CocktailDB(options)) { var sut = new BarServices(assertContext); var result = sut.GetAsync(name).GetAwaiter().GetResult(); Assert.IsNotNull(result); Assert.AreEqual(bar.Id, result.Id); } }
public void ReturnOnlyHiddenFiles() { var options = TestUtilities.GetOptions(nameof(ReturnOnlyHiddenFiles)); string name = "test"; string address = "TestAddr"; string phoneNumber = "number"; var bar = new Bar { Id = -1, Name = name, Address = address, PhoneNumber = phoneNumber, }; var bar2 = new Bar { Id = -2, Name = name, Address = address, PhoneNumber = phoneNumber, IsHidden = true, }; using (var arrangeContext = new CocktailDB(options)) { arrangeContext.Bars.AddAsync(bar).GetAwaiter(); arrangeContext.Bars.AddAsync(bar2).GetAwaiter(); arrangeContext.SaveChangesAsync().GetAwaiter(); } using (var assertContext = new CocktailDB(options)) { var sut = new BarServices(assertContext); var collection = sut.SearchBarsByMultipleCriteriaAsync(null, null, null, true).GetAwaiter().GetResult(); Assert.IsNotNull(collection); Assert.AreEqual(1, collection.Count); Assert.AreEqual(bar2.Id, collection.First().Id); Assert.AreEqual(bar2.Address, collection.First().Address); Assert.AreEqual(bar2.Name, collection.First().Name); Assert.AreEqual(bar2.PhoneNumber, collection.First().PhoneNumber); Assert.AreEqual(bar2.IsHidden, collection.First().IsHidden); } }
public void ReturnNullWhenIdNotFound() { var options = TestUtilities.GetOptions(nameof(ReturnNullWhenIdNotFound)); int resultId = -1; var review = new CocktailReview { Id = resultId, }; using (var actContext = new CocktailDB(options)) { actContext.AddAsync(review).GetAwaiter(); actContext.SaveChangesAsync().GetAwaiter(); } using (var assertContext = new CocktailDB(options)) { var sut = new CocktailReviewServices(assertContext); var result = sut.GetCocktailReviewAsync(int.MaxValue).GetAwaiter().GetResult(); Assert.IsNull(result); } }
public void ReturnCorrectReview() { var options = TestUtilities.GetOptions(nameof(ReturnCorrectReview)); int resultId = -1; var review = new CocktailReview { Id = resultId, }; using (var actContext = new CocktailDB(options)) { actContext.AddAsync(review).GetAwaiter(); actContext.SaveChangesAsync().GetAwaiter(); } using (var assertContext = new CocktailDB(options)) { var sut = new CocktailReviewServices(assertContext); var result = sut.GetCocktailReviewAsync(resultId).GetAwaiter().GetResult(); Assert.IsNotNull(result); Assert.AreEqual(resultId, result.Id); } }
public void ReturnCorrectReviews() { var options = TestUtilities.GetOptions(nameof(ReturnCorrectReviews)); int resultId = 1; 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(resultId).GetAwaiter().GetResult(); Assert.IsNotNull(result); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Select(br => br.CocktailId).Contains(1)); } }