Example #1
0
        public async Task EditMessageCommentShouldReturnFalse()
        {
            var comments = new List <Comment>();
            var appUsers = new List <ApplicationUser>();

            var mockCommentRepo = new Mock <IDeletableEntityRepository <Comment> >();

            mockCommentRepo.Setup(x => x.All()).Returns(comments.AsQueryable());
            mockCommentRepo.Setup(x => x.AddAsync(It.IsAny <Comment>())).Callback((Comment comm) => comments.Add(comm));

            var mockAppUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockAppUser.Setup(x => x.All()).Returns(appUsers.AsQueryable());
            mockAppUser.Setup(x => x.AddAsync(It.IsAny <ApplicationUser>())).Callback((ApplicationUser appU) => appUsers.Add(appU));

            var service = new CommentsService(mockCommentRepo.Object, null, mockAppUser.Object);

            var commentToChangeContent = new Comment
            {
                Id       = "1",
                UserId   = "1",
                SentById = "1",
                Content  = "Are you crazy",
            };

            comments.Add(commentToChangeContent);
            Task result = service.EditMessageComment("1", "newContent", "2");

            Assert.False(result.IsFaulted);
        }