public async Task GetMetricsByPeriod_ReturnOk() { var request = new DotNetMetricGetByPeriodQuery() { FromTime = DateTimeOffset.Now.AddDays(-5), ToTime = DateTimeOffset.Now }; _mockMediator.Setup(mediator => mediator.Send(It.IsAny <DotNetMetricGetByPeriodQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new AgentDotNetMetricResponse() { Metrics = new List <AgentDotNetMetricDto>() { new AgentDotNetMetricDto() { Id = 1, Time = DateTimeOffset.Now, Value = 99 } } }); var result = await _controller.GetMetricsByPeriod(request); var resultValue = ((OkObjectResult)result).Value as AgentDotNetMetricResponse; _mockMediator.Verify(mediator => mediator.Send(It.Is <DotNetMetricGetByPeriodQuery>( m => m.FromTime == request.FromTime && m.ToTime == request.ToTime), It.IsAny <CancellationToken>()), Times.Once); _mockMediator.Verify(mediator => mediator.Send(It.IsAny <DotNetMetricGetByPeriodQuery>(), It.IsAny <CancellationToken>()), Times.Once); Assert.Single(resultValue.Metrics); Assert.Equal(1, resultValue.Metrics[0].Id); Assert.Equal(99, resultValue.Metrics[0].Value); Assert.IsAssignableFrom <IActionResult>(result); }