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 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 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)); } }
public void CorrectlyAddCocktailReview() { var options = TestUtilities.GetOptions(nameof(CorrectlyAddCocktailReview)); var cocktail = new Cocktail { Id = 1, }; var user = new User { Id = "asd", }; using (var assertContext = new CocktailDB(options)) { var sut = new CocktailReviewServices(assertContext); var review = sut.CreateCocktailReviewAsync(5, "1addsf", cocktail, user).GetAwaiter().GetResult(); var result = assertContext.CocktailReviews.Find(review.Id); Assert.AreEqual(review, result); } }
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)); } }
public async Task AllReviewsAsync() { var userName = "******"; var userName2 = "user"; var userpassword = "******"; var roleId = 1; var cocktailName = "New Bar"; var imageUrlTest = "https://www.google.bg/"; var userServicesMock = new Mock <IUserServices>(); var cocktailReviewMock = new Mock <ICocktailReviewFactory>(); var cocktailTest = new Cocktail { Name = cocktailName, ImagePath = imageUrlTest }; var user = new User(userName, userpassword, roleId); var user2 = new User(userName2, userpassword, roleId); var cocktailReview = new CocktailReview { Cocktail = cocktailTest, User = user }; var cocktailReview2 = new CocktailReview { Cocktail = cocktailTest, User = user2 }; userServicesMock .Setup(r => r.FindUserAsync(userName)) .ReturnsAsync(user); var options = TestUtilities.GetOptions(nameof(AllReviewsAsync)); using (var arrangeContext = new CocktailMagicianDb(options)) { arrangeContext.Cocktails.Add(cocktailTest); arrangeContext.Users.Add(user); arrangeContext.Users.Add(user2); arrangeContext.CocktailReviews.Add(cocktailReview); arrangeContext.CocktailReviews.Add(cocktailReview2); await arrangeContext.SaveChangesAsync(); } using (var actContext = new CocktailMagicianDb(options)) { var cocktailTestFound = await actContext.Cocktails.Where(b => b.Name == cocktailTest.Name).Select(b => b.Id).FirstAsync(); var sut = new CocktailReviewServices(cocktailReviewMock.Object, actContext); await sut.AllReviewsAsync(cocktailTestFound); } using (var assertContext = new CocktailMagicianDb(options)) { Assert.AreEqual(2, assertContext.CocktailReviews.Count()); } }
public async Task AddReviewAsync() { var comment = "comment"; var rating = 5; var userName = "******"; var userpassword = "******"; var roleId = 1; var cocktailTestName = "New Cocktail"; var userServicesMock = new Mock <IUserServices>(); var cocktailReviewFactoryMock = new Mock <ICocktailReviewFactory>(); var cocktailTest = new Cocktail() { Name = cocktailTestName, }; var user = new User(userName, userpassword, roleId); userServicesMock .Setup(r => r.FindUserAsync(userName)) .ReturnsAsync(user); var options = TestUtilities.GetOptions(nameof(AddReviewAsync)); using (var arrangeContext = new CocktailMagicianDb(options)) { arrangeContext.Cocktails.Add(cocktailTest); arrangeContext.Users.Add(user); await arrangeContext.SaveChangesAsync(); } using (var actContext = new CocktailMagicianDb(options)) { var cocktailFound = await actContext.Cocktails.Where(b => b.Name == cocktailTestName).Select(b => b.Id).FirstAsync(); var userNameFound = await actContext.Users.Where(u => u.UserName == userName).Select(u => u.UserName).FirstAsync(); var userIdFound = await actContext.Users.Where(u => u.UserName == userName).Select(u => u.Id).FirstAsync(); var cocktailReview = new CocktailReview { Comment = comment, Rating = rating, UserId = userIdFound, CocktailId = cocktailFound }; cocktailReviewFactoryMock .Setup(r => r.Create(comment, rating, userIdFound, cocktailFound)) .Returns(cocktailReview); var sut = new CocktailReviewServices(cocktailReviewFactoryMock.Object, actContext); await sut.AddReviewAsync(comment, rating, userNameFound, cocktailFound); } using (var assertContext = new CocktailMagicianDb(options)) { var cocktailReviewTest = await assertContext.CocktailReviews.Include(b => b.User).FirstAsync(u => u.User == user); var userIdFound = await assertContext.Users.Where(u => u.UserName == userName).Select(u => u.Id).FirstAsync(); Assert.AreEqual(cocktailReviewTest.User.Id, user.Id); } }