コード例 #1
0
        public async Task WhenFSSClientReturnsOtherThan200_ThenFileShareServiceIsUnhealthy()
        {
            A.CallTo(() => fakeAuthFssTokenProvider.GetManagedIdentityAuthAsync(A <string> .Ignored)).Returns(GetFakeToken());
            A.CallTo(() => fakeFileShareServiceClient.CallFileShareServiceApi(A <HttpMethod> .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored, A <CancellationToken> .Ignored, A <string> .Ignored))
            .Returns(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage()
                {
                    RequestUri = new Uri("http://test.com")
                }, Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("BadRequest")))
            });

            var response = await fileShareServiceHealthCheck.CheckHealthAsync(new HealthCheckContext());

            Assert.AreEqual(HealthStatus.Unhealthy, response.Status);
        }
コード例 #2
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            var uri         = $"/batch?limit={fileShareServiceConfig.Value.Limit}&start={fileShareServiceConfig.Value.Start}&$filter=BusinessUnit eq 'invalid'";
            var accessToken = await authFssTokenProvider.GetManagedIdentityAuthAsync(fileShareServiceConfig.Value.ResourceId);

            string payloadJson = string.Empty;
            var    fileShareServiceResponse = await fileShareServiceClient.CallFileShareServiceApi(HttpMethod.Get, payloadJson, accessToken, uri, CancellationToken.None);

            if (fileShareServiceResponse.StatusCode == HttpStatusCode.OK)
            {
                logger.LogDebug(EventIds.FileShareServiceIsHealthy.ToEventId(), "File share service is healthy responded with {StatusCode}", fileShareServiceResponse.StatusCode);
                return(HealthCheckResult.Healthy("File share service is healthy"));
            }
            else
            {
                logger.LogError(EventIds.FileShareServiceIsUnhealthy.ToEventId(), "File share service is unhealthy responded with {StatusCode} for request uri {RequestUri}", fileShareServiceResponse.StatusCode, fileShareServiceResponse.RequestMessage.RequestUri);
                return(HealthCheckResult.Unhealthy("File share service is unhealthy"));
            }
        }