Files
AI-Studio/app/Tests/Tools/Mail/MailboxProviderTemplatesTests.cs
T
Thorsten Sommer c4400c0ff6
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Added mailboxes as local data sources (#1022)
2026-10-04 12:26:26 +02:00

75 lines
3.4 KiB
C#

using AIStudio.Settings.DataModel;
using AIStudio.Tools.Mail;
namespace AIStudio.Tests.Tools.Mail;
/// <summary>
/// Checks that every provider template would make a mailbox the connector accepts.
/// </summary>
/// <remarks>
/// The table is typed in by hand. A host with a stray scheme or a port out of range would only
/// show itself once somebody picks that provider, and then as a failed connection the user cannot
/// explain.
/// </remarks>
[TestFixture]
public sealed class MailboxProviderTemplatesTests
{
private static IEnumerable<TestCaseData> Templates() => MailboxProviderTemplates.ALL.Select(template => new TestCaseData(template).SetArgDisplayNames(template.Name));
[TestCaseSource(nameof(Templates))]
public void ATemplateMakesAValidConnection(MailboxProviderTemplate template)
{
Assert.Multiple(() =>
{
Assert.That(template.Port, Is.InRange(1, 65535), "The port is out of range.");
Assert.That(template.TransportSecurity, Is.Not.EqualTo(MailboxTransportSecurity.UNKNOWN), "The template does not say how the connection is encrypted.");
Assert.That(Uri.TryCreate(template.HelpUrl, UriKind.Absolute, out var helpUrl) && helpUrl.Scheme == Uri.UriSchemeHttps, Is.True, "The help page is no HTTPS address.");
});
}
[TestCaseSource(nameof(Templates))]
public void ATemplateNamesAHostUnlessEveryOrganizationRunsItsOwn(MailboxProviderTemplate template)
{
if (template.Requirements.HasFlag(MailboxProviderRequirements.ADMIN_ACTIVATION))
Assert.That(template.Host, Is.Empty, "A server every organization runs itself has no host to fill in.");
else
Assert.That(Uri.CheckHostName(template.Host), Is.EqualTo(UriHostNameType.Dns), "The host is no DNS name.");
}
[Test]
public void EveryProviderIsListedOnce()
{
Assert.Multiple(() =>
{
Assert.That(MailboxProviderTemplates.ALL.Select(template => template.Name), Is.Unique);
Assert.That(MailboxProviderTemplates.ALL.Where(template => template.Host.Length > 0).Select(template => template.Host), Is.Unique);
});
}
[Test]
public void EveryRequirementHasItsOwnDescription()
{
var requirements = Enum.GetValues<MailboxProviderRequirements>().Where(requirement => requirement is not MailboxProviderRequirements.NONE).ToList();
var descriptions = requirements.Select(requirement => requirement.GetDescriptions().ToList()).ToList();
Assert.Multiple(() =>
{
Assert.That(MailboxProviderRequirements.NONE.GetDescriptions(), Is.Empty, "A provider without requirements got a description.");
Assert.That(descriptions, Has.All.Count.EqualTo(1), "A requirement does not have exactly one description.");
Assert.That(descriptions.Select(texts => texts.FirstOrDefault()), Is.Unique, "Two requirements share a description.");
});
}
[Test]
public void EveryUsernameFormatHasItsOwnDescription()
{
var descriptions = Enum.GetValues<MailboxUsernameFormat>().Select(format => format.GetDescription()).ToList();
var fallback = ((MailboxUsernameFormat)int.MaxValue).GetDescription();
Assert.Multiple(() =>
{
Assert.That(descriptions, Is.Unique, "Two username formats share a description.");
Assert.That(descriptions, Has.None.EqualTo(fallback), "A username format falls back to the description of an unknown one.");
});
}
}