Пример #1
0
        public async Task GetLikesCountShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);
            await db.Likes.AddRangeAsync(
                new Like { UserId = "user1", ReviewId = 1, IsLiked = true },
                new Like { UserId = "user2", ReviewId = 2, IsLiked = true },
                new Like { UserId = "user2", ReviewId = 1, IsLiked = true },
                new Like { UserId = "user2", ReviewId = 1, IsLiked = false });

            await db.SaveChangesAsync();

            var likesService = new LikesService(db);

            var result = await likesService.GetLikesCountByReviewIdAsync(1);

            Assert.Equal(2, result);
        }