public void GetMetricsByPercentileFromAgent_ReturnsOk()
        {
            int        agentId = 1;
            Percentile percentile;

            percentile = Percentile.P75;
            var fixture    = new Fixture();
            var returnList = fixture.Create <AllHddMetricsApiResponse>();

            double[] masValue = new double[returnList.Metrics.Count];
            for (int i = 0; i < masValue.Length; i++)
            {
                masValue[i] = returnList.Metrics[i].Value;
            }
            var percentileCalculationMethod = new PercentileCalculationMethod();
            var percentileValue             = percentileCalculationMethod.PercentileCalculation(masValue, (double)percentile / 100);

            _metricsAgentClient.Setup(repository => repository.GetAllHddMetrics(It.IsAny <GetAllHddMetricsApiRequest>())).Returns(returnList);

            var fromTime = DateTimeOffset.Now.AddHours(-1);
            var toTime   = DateTimeOffset.Now;
            var result   = (OkObjectResult)_controller.GetMetricsByPercentileFromAgent(agentId, fromTime, toTime, percentile);

            var actualResult = result.Value;

            _metricsAgentClient.Verify(repository => repository.GetAllHddMetrics(It.IsAny <GetAllHddMetricsApiRequest>()));
            _ = Assert.IsAssignableFrom <IActionResult>(result);
            Assert.Equal(actualResult, percentileValue);
        }
示例#2
0
        public void GetHddPercentileFromAgent()
        {
            //Arrange
            var fixture    = new Fixture();
            var returnList = fixture.Create <List <HddMetricModel> >();

            _repository.Setup(a => a.GetMetricsFromTimeToTimeFromAgentOrderBy(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>(), "value", 1))
            .Returns(returnList).Verifiable();
            //Act
            var result = (OkObjectResult)_controller.GetMetricsByPercentileFromAgent(1,
                                                                                     DateTimeOffset.FromUnixTimeSeconds(0),
                                                                                     DateTimeOffset.FromUnixTimeSeconds(17000000000),
                                                                                     Percentile.P90);

            //Assert
            _repository.Verify(repository => repository.GetMetricsFromTimeToTimeFromAgentOrderBy(
                                   DateTimeOffset.FromUnixTimeSeconds(0),
                                   DateTimeOffset.FromUnixTimeSeconds(17000000000),
                                   "value",
                                   1),
                               Times.Once());
            _ = Assert.IsAssignableFrom <IActionResult>(result);
            int percentileThisList = (int)Percentile.P90;

            percentileThisList = percentileThisList * returnList.Count / 100;

            var returnPercentile = returnList[percentileThisList].Value;

            Assert.Equal(returnPercentile, result.Value);
            _logger.Verify();
        }
        public void GetMetricsByPercentileFromAgent_ReturnsCorrectMetric()
        {
            //Arrange
            var request = new HddMetricGetByIntervalForAgentRequest()
            {
                AgentId  = 1,
                FromTime = DateTimeOffset.MinValue,
                ToTime   = DateTimeOffset.Now
            };
            var percentile = Percentile.P90;

            //фейковые метрики возвращаемые репозиторием
            var mockMetrics = new AllMetrics <HddMetric>();

            mockMetrics.Metrics.Add(new HddMetric()
            {
                AgentId = 1, Time = DateTimeOffset.MinValue, Value = 100
            });

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

            //Act
            var result = controller.GetMetricsByPercentileFromAgent(request, percentile);

            // Assert
            Assert.True(CompareMetricsContainers(result, mockMetrics));
        }
示例#4
0
        public void GetMetricsByPercentileFromAgent_ReturnsOk()
        {
            var agentId    = 1;
            var fromTime   = new DateTime(2012, 11, 11);
            var toTime     = new DateTime(2013, 11, 11);
            var percentile = Percentile.P99;

            var result = _controller.GetMetricsByPercentileFromAgent(agentId, fromTime, toTime, percentile);

            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
示例#5
0
        public void GetMetricsByPercentileFromAgent_ReturnsOk()
        {
            //Arrange
            var agentId  = 1;
            var fromTime = TimeSpan.FromSeconds(0);
            var toTime   = TimeSpan.FromSeconds(100);

            //Act
            var result = _controller.GetMetricsByPercentileFromAgent(agentId, fromTime, toTime);

            // Assert
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void GetMetricsByPercentileFromAgentCheckRequestSelect()
        {
            //Arrange
            DateTimeOffset fromTime   = DateTimeOffset.FromUnixTimeSeconds(3);
            DateTimeOffset toTime     = DateTimeOffset.FromUnixTimeSeconds(15);
            int            agentId    = 1;
            Percentile     percentile = Percentile.P90;
            string         sort       = "value";

            _mock.Setup(a => a.GetByPeriodWithSortingFromAgent(fromTime, toTime, sort, agentId))
            .Returns(new List <HddMetricModel>()).Verifiable();
            //Act
            var result = _controller.GetMetricsByPercentileFromAgent(agentId, fromTime, toTime, percentile);

            //Assert
            _mock.Verify(repository => repository.GetByPeriodWithSortingFromAgent(fromTime, toTime, sort, agentId), Times.AtMostOnce());
            _logger.Verify();
        }
        public void GetMetricsByPercentileFromAgent__ShouldCall_From_Repository()
        {
            //Arrange
            var agentId    = 2;
            var fromTime   = DateTimeOffset.MinValue;
            var toTime     = DateTimeOffset.Now;
            var percentile = Percentile.P90;

            mockRepository
            .Setup(repository => repository.GetInTimePeriodPercentile(
                       It.IsAny <int>(),
                       It.IsAny <DateTimeOffset>(),
                       It.IsAny <DateTimeOffset>(),
                       It.IsAny <Percentile>())).
            Returns(GetTestMetricFromAgent()[1]);

            //Act
            var result = controller.GetMetricsByPercentileFromAgent(agentId, fromTime, toTime, percentile);

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

            Assert.Equal(GetTestMetricFromAgent()[1].Value, response.Value);
        }