public async Task GetRatesCountByBookIdShouldReturnZeroWhenInvalidBookId() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var rates = new List <StarRating>(); for (int i = 1; i <= 10; i++) { rates.Add(new StarRating { Rate = i, UserId = i.ToString(), BookId = 1, }); } await db.AddRangeAsync(rates); await db.SaveChangesAsync(); var ratingsService = new StarRatingsService(db); var result = await ratingsService.GetRatesCountByBookIdAsync(3); Assert.Equal(0, result); }
public async Task DoesReviewIdExistShouldReturnFalseIfNotFound() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, }, new Review { Description = "description2", AuthorId = "author1", BookId = 1, ParentId = 1, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.DoesReviewIdExistAsync(5); Assert.False(result); }
public async Task GetReviewByIdShouldReturnCorrectReview() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, }, new Review { Description = "description2", AuthorId = "author1", BookId = 1, ParentId = 1, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetReviewByIdAsync <ReviewTestModel>(2); Assert.Equal("description2", result.Description); Assert.NotNull(result.ParentId); }
public async Task DeleteReviewShouldSetIsDeletedAndDeletedOn() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, ReadingProgress = ReadingProgress.Finished, }, new Review { Description = "description2", AuthorId = "author2", BookId = 1, ReadingProgress = ReadingProgress.Finished, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); await reviewsService.DeleteReviewByIdAsync(1); var result = await db.Reviews.FirstOrDefaultAsync(); Assert.NotNull(result.DeletedOn); Assert.True(result.IsDeleted); }
public async Task GetAllReviewsByAuthorIdShouldReturnAllReviews() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", }, new Review { Description = "description1", AuthorId = "author1", }, new Review { Description = "description1", AuthorId = "author1", }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetAllReviewsByAuthorIdAsync <ReviewTestModel>("author1"); Assert.Equal(3, result.Count()); }
public async Task AreReviewsAboutSameBookShouldReturnFalseIfDeleted() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, ReadingProgress = ReadingProgress.Finished, IsDeleted = true, }, new Review { Description = "description2", AuthorId = "author2", BookId = 1, ReadingProgress = ReadingProgress.Finished, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.AreReviewsAboutSameBookAsync(1, 1); Assert.False(result); }
public async Task GetAuthorIdByIdShouldReturnNullIfDeleted() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, IsDeleted = true, }, new Review { Description = "description2", AuthorId = "author1", BookId = 1, ParentId = 1, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetAuthorIdByIdAsync(1); Assert.Null(result); }
public async Task GetChildrenReviewsToReviewsAsyncShouldNotReturnReviewsWithOtherBookId() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, }, new Review { Description = "description2", AuthorId = "author1", BookId = 1, }, new Review { Description = "description3", AuthorId = "author1", BookId = 1, ParentId = 1, }, new Review { Description = "description4", AuthorId = "author1", BookId = 2, ParentId = 2, }, new Review { Description = "description4", AuthorId = "author1", BookId = 1, ParentId = 3, }, new Review { Description = "description4", AuthorId = "author1", BookId = 1, ParentId = 4, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var ids = new List <int> { 1, 2 }; var result = await reviewsService.GetChildrenReviewsToReviewsAsync <ReviewTestModel>(ids, 1); Assert.Equal(2, result.Count()); }
public async Task GetAllTagsMethodShouldReturnCorrectCountWhenBothTakeAndSkipAreGiven() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var tags = new List <Tag>(); for (int i = 1; i <= 10; i++) { tags.Add(new Tag { Name = $"test{i}", CreatedOn = DateTime.UtcNow, }); } await db.AddRangeAsync(tags); await db.SaveChangesAsync(); var tagsService = new TagsService(db); var resultTags = await tagsService.GetAllTagsAsync <TagTestModel>(5, 5); Assert.Equal(5, resultTags.ToList().Count()); }
public async Task GetAllTagsMethodShouldReturnZeroIfTagsAreDeleted() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var tags = new List <Tag>(); for (int i = 1; i <= 10; i++) { tags.Add(new Tag { Name = $"test{i}", CreatedOn = DateTime.UtcNow, IsDeleted = true, DeletedOn = DateTime.UtcNow, }); } await db.AddRangeAsync(tags); await db.SaveChangesAsync(); var tagsService = new TagsService(db); var resultTags = await tagsService.GetAllTagsAsync <TagTestModel>(); Assert.Empty(resultTags.ToList()); }
public async Task GetAllReviewsByAuthorIdShouldReturnCollectionWithCorrectOrder() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", Likes = new List <Like> { new Like { ReviewId = 1, UserId = "1", IsLiked = true } }, }, new Review { Description = "description2", AuthorId = "author1", Likes = new List <Like> { new Like { ReviewId = 2, UserId = "1", IsLiked = false } }, }, new Review { Description = "description3", AuthorId = "author1", Likes = new List <Like> { new Like { ReviewId = 3, UserId = "1", IsLiked = true }, new Like { ReviewId = 3, UserId = "1", IsLiked = true } }, }, new Review { Description = "description4", AuthorId = "author1", }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetAllReviewsByAuthorIdAsync <ReviewTestModel>("author1"); var resultReviews = result.ToArray(); Assert.Equal(4, resultReviews.Count()); Assert.Equal("description3", resultReviews[0].Description); Assert.Equal("description1", resultReviews[1].Description); }
public async Task GetTopReviewsByBookIdShouldNotReturnDeletedAndReviewsWithParentId() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, }, new Review { Description = "description2", AuthorId = "author1", BookId = 1, ParentId = 1, }, new Review { Description = "description3", AuthorId = "author1", BookId = 1, }, new Review { Description = "description4", AuthorId = "author1", BookId = 1, IsDeleted = true, }, new Review { Description = "description4", AuthorId = "author1", BookId = 2, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetTopReviewsByBookIdAsync <ReviewTestModel>(1, 5); Assert.Equal(2, result.Count()); }
public async Task GetChildrenReviewsByReviewIdShouldReturnCorrectResultWhenTakeAndSkipAreUsed() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, }, new Review { Description = "description2", AuthorId = "author1", BookId = 1, ParentId = 1, }, new Review { Description = "description3", AuthorId = "author1", BookId = 1, ParentId = 1, }, new Review { Description = "description4", AuthorId = "author1", BookId = 1, ParentId = 1, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetChildrenReviewsByReviewIdAsync <ReviewTestModel>(1, 5, 1); var resultReview = result.FirstOrDefault(); Assert.Equal(2, result.Count()); Assert.Equal("description3", resultReview.Description); }
public async Task GetChildrenReviewsCountShouldReturnCorrectCount() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.AddRangeAsync( new Review { Description = "description1", AuthorId = "author1", BookId = 1, }, new Review { Description = "description2", AuthorId = "author2", BookId = 1, ParentId = 1, }, new Review { Description = "description3", AuthorId = "author3", BookId = 1, ParentId = 1, }, new Review { Description = "description4", AuthorId = "author4", BookId = 1, ParentId = 1, IsDeleted = true, }); await db.SaveChangesAsync(); var reviewsService = new ReviewsService(db); var result = await reviewsService.GetChildrenReviewsCountByReviewIdAsync(1); Assert.Equal(2, result); }