public async Task GetAllCommentsForCocktail_Returns_Correct_WhenParam_IsValid() { //Arrange var options = Utils.GetOptions(nameof(GetAllCommentsForCocktail_Returns_Correct_WhenParam_IsValid)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var user2 = new User { Id = Guid.NewGuid(), UserName = "******" }; var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "Manhattan" }; var cocktailComment = new CocktailComment { CocktailId = cocktail.Id, UserId = user.Id }; var cocktailComment2 = new CocktailComment { CocktailId = cocktail.Id, UserId = user2.Id }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.Users.AddRangeAsync(user, user2); await arrangeContext.CocktailComments.AddRangeAsync(cocktailComment, cocktailComment2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new CocktailCommentServices(assertContext); var result = await sut.GetAllCommentsForCocktail(cocktail.Id); Assert.AreEqual(2, result.Count()); Assert.AreEqual(result.ToList()[0].UserId, user.Id); Assert.AreEqual(result.ToList()[1].UserId, user2.Id); Assert.IsInstanceOfType(result, typeof(ICollection <CocktailCommentsDTO>)); } }
public async Task GetAllCommentsForCocktail_Returns_OnlyExistingEntities() { //Arrange var options = Utils.GetOptions(nameof(GetAllCommentsForCocktail_Returns_OnlyExistingEntities)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var user2 = new User { Id = Guid.NewGuid(), UserName = "******" }; var cocktail = new Cocktail { Id = Guid.NewGuid(), Name = "Manhattan" }; var cocktailComment = new CocktailComment { CocktailId = cocktail.Id, UserId = user.Id }; var cocktailComment2 = new CocktailComment { CocktailId = cocktail.Id, UserId = user2.Id, IsDeleted = true }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Cocktails.AddAsync(cocktail); await arrangeContext.Users.AddRangeAsync(user, user2); await arrangeContext.CocktailComments.AddRangeAsync(cocktailComment, cocktailComment2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new CocktailCommentServices(assertContext); var result = await sut.GetAllCommentsForCocktail(cocktail.Id); Assert.AreEqual(1, result.Count()); } }