Example #1
0
        public async Task GetAllLikesByCommentIdAsyncShouldReturnLikesSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var commentsService = new CommentsService(dbContext, null, usersService);

            var user = new ApplicationUser
            {
                FirstName = UserFirstName,
                LastName  = UserLastName,
            };

            await dbContext.Users.AddAsync(user);

            await dbContext.SaveChangesAsync();

            var comment = new Comment
            {
                Text     = CommentText,
                AuthorId = user.Id,
            };

            await dbContext.Comments.AddAsync(comment);

            await dbContext.SaveChangesAsync();

            var like = UserFirstName + user.Id;

            for (int i = 0; i < 4; i++)
            {
                comment.LikesUsersNames.Add(like);
            }

            dbContext.Update(comment);

            await dbContext.SaveChangesAsync();

            var likes = await commentsService.GetAllLikesByCommentIdAsync(comment.Id);

            Assert.Equal(4, likes.Count);
        }