Ejemplo n.º 1
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IQuoteTweetRepository>();
            var model = new ApiQuoteTweetRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <QuoteTweet>())).Returns(Task.FromResult(new QuoteTweet()));
            var service = new QuoteTweetService(mock.LoggerMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object,
                                                mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock,
                                                mock.DALMapperMockFactory.DALQuoteTweetMapperMock);

            CreateResponse <ApiQuoteTweetResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiQuoteTweetRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <QuoteTweet>()));
        }
Ejemplo n.º 2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>();

            var model = new ApiQuoteTweetServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <QuoteTweet>())).Returns(Task.FromResult(new QuoteTweet()));
            var service = new QuoteTweetService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALQuoteTweetMapperMock);

            CreateResponse <ApiQuoteTweetServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiQuoteTweetServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <QuoteTweet>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <QuoteTweetCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>();
            var model         = new ApiQuoteTweetServerRequestModel();
            var validatorMock = new Mock <IApiQuoteTweetServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiQuoteTweetServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new QuoteTweetService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                validatorMock.Object,
                                                mock.DALMapperMockFactory.DALQuoteTweetMapperMock);

            CreateResponse <ApiQuoteTweetServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiQuoteTweetServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <QuoteTweetCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }