Пример #1
0
        public async Task TestIfServiceReturnComment()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context            = new ApplicationDbContext(options.Options);
            var commentsRepository = new EfDeletableEntityRepository <Comment>(context);

            var service = new CommentsService(commentsRepository);

            var firstId = await service.AddCommentAsync(1, "1", "Test content");

            var secondId = await service.AddCommentAsync(1, "1", "Test content 2");

            var thirdId = await service.AddCommentAsync(1, "1", "Test content 3");

            AutoMapperConfig.RegisterMappings(this.GetType().Assembly);

            var firstComment  = service.GetComment <TestCommentModel>(firstId);
            var secondComment = service.GetComment <TestCommentModel>(secondId);
            var thirdComment  = service.GetComment <TestCommentModel>(thirdId);

            Assert.Equal("Test content", firstComment.Content);
            Assert.Equal("Test content 2", secondComment.Content);
            Assert.Equal("Test content 3", thirdComment.Content);
        }
Пример #2
0
        public async Task ShouldGetSingleCommentWithParsedText()
        {
            var id   = 42;
            var text = "Test text";

            repositoryMock.Setup(r => r.GetComment(id)).ReturnsAsync(new Comment()
            {
                Text = text
            });

            await service.GetComment(id);

            repositoryMock.Verify(r => r.GetComment(id), Times.Once);
            parserMock.Verify(p => p.ToHtml(text), Times.Once);
        }
Пример #3
0
 // GET api/comments/5
 public CommentViewModel Get(int id)
 {
     return(new CommentViewModel(_service.GetComment(id)));
 }