public async Task <IActionResult> UpdateStatus(UpdateLeadStatusCommand command) { try { await this.mediator.Send(command); } catch (InvalidJobIdException e) { return(NotFound(e.Message)); } return(Ok()); }
public async Task UpdateStatusUnitTest(Job job, UpdateLeadStatusCommand command, Type ex) { var jobDbHandler = new Mock <IJobDbHandler>(); jobDbHandler.Setup(jh => jh.GetJobById(1)).ReturnsAsync(job); var handler = new UpdateLeadStatusCommandHandler(jobDbHandler.Object); if (ex == null) { await handler.Handle(command, CancellationToken.None); jobDbHandler.Verify(jh => jh.GetJobById(command.Id), Times.Once); jobDbHandler.Verify(jh => jh.UpdateJobAsync(It.IsAny <Job>()), Times.Once); } else { await Assert.ThrowsAsync(ex, () => handler.Handle(command, CancellationToken.None)); jobDbHandler.Verify(jh => jh.UpdateJobAsync(It.IsAny <Job>()), Times.Never); } }