Restructure solution layout by module
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using StellaOps.Notify.Engine;
|
||||
using StellaOps.Notify.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Notify.Connectors.Email.Tests;
|
||||
|
||||
public sealed class EmailChannelHealthProviderTests
|
||||
{
|
||||
private static readonly EmailChannelHealthProvider Provider = new();
|
||||
|
||||
[Fact]
|
||||
public async Task CheckAsync_ReturnsHealthy()
|
||||
{
|
||||
var channel = CreateChannel(enabled: true, target: "ops@example.com");
|
||||
|
||||
var context = new ChannelHealthContext(
|
||||
channel.TenantId,
|
||||
channel,
|
||||
channel.Config.Target!,
|
||||
new DateTimeOffset(2025, 10, 20, 15, 0, 0, TimeSpan.Zero),
|
||||
"trace-email-001");
|
||||
|
||||
var result = await Provider.CheckAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.Equal(ChannelHealthStatus.Healthy, result.Status);
|
||||
Assert.Equal("true", result.Metadata["email.channel.enabled"]);
|
||||
Assert.Equal("true", result.Metadata["email.validation.targetPresent"]);
|
||||
Assert.Equal("ops@example.com", result.Metadata["email.target"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CheckAsync_ReturnsDegradedWhenDisabled()
|
||||
{
|
||||
var channel = CreateChannel(enabled: false, target: "ops@example.com");
|
||||
|
||||
var context = new ChannelHealthContext(
|
||||
channel.TenantId,
|
||||
channel,
|
||||
channel.Config.Target!,
|
||||
DateTimeOffset.UtcNow,
|
||||
"trace-email-002");
|
||||
|
||||
var result = await Provider.CheckAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.Equal(ChannelHealthStatus.Degraded, result.Status);
|
||||
Assert.Equal("false", result.Metadata["email.channel.enabled"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CheckAsync_ReturnsUnhealthyWhenTargetMissing()
|
||||
{
|
||||
var channel = NotifyChannel.Create(
|
||||
channelId: "channel-email-ops",
|
||||
tenantId: "tenant-sec",
|
||||
name: "email:ops",
|
||||
type: NotifyChannelType.Email,
|
||||
config: NotifyChannelConfig.Create(
|
||||
secretRef: "ref://notify/channels/email/ops",
|
||||
target: null,
|
||||
properties: new Dictionary<string, string>
|
||||
{
|
||||
["smtpHost"] = "smtp.ops.example.com"
|
||||
}),
|
||||
enabled: true);
|
||||
|
||||
var context = new ChannelHealthContext(
|
||||
channel.TenantId,
|
||||
channel,
|
||||
channel.Name,
|
||||
DateTimeOffset.UtcNow,
|
||||
"trace-email-003");
|
||||
|
||||
var result = await Provider.CheckAsync(context, CancellationToken.None);
|
||||
|
||||
Assert.Equal(ChannelHealthStatus.Unhealthy, result.Status);
|
||||
Assert.Equal("false", result.Metadata["email.validation.targetPresent"]);
|
||||
}
|
||||
|
||||
private static NotifyChannel CreateChannel(bool enabled, string? target)
|
||||
{
|
||||
return NotifyChannel.Create(
|
||||
channelId: "channel-email-ops",
|
||||
tenantId: "tenant-sec",
|
||||
name: "email:ops",
|
||||
type: NotifyChannelType.Email,
|
||||
config: NotifyChannelConfig.Create(
|
||||
secretRef: "ref://notify/channels/email/ops",
|
||||
target: target,
|
||||
properties: new Dictionary<string, string>
|
||||
{
|
||||
["smtpHost"] = "smtp.ops.example.com",
|
||||
["password"] = "super-secret"
|
||||
}),
|
||||
enabled: enabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseConcelierTestInfra>false</UseConcelierTestInfra>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../__Libraries/StellaOps.Notify.Connectors.Email/StellaOps.Notify.Connectors.Email.csproj" />
|
||||
<ProjectReference Include="../../__Libraries/StellaOps.Notify.Engine/StellaOps.Notify.Engine.csproj" />
|
||||
<ProjectReference Include="../../__Libraries/StellaOps.Notify.Models/StellaOps.Notify.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user