Пример #1
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IHandlerPipelineStepRepository>();
            var model = new ApiHandlerPipelineStepRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <HandlerPipelineStep>())).Returns(Task.FromResult(new HandlerPipelineStep()));
            var service = new HandlerPipelineStepService(mock.LoggerMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object,
                                                         mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock,
                                                         mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiHandlerPipelineStepRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <HandlerPipelineStep>()));
        }
Пример #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IHandlerPipelineStepService, IHandlerPipelineStepRepository>();

            var model = new ApiHandlerPipelineStepServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <HandlerPipelineStep>())).Returns(Task.FromResult(new HandlerPipelineStep()));
            var service = new HandlerPipelineStepService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object,
                                                         mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiHandlerPipelineStepServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <HandlerPipelineStep>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerPipelineStepCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Пример #3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IHandlerPipelineStepService, IHandlerPipelineStepRepository>();
            var model         = new ApiHandlerPipelineStepServerRequestModel();
            var validatorMock = new Mock <IApiHandlerPipelineStepServerRequestModelValidator>();

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

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

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