コード例 #1
0
        public static PublicationResponse ToResponseModel(Publication publication)
        {
            var result = new PublicationResponse
            {
                Id           = publication.Id,
                Text         = publication.Text,
                Title        = publication.Title,
                CreationDate = publication.CreationDate,
                Author       = new UserResponse
                {
                    Id        = publication.Author.Id,
                    FirstName = publication.Author.FirstName,
                    LastName  = publication.Author.LastName
                }
            };

            return(result);
        }
        public async Task GetAllAsyncWhenNoPublicationsReturnsEmptyCollection()
        {
            //Arrange
            var mockPublicationRepository = GetDefaultIPublicationRepositoryInstance();
            var mockUnitOfWork            = GetDefaultIUnitOfWorkInstance();
            var publicationId             = 200;

            mockPublicationRepository.Setup(r => r.FindById(publicationId))
            .Returns(Task.FromResult <Publication>(null));

            var service = new PublicationService(mockPublicationRepository.Object, mockUnitOfWork.Object);
            //Act
            PublicationResponse result = await service.GetByIdAsync(publicationId);

            var message = result.Message;

            //Assert
            message.Should().Be("Publication not found");
        }