public async void Create()
        {
            var mock  = new ServiceMockFacade <ITestAllFieldTypeRepository>();
            var model = new ApiTestAllFieldTypeRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TestAllFieldType>())).Returns(Task.FromResult(new TestAllFieldType()));
            var service = new TestAllFieldTypeService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLTestAllFieldTypeMapperMock,
                                                      mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTestAllFieldTypeRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TestAllFieldType>()));
        }
Пример #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ITestAllFieldTypeService, ITestAllFieldTypeRepository>();

            var model = new ApiTestAllFieldTypeServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TestAllFieldType>())).Returns(Task.FromResult(new TestAllFieldType()));
            var service = new TestAllFieldTypeService(mock.LoggerMock.Object,
                                                      mock.MediatorMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Object,
                                                      mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTestAllFieldTypeServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TestAllFieldType>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TestAllFieldTypeCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Пример #3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ITestAllFieldTypeService, ITestAllFieldTypeRepository>();
            var model         = new ApiTestAllFieldTypeServerRequestModel();
            var validatorMock = new Mock <IApiTestAllFieldTypeServerRequestModelValidator>();

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

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

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