public async Task ShouldSendCommandToMediator() { AddCigarCommand command = new AddCigarCommand() { Blend = "Family Reserve", Brand = "Padron", Gauge = 52, Length = 5.5M }; Guid newCigarId = Guid.NewGuid(); Mock <IMediator> mediatorMock = new Mock <IMediator>(); mediatorMock .Setup(mediator => mediator.Send(command, CancellationToken.None)) .ReturnsAsync(newCigarId); CigarsController controller = new CigarsController(mediatorMock.Object); ActionResult <Guid> result = await controller.Post(command); CreatedAtActionResult actionResult = (CreatedAtActionResult)result.Result; Assert.Equal(newCigarId, actionResult.Value); }
public async Task ShouldSendSaveNewCigarToRepository() { AddCigarCommand command = new AddCigarCommand(); AddCigarCommandHandler handler = CreateHandler(); await handler.Handle(command, CancellationToken.None); _cigarRepositoryMock.Verify(repository => repository.Save(It.Is <Cigar>(cigar => cigar.Id != Guid.Empty) ) ); }
public async Task <ActionResult <Guid> > Post(AddCigarCommand command) { Guid commandResult = await _mediator.Send(command); return(CreatedAtAction(nameof(Get), new { id = commandResult }, commandResult)); }