Added a NUnit test project for the whole solution

This commit is contained in:
Thorsten Sommer committed 2026-09-11 16:37:09 +02:00
1 parent d21e09dd1e
commit de775048f0
6 files changed
+135 -1

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
using AIStudio.Provider;
using AIStudio.Settings;
namespace AIStudio.Tests.Models;
/// <summary>
/// Checks the test harness itself, before any test states something about the app.
/// </summary>
/// <remarks>
/// Three things have to hold before a capability test can mean anything: the app assembly is
/// referenced, this project counts as a friend assembly, and the assembly-wide setup has run. When
/// one of them is missing, the failure looks like a broken rule rather than a broken harness, which
/// is an expensive detour. These two tests make the difference visible right away.
///
/// Note the fully written type name below. AIStudio.Provider is a namespace and AIStudio.Settings
/// .Provider is a type; inside a namespace under AIStudio, the namespace wins the lookup. That is a
/// property of the app's own naming, not of the tests.
/// </remarks>
[TestFixture]
public sealed class TestHarnessTests
{
[Test]
public void TheStaticApplicationStateIsAvailable()
{
//
// Settings.Provider initializes a static logger from Program.LOGGER_FACTORY. Touching it
// without the assembly-wide setup throws a TypeInitializationException.
//
Assert.That(AIStudio.Settings.Provider.NONE.UsedLLMProvider, Is.EqualTo(LLMProviders.NONE));
}
[Test]
public void TheCapabilityApiOfTheAppIsReachable()
{
var capabilities = LLMProviders.OPEN_AI.GetModelCapabilities(new Model("gpt-5.1", null));
Assert.That(capabilities, Does.Contain(Capability.FUNCTION_CALLING));
}
}
+26
View File
@@ -0,0 +1,26 @@
using Microsoft.Extensions.Logging.Abstractions;
//
// Deliberately without a namespace: NUnit then applies this fixture to the whole assembly, so every
// test -- the ones written today and the ones written later in some other folder -- starts with the
// static state below already in place. A second setup fixture would only ever be needed for state
// that must not leak between areas.
//
namespace AIStudio.Tests;
[SetUpFixture]
public sealed class TestHost
{
[OneTimeSetUp]
public void PrepareStaticApplicationState()
{
//
// A number of types in the app hold a static logger field that is initialized from
// Program.LOGGER_FACTORY, among them Settings.Provider. The app assigns that factory while
// Kestrel comes up; in a test process nobody does, so it stays null and the first touch of
// such a type dies inside its type initializer -- before a single assertion runs. A factory
// that writes nowhere is all it takes to get past that.
//
Program.LOGGER_FACTORY = NullLoggerFactory.Instance;
}
}
+40
View File
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>AIStudio.Tests</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<!--
Pinned below 4.6.0 on purpose, verified by bisecting 4.4.0, 4.5.0, 4.5.1, 4.6.0 and 4.6.1
against the .NET 9 SDK (9.0.120, C# 13): from 4.6.0 on, the compiler no longer picks
Assert.That<TActual>(TActual, IResolveConstraint, ...) for a plain value. 4.6.0 added
Assert.That(Action, ...) and Assert.That<T>(Func<T>, ...) alongside it, and the value
overload drops out of the candidate set, so even Assert.That(1, Is.EqualTo(1)) fails with
"argument 1: cannot convert int to System.Action", a message that points nowhere near the
real cause. Re-test the newest version whenever the .NET SDK is raised.
-->
<PackageReference Include="NUnit" Version="4.5.1" />
<PackageReference Include="NUnit.Analyzers" Version="4.14.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MindWork AI Studio\MindWork AI Studio.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>