Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
dotnet restore Dashboard/Dashboard.csproj --locked-mode
dotnet restore Lite/PerformanceMonitorLite.csproj --locked-mode
dotnet restore Installer/PerformanceMonitorInstaller.csproj --locked-mode
dotnet restore Dashboard.Tests/Dashboard.Tests.csproj --locked-mode
dotnet restore Lite.Tests/Lite.Tests.csproj --locked-mode
dotnet restore Installer.Tests/Installer.Tests.csproj --locked-mode

Expand All @@ -77,6 +78,10 @@ jobs:
if: steps.filter.outputs.code != 'false'
run: dotnet build Installer.Tests/Installer.Tests.csproj -c Release --no-restore

- name: Build Dashboard.Tests
if: steps.filter.outputs.code != 'false'
run: dotnet build Dashboard.Tests/Dashboard.Tests.csproj -c Release --no-restore

- name: Run Lite fast tests
if: steps.filter.outputs.code != 'false'
run: dotnet test Lite.Tests/Lite.Tests.csproj -c Release --no-build --verbosity normal --filter "FullyQualifiedName!~AnomalyDetectorTests&FullyQualifiedName!~FactCollectorTests&FullyQualifiedName!~FactCollectorMiseryTests&FullyQualifiedName!~BaselineProviderTests&FullyQualifiedName!~InferenceEngineTests&FullyQualifiedName!~ScenarioTests&FullyQualifiedName!~AnalysisServiceTests"
Expand All @@ -89,6 +94,10 @@ jobs:
if: steps.filter.outputs.installer == 'true' || github.event_name == 'release'
run: dotnet test Installer.Tests/Installer.Tests.csproj -c Release --no-build --verbosity normal --filter "FullyQualifiedName!~VersionDetectionTests&FullyQualifiedName!~IdempotencyTests&FullyQualifiedName!~AdversarialTests"

- name: Run Dashboard tests
if: steps.filter.outputs.code != 'false'
run: dotnet test Dashboard.Tests/Dashboard.Tests.csproj -c Release --no-build --verbosity normal

- name: Get version
if: steps.filter.outputs.code != 'false'
id: version
Expand Down
25 changes: 25 additions & 0 deletions Dashboard.Tests/Dashboard.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0-windows7.0</TargetFramework>
<IsTestProject>true</IsTestProject>
<Nullable>enable</Nullable>
<UseWPF>false</UseWPF>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="3.2.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Dashboard\Dashboard.csproj" />
</ItemGroup>

</Project>
54 changes: 54 additions & 0 deletions Dashboard.Tests/UpgradeAggregationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using PerformanceMonitorDashboard;
using Xunit;

namespace Dashboard.Tests
{
public class UpgradeAggregationTests
{
[Fact]
public void AggregatesServerAndStepCounts_Correctly()
{
// Arrange: three servers, two successes, one failure
var inputs = new[]
{
// success: 2 upgrade steps succeeded, 1 step succeeded
new AggregationInput(true, 2, 0, 1, 0),
// failure: 0 succeeded, 1 upgrade failed
new AggregationInput(false, 0, 1, 0, 0),
// success: 1 upgrade succeeded
new AggregationInput(true, 1, 0, 0, 0)
};

// Act
var result = UpgradeAggregator.Aggregate(inputs);

// Assert
Assert.Equal(2, result.ServerSuccessCount);
Assert.Equal(1, result.ServerFailCount);

// Steps succeeded: (2+1) + (0) + (1) = 4
Assert.Equal(4, result.StepsSucceeded);
// Steps failed: 1
Assert.Equal(1, result.StepsFailed);

// Summary contains expected fragments
Assert.Contains("2 servers upgraded", result.Summary);
Assert.Contains("4 steps succeeded", result.Summary);
Assert.Contains("1 step failed", result.Summary);
}

[Fact]
public void Aggregator_FormatsSingularPlural_Correctly()
{
var singleSuccess = new[] { new AggregationInput(true, 1, 0, 0, 0) };
var r1 = UpgradeAggregator.Aggregate(singleSuccess);
Assert.Equal(1, r1.ServerSuccessCount);
Assert.Contains("1 server upgraded", r1.Summary);

var singleFail = new[] { new AggregationInput(false, 0, 0, 0, 1) };
var r2 = UpgradeAggregator.Aggregate(singleFail);
Assert.Equal(1, r2.ServerFailCount);
Assert.Contains("1 step failed", r2.Summary);
}
}
}
Loading