public void GetMetricsFromAgent_ReturnsCorrectMetrics() { //Arrange var request = new DotNetMetricGetByIntervalForAgentRequest() { AgentId = 1, FromTime = DateTimeOffset.MinValue, ToTime = DateTimeOffset.Now }; //фейковые метрики возвращаемые репозиторием 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 }); mockRepository. Setup(repository => repository.GetByTimeInterval(It.IsAny <int>(), It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())). Returns(mockMetrics); //Act var result = controller.GetMetricsFromAgent(request); // Assert Assert.True(CompareMetricsContainers(result, mockMetrics)); }
public void GetMetricsFromAgent_ShouldCall_From_Repository() { //Arrange var agentId = 2; var fromTime = DateTimeOffset.MinValue; var toTime = DateTimeOffset.Now; mockAgentsRepository .Setup(repository => repository.GetAllAgentsInfo()) .Returns(GetTestAgentsInfo()); mockRepository .Setup(repository => repository.GetInTimePeriod( It.IsAny <int>(), It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns(GetTestMetricFromAgent()); //Act var result = controller.GetMetricsFromAgent(agentId, fromTime, toTime); // Assert var response = ((result as OkObjectResult).Value as AllDotNetMetricsResponse).Metrics; Assert.Equal(GetTestMetricFromAgent().Count, response.Count); }
public void GetDotNetMetricsFromAgent() { //Arrange var fixture = new Fixture(); var returnList = fixture.Create <List <DotNetMetricModel> >(); _repository.Setup(a => a.GetMetricsFromTimeToTimeFromAgent(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>(), 1)) .Returns(returnList).Verifiable(); //Act var result = (OkObjectResult)_controller.GetMetricsFromAgent(1, DateTimeOffset.FromUnixTimeSeconds(0), DateTimeOffset.FromUnixTimeSeconds(17000000000)); var actualResult = (AllDotNetMetricsResponse)result.Value; //Assert _repository.Verify(repository => repository.GetMetricsFromTimeToTimeFromAgent( DateTimeOffset.FromUnixTimeSeconds(0), DateTimeOffset.FromUnixTimeSeconds(17000000000), 1), Times.Once()); _ = Assert.IsAssignableFrom <IActionResult>(result); for (int i = 0; i < returnList.Count; i++) { Assert.Equal(returnList[i].Id, actualResult.Metrics[i].Id); Assert.Equal(returnList[i].Value, actualResult.Metrics[i].Value); Assert.Equal(returnList[i].IdAgent, actualResult.Metrics[i].IdAgent); } _logger.Verify(); }
public void GetMetricsFromAgent_ReturnsOk() { var fromTime = DateTimeOffset.FromUnixTimeSeconds(0); var toTime = DateTimeOffset.FromUnixTimeSeconds(100); var result = _controller.GetMetricsFromAgent(fromTime, toTime); _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetMetricsFromAgent_ReturnsOk() { var agentId = 1; var fromTime = TimeSpan.FromSeconds(0); var toTime = TimeSpan.FromSeconds(100); var result = _controller.GetMetricsFromAgent(agentId, fromTime, toTime); _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetMetricsFromAgent_ReturnsOk() { int errorsCount = 1; var fromTime = TimeSpan.FromSeconds(0); var toTime = TimeSpan.FromSeconds(100); //Act var result = controller.GetMetricsFromAgent(errorsCount, fromTime, toTime); // Assert _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetMetricsFromAgent_ReturnsOk() { //Arrange var agentId = 1; var fromTime = new DateTime(2012, 11, 11); var toTime = new DateTime(2013, 11, 11); //Act var result = _controller.GetMetricsFromAgent(agentId, fromTime, toTime); // Assert _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetMetricsFromAgent_ReturnOk() { //Arrange var agentId = 1; var fromTime = DateTimeOffset.Now.AddDays(-4); var toTime = DateTimeOffset.Now; //Act var result = controller.GetMetricsFromAgent(agentId, fromTime, toTime); //Assert _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetFromTimeToTime() { _mock.Setup(repository => repository.GetFromTo(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())).Verifiable(); DateTime d1 = new DateTime(2011, 10, 10); DateTime d2 = new DateTime(2011, 11, 11); DateTimeOffset fromTime = new DateTimeOffset(d1); DateTimeOffset toTime = new DateTimeOffset(d2); var result = _controller.GetMetricsFromAgent(fromTime, toTime); _mock.Verify(repository => repository.GetFromTo(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>()), Times.AtMostOnce()); }
public void GetMetricsFromAgent_ReturnsOk() { //Arrange var agentId = 1; var fromTime = DateTimeOffset.FromUnixTimeSeconds(0); var toTime = DateTimeOffset.FromUnixTimeSeconds(100); //Act var result = controller.GetMetricsFromAgent(agentId, fromTime, toTime); // Assert _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetByPeriodCheckRequestSelect() { //Arrange DateTimeOffset fromTime = DateTimeOffset.FromUnixTimeSeconds(3); DateTimeOffset toTime = DateTimeOffset.FromUnixTimeSeconds(15); _mock.Setup(a => a.GetByPeriod(fromTime, toTime)).Returns(new List <DotNetMetric>()).Verifiable(); //Act var result = _controller.GetMetricsFromAgent(fromTime, toTime); //Assert _mock.Verify(repository => repository.GetByPeriod(fromTime, toTime), Times.AtMostOnce()); _logger.Verify(); }
public async Task GetMetricsFromAgent_ReturnOk() { var request = new DotNetMetricGetByPeriodFromAgentQuery() { AgentId = 2, FromTime = DateTimeOffset.Now.AddDays(-1), ToTime = DateTimeOffset.Now }; _mockMediator.Setup(mediator => mediator.Send(It.IsAny <DotNetMetricGetByPeriodFromAgentQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new DotNetMetricResponse() { Metrics = new List <DotNetMetricDto>() { new DotNetMetricDto() { Id = 1, AgentId = 2, Time = DateTimeOffset.Now, Value = 99 } } }); var result = await _controller.GetMetricsFromAgent(request); var resultValue = ((OkObjectResult)result).Value as DotNetMetricResponse; _mockMediator.Verify(mediator => mediator.Send(It.Is <DotNetMetricGetByPeriodFromAgentQuery>( m => m.AgentId == request.AgentId && 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(request.AgentId, resultValue.Metrics[0].AgentId); Assert.Equal(99, resultValue.Metrics[0].Value); Assert.IsAssignableFrom <IActionResult>(result); }
public void GetMetricsFromAgent_ReturnsOk() { //Подготовка данных var agentId = 1; var period = new TimePeriod { From = DateTimeOffset.FromUnixTimeSeconds(0), To = DateTimeOffset.FromUnixTimeSeconds(100) }; //Действие var result = _controller.GetMetricsFromAgent(agentId, period); //Проверка результата _ = Assert.IsAssignableFrom <IActionResult>(result); }
public void GetMetricsFromAgent_ReturnsOk() { var fixture = new Fixture(); var returnList = fixture.Create <List <DotNetMetrics> >(); _mock.Setup(repository => repository.GetByTimeInterval(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())).Returns(returnList); var fromTime = DateTimeOffset.Now.AddHours(-1); var toTime = DateTimeOffset.Now; var result = (OkObjectResult)_controller.GetMetricsFromAgent(fromTime, toTime); var actualResult = (AllDotNetMetricsApiResponse)result.Value; _mock.Verify(repository => repository.GetByTimeInterval(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())); _ = Assert.IsAssignableFrom <IActionResult>(result); Assert.Equal(returnList[0].Id, actualResult.Metrics[0].Id); }
public void GetDotNetMetricsFromAgent_ReturnsOk() { var fixture = new Fixture(); var returnList = fixture.Create <List <DotNetMetric> >(); _repositoryMock.Setup(repository => repository.GetByTimePeriod(It.IsAny <int>(), It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns((IList <DotNetMetric>)returnList); var agentId = 1; var fromTime = DateTimeOffset.Now - new TimeSpan(0, 0, 100); var toTime = DateTimeOffset.Now; var result = (OkObjectResult)_controller.GetMetricsFromAgent(agentId, fromTime, toTime); var actualResult = (List <DotNetMetric>)result.Value; _repositoryMock.Verify(repository => repository.GetByTimePeriod(It.IsAny <int>(), It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())); _ = Assert.IsAssignableFrom <IActionResult>(result); Assert.Equal(returnList[0].Id, actualResult[0].Id); }
public void GetMetricsFromAgent_ReturnOk() { var result = _controller.GetMetricsFromAgent(_agentId, _fromTime, _toTime); Assert.IsAssignableFrom <IActionResult>(result); }