public void PostEndpointsHealth_should_update_endpoints_health() { AuthorizeRequest(SecurityRole.Monitor); var update1 = new EndpointHealthUpdate { EndpointId = Guid.NewGuid(), CheckTimeUtc = _utcNow, Status = EndpointStatus.Offline, ResponseTime = TimeSpan.FromSeconds(5), Details = new Dictionary<string, string> { { "a", "b" } } }; var update2 = new EndpointHealthUpdate { EndpointId = Guid.NewGuid(), CheckTimeUtc = _utcNow, Status = EndpointStatus.Healthy, ResponseTime = TimeSpan.FromSeconds(5), Details = new Dictionary<string, string> { { "a", "b" } } }; Assert.IsType<OkResult>(_controller.PostEndpointsHealth(null, update1, update2)); _endpointRegistry.Verify(r => r.UpdateHealth(update1.EndpointId, It.Is<EndpointHealth>(h => AssertHealth(h, update1)))); _endpointRegistry.Verify(r => r.UpdateHealth(update2.EndpointId, It.Is<EndpointHealth>(h => AssertHealth(h, update2)))); }
public void PostEndpointsHealth_should_not_update_health_if_admin_credentials_provided() { var endpointId = Guid.NewGuid(); var hasBeenCalled = false; AuthorizeRequest(SecurityRole.Admin); _endpointRegistry.Setup(m => m.UpdateHealth(It.IsAny<Guid>(), It.IsAny<EndpointHealth>())).Callback(() => { hasBeenCalled = true; }); var update = new EndpointHealthUpdate { EndpointId = endpointId, CheckTimeUtc = DateTime.UtcNow, Status = EndpointStatus.Healthy, ResponseTime = TimeSpan.FromSeconds(5), Details = new Dictionary<string, string> { { "a", "b" } } }; Assert.Throws<UnauthorizedAccessException>(() => _controller.PostEndpointsHealth(null, update)); Assert.False(hasBeenCalled); }
public void PostEndpointsHealth_should_update_endpoints_health_and_adjust_check_time_with_clientServer_time_difference() { var update1 = new EndpointHealthUpdate { EndpointId = Guid.NewGuid(), CheckTimeUtc = _utcNow, Status = EndpointStatus.Offline, ResponseTime = TimeSpan.FromSeconds(5), Details = new Dictionary<string, string> { { "a", "b" } } }; var update2 = new EndpointHealthUpdate { EndpointId = Guid.NewGuid(), CheckTimeUtc = _utcNow, Status = EndpointStatus.Healthy, ResponseTime = TimeSpan.FromSeconds(5), Details = new Dictionary<string, string> { { "a", "b" } } }; var timeDifference = TimeSpan.FromMinutes(5); var updates = new[] { update1, update2 }; var expected = updates .Select(u => new EndpointHealthUpdate { CheckTimeUtc = u.CheckTimeUtc - timeDifference, Details = u.Details, EndpointId = u.EndpointId, ResponseTime = u.ResponseTime, Status = u.Status }) .ToArray(); AuthorizeRequest(SecurityRole.Monitor); Assert.IsType<OkResult>(_controller.PostEndpointsHealth(_utcNow + timeDifference, update1, update2)); foreach (var expectedEndpoint in expected) _endpointRegistry.Verify(r => r.UpdateHealth(expectedEndpoint.EndpointId, It.Is<EndpointHealth>(h => AssertHealth(h, expectedEndpoint)))); }