public async void Get_null_record() { var mock = new ServiceMockFacade <IHandlerPipelineStepRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <HandlerPipelineStep>(null)); var service = new HandlerPipelineStepService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock); ApiHandlerPipelineStepResponseModel 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 <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>())); }
public async void All() { var mock = new ServiceMockFacade <IHandlerPipelineStepRepository>(); var records = new List <HandlerPipelineStep>(); records.Add(new HandlerPipelineStep()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); var service = new HandlerPipelineStepService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock); List <ApiHandlerPipelineStepResponseModel> 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 <IHandlerPipelineStepRepository>(); var model = new ApiHandlerPipelineStepRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new HandlerPipelineStepService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IHandlerPipelineStepService, IHandlerPipelineStepRepository>(); var model = new ApiHandlerPipelineStepServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new HandlerPipelineStepService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerPipelineStepModelValidatorMock.Object, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock); 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.HandlerPipelineStepModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerPipelineStepDeletedNotification>(), It.IsAny <CancellationToken>())); }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IHandlerPipelineStepService, IHandlerPipelineStepRepository>(); var model = new ApiHandlerPipelineStepServerRequestModel(); var validatorMock = new Mock <IApiHandlerPipelineStepServerRequestModelValidator>(); 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 HandlerPipelineStepService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock); 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 <HandlerPipelineStepDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }