コード例 #1
0
        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);
        }
コード例 #2
0
        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)
                                                        )
                                        );
        }
コード例 #3
0
        public async Task <ActionResult <Guid> > Post(AddCigarCommand command)
        {
            Guid commandResult = await _mediator.Send(command);

            return(CreatedAtAction(nameof(Get), new { id = commandResult }, commandResult));
        }