Пример #1
0
        public IActionResult GetMetricsByTimePeriod([FromRoute] CpuMetricGetByTimePeriodRequest request)
        {
            logger.LogInformation($"From={request.From}|To={request.To}");
            var requestDAL = mapper.Map <DAL.Requests.CpuMetricGetByTimePeriodRequest>(request);
            var metrics    = repository.GetByTimePeriod(requestDAL);
            var response   = new CpuMetricsResponse();

            response.Metrics = metrics.Select(metric => mapper.Map <CpuMetricDto>(metric)).ToList();
            return(Ok(response));
        }
Пример #2
0
        public IList <CpuMetric> GetByTimePeriod(CpuMetricGetByTimePeriodRequest request)
        {
            using var connection = Connection.New();
            var result = connection.Query <CpuMetric>($"SELECT * FROM CpuMetrics 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.CpuMetricGetByTimePeriodRequest>()))
            .Returns(new List <CpuMetric>());

            //Arrange
            CpuMetricGetByTimePeriodRequest request = new CpuMetricGetByTimePeriodRequest
            {
                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.CpuMetricGetByTimePeriodRequest>()), Times.AtMostOnce());
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }