public IActionResult GetMetricsByTimePeriod([FromRoute] HddMetricGetByTimePeriodRequest request) { logger.LogInformation($"fromTime={request.From}|toTime={request.To}"); var requestDAL = mapper.Map <DAL.Requests.HddMetricGetByTimePeriodRequest>(request); var metrics = repository.GetByTimePeriod(requestDAL); var response = new HddMetricsResponse(); response.Metrics = metrics.Select(metric => mapper.Map <HddMetricDto>(metric)).ToList(); return(Ok(response)); }
public IList <HddMetric> GetByTimePeriod(HddMetricGetByTimePeriodRequest request) { using var connection = Connection.New(); var result = connection.Query <HddMetric>($"SELECT * FROM HddMetrics WHERE Time >= @from AND Time <= @to", new { from = request.From, to = request.To }); return(result.AsList()); }
public void GetMetricsByTimePeriod_ReturnsOk() { //Moq Setup repository.Setup(r => r.GetByTimePeriod(It.IsAny <MetricsAgent.DAL.Requests.HddMetricGetByTimePeriodRequest>())).Returns(new List <HddMetric>()); //Arrange HddMetricGetByTimePeriodRequest request = new HddMetricGetByTimePeriodRequest { From = DateTimeOffset.FromUnixTimeSeconds(0), To = DateTimeOffset.FromUnixTimeSeconds(100) }; //Act var result = controller.GetMetricsByTimePeriod(request); // Assert repository.Verify(r => r.GetByTimePeriod(It.IsAny <MetricsAgent.DAL.Requests.HddMetricGetByTimePeriodRequest>()), Times.AtMostOnce()); _ = Assert.IsAssignableFrom <IActionResult>(result); }