public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ITestAllFieldTypeRepository>();

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

            ApiTestAllFieldTypeResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        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>()));
        }
        public async void All()
        {
            var mock    = new ServiceMockFacade <ITestAllFieldTypeRepository>();
            var records = new List <TestAllFieldType>();

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

            List <ApiTestAllFieldTypeResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITestAllFieldTypeRepository>();
            var model = new ApiTestAllFieldTypeRequestModel();

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

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Esempio n. 5
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <ITestAllFieldTypeService, ITestAllFieldTypeRepository>();
            var model = new ApiTestAllFieldTypeServerRequestModel();

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

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TestAllFieldTypeDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 6
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ITestAllFieldTypeService, ITestAllFieldTypeRepository>();
            var model         = new ApiTestAllFieldTypeServerRequestModel();
            var validatorMock = new Mock <IApiTestAllFieldTypeServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).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);

            ActionResponse response = await service.Delete(default(int));

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