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 AllHddMetricsResponse).Metrics;

            Assert.Equal(expectedResult.Count, response.Count);
        }
Beispiel #2
0
        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()
        {
            //Arrange
            var fromTime = DateTimeOffset.FromUnixTimeSeconds(0);
            var toTime   = DateTimeOffset.FromUnixTimeSeconds(100);

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

            //Assert
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
Beispiel #4
0
        public void GetMetricsFromCluster_ReturnsOk()
        {
            //Arrange
            var fromTime = TimeSpan.FromSeconds(0);
            var toTime   = TimeSpan.FromSeconds(100);

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

            // Assert
            _ = Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void GetHddMetricsFromClusterCheckRequestSelect()
        {
            //Arrange
            DateTimeOffset fromTime = DateTimeOffset.FromUnixTimeSeconds(3);
            DateTimeOffset toTime   = DateTimeOffset.FromUnixTimeSeconds(15);

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

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

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

            var result = await _controller.GetMetricsFromAllCluster(request);

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

            _mockMediator.Verify(mediator => mediator.Send(It.Is <HddMetricGetByPeriodQuery>(
                                                               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);
        }
        public void GetMetricsFromAllCluster_ReturnOk()
        {
            var result = _controller.GetMetricsFromAllCluster(_fromTime, _toTime);

            Assert.IsAssignableFrom <IActionResult>(result);
        }
        public void GetMetricsFromAllCluster_ReturnsOk()
        {
            var result = _controller.GetMetricsFromAllCluster();

            _ = Assert.IsAssignableFrom<IActionResult>(result);
        }
        public void GetMetricsFromAllCluster_ReturnsCorrectMetrics()
        {
            //Arrange
            var request = new HddMetricGetByIntervalForClusterRequest()
            {
                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 <HddMetric>();

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

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

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

            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));
        }