public IActionResult Delete(string id) { var apiRep = new APIResponse(); var rate = _rateService.Get(id); if (rate == null) { apiRep.Error = false; apiRep.Data = null; return(Ok(apiRep)); } _rateService.Delete(rate.Id); apiRep.Error = false; apiRep.Data = true; return(Ok(apiRep)); }
public async void Delete() { var mock = new ServiceMockFacade <IRateRepository>(); var model = new ApiRateRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new RateService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.RateModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLRateMapperMock, mock.DALMapperMockFactory.DALRateMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.RateModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IRateService, IRateRepository>(); var model = new ApiRateServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new RateService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.RateModelValidatorMock.Object, mock.DALMapperMockFactory.DALRateMapperMock); 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.RateModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <RateDeletedNotification>(), It.IsAny <CancellationToken>())); }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IRateService, IRateRepository>(); var model = new ApiRateServerRequestModel(); var validatorMock = new Mock <IApiRateServerRequestModelValidator>(); 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 RateService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALRateMapperMock); 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 <RateDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }