Exemple #1
0
        public async Task <IActionResult> EnableAgentById([FromRoute] EnableAgentByIdCommand request)
        {
            _logger.LogInformation($"EnableAgentById Parameters: command={request}");

            await _mediator.Send(request);

            return(Ok());
        }
        public async Task EnableAgentById_ReturnOk()
        {
            var command = new EnableAgentByIdCommand()
            {
                AgentId = 1
            };

            _mockMediator.Setup(mediator => mediator.Send(It.IsAny <EnableAgentByIdCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Unit.Value);

            var result = await _controller.EnableAgentById(command);

            _mockMediator.Verify(mediator => mediator.Send(It.Is <EnableAgentByIdCommand>(
                                                               m => m.AgentId == command.AgentId),
                                                           It.IsAny <CancellationToken>()), Times.Once);
            Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void EnableAgentById_ShouldCall_LogInformation()
        {
            var command = new EnableAgentByIdCommand()
            {
                AgentId = 1
            };

            _mockMediator.Setup(mediator => mediator.Send(It.IsAny <EnableAgentByIdCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(Unit.Value);
            var logText = $"EnableAgentById Parameters: command={command}";

            _ = _controller.EnableAgentById(command);

            _mockLogger.Verify(
                x => x.Log(
                    It.Is <LogLevel>(l => l == LogLevel.Information),
                    It.IsAny <EventId>(),
                    It.Is <It.IsAnyType>((v, t) => v.ToString().CompareTo(logText) == 0),
                    It.IsAny <Exception>(),
                    It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)));
        }