コード例 #1
0
        public void GetMetricsByPercentileFromAgent_ReturnsCorrectMetric()
        {
            //Arrange
            var request = new DotNetMetricGetByIntervalForAgentRequest()
            {
                AgentId  = 1,
                FromTime = DateTimeOffset.MinValue,
                ToTime   = DateTimeOffset.Now
            };
            var percentile = Percentile.P90;

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

            mockMetrics.Metrics.Add(new DotNetMetric()
            {
                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));
        }
コード例 #2
0
        public void GetDotNetPercentileFromAgent()
        {
            //Arrange
            var fixture    = new Fixture();
            var returnList = fixture.Create <List <DotNetMetricModel> >();

            _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();
        }
コード例 #3
0
        public void GetMetricsByPercentileFromAgent_ReturnsOk()
        {
            int        agentId = 1;
            Percentile percentile;

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

            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.GetAllDotNetMetrics(It.IsAny <GetAllDotNetMetricsApiRequest>())).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.GetAllDotNetMetrics(It.IsAny <GetAllDotNetMetricsApiRequest>()));
            _ = Assert.IsAssignableFrom <IActionResult>(result);
            Assert.Equal(actualResult, percentileValue);
        }
コード例 #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);
        }
コード例 #6
0
        public void GetByPeriodPercentileCheckRequestSelect()
        {
            //Arrange
            DateTimeOffset fromTime   = DateTimeOffset.FromUnixTimeSeconds(3);
            DateTimeOffset toTime     = DateTimeOffset.FromUnixTimeSeconds(15);
            Percentile     percentile = Percentile.P99;
            string         sort       = "value";

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

            //Assert
            _mock.Verify(repository => repository.GetByPeriodWithSorting(fromTime, toTime, sort), Times.AtMostOnce());
            _logger.Verify();
        }
コード例 #7
0
        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 DotNetMetricDto);

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