public void GetMetricsFromAgent_ReturnsOk()
        {
            //Arrange


            //Act
            var result = controller.GetMetrics();

            // Assert
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
Beispiel #2
0
        public void GetMetricsByInterval_ReturnsCorrectMetrics()
        {
            //Arrange
            var request = new HddMetricGetByIntervalRequest()
            {
                FromTime = DateTimeOffset.MinValue,
                ToTime   = DateTimeOffset.Now
            };

            //фейковые метрики возвращаемые репозиторием
            var mockMetrics = new List <HddMetric>()
            {
                { new HddMetric()
                  {
                      Time = DateTimeOffset.MinValue, Value = 100
                  } },
                { new HddMetric()
                  {
                      Time = DateTimeOffset.UtcNow, Value = 121
                  } }
            };

            mockRepository.
            Setup(repository => repository.GetByTimeInterval(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())).
            Returns(mockMetrics);

            //Act
            var result = controller.GetMetrics(request);

            var response = ((result as OkObjectResult).Value as AllHddMetricsResponse).Metrics;

            //сравнение полученных значений с ожидаемыми значениями
            bool check = true;

            if (mockMetrics.Count == response.Count)
            {
                for (int i = 0; i < mockMetrics.Count; i++)
                {
                    if ((mockMetrics[i].Value != response[i].Value) ||
                        (mockMetrics[i].Time != response[i].Time))
                    {
                        check = false;
                    }
                }
            }
            else
            {
                check = false;
            }

            // Assert
            Assert.True(check);
        }
        public void GetMetrics_ShouldCall_GetInTimePeriod_From_Repository()
        {
            var fromTime = DateTimeOffset.MinValue;
            var toTime   = DateTimeOffset.Now;

            // Arrange
            mockRepository.
            Setup(repository => repository.GetInTimePeriod(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>()))
            .Returns(GetTestHddMetric());

            // Act
            var result = controller.GetMetrics(fromTime, toTime);

            // Assert
            var response = ((result as OkObjectResult).Value as AllHddMetricsResponse).Metrics;

            Assert.Equal(GetTestHddMetric().Count, response.Count);
        }
Beispiel #4
0
        public void GetMetrics_returnsOk()
        {
            var actual = _controller.GetMetrics(fromTime, toTime);

            _ = Assert.IsAssignableFrom <IActionResult>(actual);
        }