public ActionResult <Species> Delete(int id) { try { return(Ok(_serv.Delete(id))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public async void Delete() { var mock = new ServiceMockFacade <ISpeciesRepository>(); var model = new ApiSpeciesRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new SpeciesService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSpeciesMapperMock, mock.DALMapperMockFactory.DALSpeciesMapperMock, mock.BOLMapperMockFactory.BOLBreedMapperMock, mock.DALMapperMockFactory.DALBreedMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ISpeciesService, ISpeciesRepository>(); var model = new ApiSpeciesServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new SpeciesService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SpeciesModelValidatorMock.Object, mock.DALMapperMockFactory.DALSpeciesMapperMock, mock.DALMapperMockFactory.DALBreedMapperMock); 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.SpeciesModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SpeciesDeletedNotification>(), It.IsAny <CancellationToken>())); }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ISpeciesService, ISpeciesRepository>(); var model = new ApiSpeciesServerRequestModel(); var validatorMock = new Mock <IApiSpeciesServerRequestModelValidator>(); 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 SpeciesService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALSpeciesMapperMock, mock.DALMapperMockFactory.DALBreedMapperMock); 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 <SpeciesDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }