public async Task <IActionResult> ReadAllTitle() { var command = new ReadAllTitleCommand(); var result = await this._mediator.Send(command); if (result == null) { return(new BadRequestObjectResult("Something went wrong")); } return(new OkObjectResult(result)); }
public async void ReturnListOfTitle() { _unitOfWork.Setup(mock => mock.TitleRepository.ReadAll()) .Returns(Task.FromResult(list)); var command = new ReadAllTitleCommand(); var handler = new ReadAllTitleHandler(_unitOfWork.Object); List <DBTitle> returnValue = (List <DBTitle>) await handler.Handle(command, new CancellationToken()); Assert.NotNull(returnValue); Assert.Equal(3, returnValue.Count); }
public async void ReturnFalse_IfResultIsNull() { List <DBTitle> list = null; _unitOfWork.Setup(mock => mock.TitleRepository.ReadAll()) .Returns(Task.FromResult(list)); var command = new ReadAllTitleCommand(); var handler = new ReadAllTitleHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.Null(returnValue); }
public async void ReturnNull_IfExceptionOccurs() { var exc = new Exception(); _unitOfWork.Setup(mock => mock.TitleRepository.ReadAll()) .Throws(exc); var command = new ReadAllTitleCommand(); var handler = new ReadAllTitleHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.Null(returnValue); }