chore: add hrynco common library solution
- add the standalone HrynCo.Common solution and projects - include the shared common library source and tests - add package metadata and a repo gitignore
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
namespace HrynCo.Common.Tests;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using HrynCo.Common.HealthChecks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Xunit;
|
||||
|
||||
public sealed class BaseConfigurationCheckTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CheckConfigurationAsync_ShouldReturnHealthyWhenOptionsAreValid()
|
||||
{
|
||||
var check = new FakeConfigurationCheck(new SampleOptions
|
||||
{
|
||||
Code = "ok"
|
||||
}, "Sample");
|
||||
|
||||
HealthCheckResult result = await check.CheckConfigurationAsync(default);
|
||||
|
||||
result.Status.Should().Be(HealthStatus.Healthy);
|
||||
result.Description.Should().Be("Sample configuration is valid.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CheckConfigurationAsync_ShouldReturnUnhealthyWhenOptionsAreInvalid()
|
||||
{
|
||||
var check = new FakeConfigurationCheck(new SampleOptions(), "Sample");
|
||||
|
||||
HealthCheckResult result = await check.CheckConfigurationAsync(default);
|
||||
|
||||
result.Status.Should().Be(HealthStatus.Unhealthy);
|
||||
result.Description.Should().Contain("Sample configuration invalid:");
|
||||
result.Description.Should().Contain("The Code field is required.");
|
||||
}
|
||||
|
||||
private sealed class FakeConfigurationCheck : BaseConfigurationCheck<SampleOptions>
|
||||
{
|
||||
public FakeConfigurationCheck(SampleOptions options, string name)
|
||||
: base(options, name)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class SampleOptions
|
||||
{
|
||||
[Required]
|
||||
public string? Code { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user