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

            await _mediator.Send(request);

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

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

            var result = await _controller.DisableAgentById(command);

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

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

            _ = _controller.DisableAgentById(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)));
        }