public void GetMetricsFromAllCluster_ShouldCall_From_Repository()
        {
            //Arrange
            var fromTime = DateTimeOffset.MinValue;
            var toTime   = DateTimeOffset.Now;

            mockAgentsRepository
            .Setup(repository => repository.GetAllAgentsInfo())
            .Returns(GetTestAgentsInfo().FindAll(m => (m.AgentId <= 2)));

            mockRepository.
            Setup(repository => repository.GetInTimePeriod(
                      It.Is <int>(agentId => agentId == 2),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>())).
            Returns(GetTestMetric().FindAll(m => m.AgentId == 2));

            mockRepository.
            Setup(repository => repository.GetInTimePeriod(
                      It.Is <int>(agentId => agentId == 1),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>())).
            Returns(GetTestMetric().FindAll(m => m.AgentId == 1));

            //Act
            var result         = controller.GetMetricsFromAllCluster(fromTime, toTime);
            var expectedResult = GetTestMetric().FindAll(m => (m.AgentId <= 2));
            // Assert
            var response = ((result as OkObjectResult).Value as AllDotNetMetricsResponse).Metrics;

            Assert.Equal(expectedResult.Count, response.Count);
        }
        public void GetMetricsFromAllCluster()
        {
            var fromTime = new DateTime(2012, 11, 11);
            var toTime   = new DateTime(2013, 11, 11);

            var result = _controller.GetMetricsFromAllCluster(fromTime, toTime);

            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void GetMetricsFromAllCluster_ReturnsOk()
        {
            var fromTime = TimeSpan.FromSeconds(0);
            var toTime   = TimeSpan.FromSeconds(100);

            var result = _controller.GetMetricsFromAllCluster(fromTime, toTime);

            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
예제 #4
0
        public void GetMetricsFromAllCluster_ReturnsOk()
        {
            //Arrange
            var fromTime = DateTimeOffset.FromUnixTimeSeconds(0);
            var toTime   = DateTimeOffset.FromUnixTimeSeconds(100);

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

            // Assert
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
예제 #5
0
        public void GetDotNetMetricsFromClusterCheckRequestSelect()
        {
            //Arrange
            DateTimeOffset fromTime = DateTimeOffset.FromUnixTimeSeconds(3);
            DateTimeOffset toTime   = DateTimeOffset.FromUnixTimeSeconds(15);

            _mock.Setup(a => a.GetByPeriod(fromTime, toTime)).Returns(new List <DotNetMetricModel>()).Verifiable();
            //Act
            var result = _controller.GetMetricsFromAllCluster(fromTime, toTime);

            //Assert
            _mock.Verify(repository => repository.GetByPeriod(fromTime, toTime), Times.AtMostOnce());
            _logger.Verify();
        }
예제 #6
0
        public async Task GetMetricsFromAllCluster_ReturnOk()
        {
            var request = new DotNetMetricGetByPeriodQuery()
            {
                FromTime = DateTimeOffset.Now.AddDays(-1),
                ToTime   = DateTimeOffset.Now
            };

            _mockMediator.Setup(mediator => mediator.Send(It.IsAny <DotNetMetricGetByPeriodQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new DotNetMetricResponse()
            {
                Metrics = new List <DotNetMetricDto>()
                {
                    new DotNetMetricDto()
                    {
                        Id      = 1,
                        AgentId = 1,
                        Time    = DateTimeOffset.Now,
                        Value   = 99
                    }
                }
            });

            var result = await _controller.GetMetricsFromAllCluster(request);

            var resultValue = ((OkObjectResult)result).Value as DotNetMetricResponse;

            _mockMediator.Verify(mediator => mediator.Send(It.Is <DotNetMetricGetByPeriodQuery>(
                                                               m => m.FromTime == request.FromTime && m.ToTime == request.ToTime),
                                                           It.IsAny <CancellationToken>()), Times.Once);
            Assert.Single(resultValue.Metrics);
            Assert.Equal(1, resultValue.Metrics[0].Id);
            Assert.Equal(1, resultValue.Metrics[0].AgentId);
            Assert.Equal(99, resultValue.Metrics[0].Value);
            Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void GetMetricsFromAllCluster_ReturnsOk()
        {
            //Подготовка данных
            var period = new TimePeriod
            {
                From = DateTimeOffset.FromUnixTimeSeconds(0),
                To   = DateTimeOffset.FromUnixTimeSeconds(100)
            };

            //Действие
            var result = _controller.GetMetricsFromAllCluster(period);

            //Проверка результата
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
예제 #8
0
        public void GetMetricsFromAllCluster_ReturnsCorrectMetrics()
        {
            //Arrange
            var request = new DotNetMetricGetByIntervalForClusterRequest()
            {
                FromTime = DateTimeOffset.MinValue,
                ToTime   = DateTimeOffset.Now
            };

            //фейковые данные об агентах
            var mockAgentsInfo = new AllAgentsInfo();

            mockAgentsInfo.Agents.Add(new AgentInfo()
            {
                AgentId = 1, AgentUri = "url1"
            });
            mockAgentsInfo.Agents.Add(new AgentInfo()
            {
                AgentId = 2, AgentUri = "url2"
            });

            mockAgentsRepository.
            Setup(repository => repository.GetAllAgentsInfo()).
            Returns(mockAgentsInfo);

            //фейковые метрики возвращаемые репозиторием для всех агентов
            var mockMetrics = new AllMetrics <DotNetMetric>();

            mockMetrics.Metrics.Add(new DotNetMetric()
            {
                AgentId = 1, Time = DateTimeOffset.MinValue, Value = 100
            });
            mockMetrics.Metrics.Add(new DotNetMetric()
            {
                AgentId = 1, Time = DateTimeOffset.UtcNow, Value = 121
            });
            mockMetrics.Metrics.Add(new DotNetMetric()
            {
                AgentId = 2, Time = DateTimeOffset.MinValue, Value = 101
            });
            mockMetrics.Metrics.Add(new DotNetMetric()
            {
                AgentId = 2, Time = DateTimeOffset.UtcNow, Value = 122
            });

            //фейковые метрики возвращаемые репозиторием для первого агента
            var mockMetricsForAgent_1 = new AllMetrics <DotNetMetric>();

            mockMetricsForAgent_1.Metrics.Add(mockMetrics.Metrics[0]);
            mockMetricsForAgent_1.Metrics.Add(mockMetrics.Metrics[1]);
            //фейковые метрики возвращаемые репозиторием для второго агента
            var mockMetricsForAgent_2 = new AllMetrics <DotNetMetric>();

            mockMetricsForAgent_2.Metrics.Add(mockMetrics.Metrics[2]);
            mockMetricsForAgent_2.Metrics.Add(mockMetrics.Metrics[3]);

            mockRepository.
            Setup(repository => repository.GetByTimeInterval(
                      It.Is <int>(agentId => agentId == 1),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>())).
            Returns(mockMetricsForAgent_1);
            mockRepository.
            Setup(repository => repository.GetByTimeInterval(
                      It.Is <int>(agentId => agentId == 2),
                      It.IsAny <DateTimeOffset>(),
                      It.IsAny <DateTimeOffset>())).
            Returns(mockMetricsForAgent_2);

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

            // Assert
            Assert.True(CompareMetricsContainers(result, mockMetrics));
        }
예제 #9
0
        public void GetMetricsFromAllCluster_ReturnOk()
        {
            var result = _controller.GetMetricsFromAllCluster(_fromTime, _toTime);

            Assert.IsAssignableFrom <IActionResult>(result);
        }