Exemplo n.º 1
0
        public void AddComment_ReceivesAddCommentRequest_ExpectsCommentModel()
        {
            var username  = "******";
            var title     = "My Article 1";
            var content   = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
            var thumbnail = new byte[] { 72, 101, 108, 108, 111 };

            var article = new Article(
                username,
                title,
                content,
                thumbnail);

            var comment = new Comment(3, username, "Blahblhablah");

            var mockArticlesRepo = new Mock <IArticlesRepository>();

            var mockCommentsRepo = new Mock <ICommentsRepository>();

            mockCommentsRepo
            .Setup(x => x.CreateAsync(It.IsAny <Comment>()))
            .ReturnsAsync(comment);

            var mockLogger = new Mock <ILogger <ArticlesService> >();

            var mockValidationFactory = new Mock <IValidatorFactory>();

            mockValidationFactory.Setup(x =>
                                        x.GetValidator <AddCommentRequest>()).Returns(new AddCommentRequestValidator());

            var mockContext = GetServerCallContext("AddComment");

            var service = new ArticlesService(
                mockLogger.Object,
                mockArticlesRepo.Object,
                mockCommentsRepo.Object,
                mockValidationFactory.Object);

            var request = new AddCommentRequest
            {
                ArticleId = 3,
                Content   = comment.Content,
                User      = comment.Username,
            };

            var result = service.AddComment(request, mockContext).Result;

            Assert.Equal(result.ArticleId, request.ArticleId);
            Assert.Equal(result.User, request.User);
            Assert.Equal(result.Content, request.Content);
        }