This repository was archived by the owner on Dec 19, 2025. It is now read-only.
forked from Ed-Fi-Alliance-OSS/ODS-Admin-API
-
Notifications
You must be signed in to change notification settings - Fork 13
[ADMINAPI-1292] Add Health Check for Security and Admin Databases #370
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f0b1cc
Enhance health check functionality with multi-tenancy support and cus…
jagudelo-gap b18c47a
Add unit tests for health check registration with multi-tenancy support
jagudelo-gap eb45018
Fix the Copilot comments
jagudelo-gap 758d6f6
Add the tag Databases to the health checker and return a similar resp…
jagudelo-gap f8efb9d
Add the response to the health service
jagudelo-gap 254a221
Merge branch 'main' into ADMINAPI-1292
jagudelo-gap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
Application/EdFi.Ods.AdminApi.UnitTests/Infrastructure/HealthCheckServiceExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Licensed to the Ed-Fi Alliance under one or more agreements. | ||
| // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
| // See the LICENSE and NOTICES files in the project root for more information. | ||
|
|
||
| using EdFi.Ods.AdminApi.Infrastructure; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.Logging; | ||
| using NUnit.Framework; | ||
| using Shouldly; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace EdFi.Ods.AdminApi.UnitTests.Infrastructure; | ||
|
|
||
| [TestFixture] | ||
| public class HealthCheckServiceExtensionsTests | ||
| { | ||
| [Test] | ||
| public void AddHealthCheck_ShouldRegisterBothAdminAndSecurityHealthChecks_WhenMultiTenancyDisabled() | ||
| { | ||
| // Arrange | ||
| var services = new ServiceCollection(); | ||
| services.AddLogging(); // Required for health checks | ||
| var configuration = CreateTestConfiguration(multiTenancy: false); | ||
|
|
||
| // Act | ||
| services.AddHealthCheck(configuration); | ||
|
|
||
| // Assert - Check that health check services are registered | ||
| var healthCheckServiceDescriptor = services.FirstOrDefault(s => s.ServiceType == typeof(HealthCheckService)); | ||
| healthCheckServiceDescriptor.ShouldNotBeNull(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AddHealthCheck_ShouldRegisterMultiTenantHealthChecks_WhenMultiTenancyEnabled() | ||
| { | ||
| // Arrange | ||
| var services = new ServiceCollection(); | ||
| services.AddLogging(); // Required for health checks | ||
| var configuration = CreateTestConfiguration(multiTenancy: true); | ||
|
|
||
| // Act | ||
| services.AddHealthCheck(configuration); | ||
|
|
||
| // Assert - Check that health check services are registered | ||
| var healthCheckServiceDescriptor = services.FirstOrDefault(s => s.ServiceType == typeof(HealthCheckService)); | ||
| healthCheckServiceDescriptor.ShouldNotBeNull(); | ||
| } | ||
|
|
||
| private static IConfigurationRoot CreateTestConfiguration(bool multiTenancy) | ||
| { | ||
| var configData = new Dictionary<string, string> | ||
| { | ||
| ["AppSettings:DatabaseEngine"] = "SqlServer", | ||
| ["AppSettings:MultiTenancy"] = multiTenancy.ToString(), | ||
| ["ConnectionStrings:EdFi_Admin"] = "Data Source=test;Initial Catalog=EdFi_Admin_Test;Integrated Security=True", | ||
| ["ConnectionStrings:EdFi_Security"] = "Data Source=test;Initial Catalog=EdFi_Security_Test;Integrated Security=True" | ||
| }; | ||
|
|
||
| if (multiTenancy) | ||
| { | ||
| configData["Tenants:tenant1:ConnectionStrings:EdFi_Admin"] = "Data Source=test;Initial Catalog=EdFi_Admin_Tenant1;Integrated Security=True"; | ||
| configData["Tenants:tenant1:ConnectionStrings:EdFi_Security"] = "Data Source=test;Initial Catalog=EdFi_Security_Tenant1;Integrated Security=True"; | ||
| configData["Tenants:tenant2:ConnectionStrings:EdFi_Admin"] = "Data Source=test;Initial Catalog=EdFi_Admin_Tenant2;Integrated Security=True"; | ||
| configData["Tenants:tenant2:ConnectionStrings:EdFi_Security"] = "Data Source=test;Initial Catalog=EdFi_Security_Tenant2;Integrated Security=True"; | ||
| } | ||
|
|
||
| return new ConfigurationBuilder() | ||
| .AddInMemoryCollection(configData) | ||
| .Build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.