Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ jobs:
- name: Build
run: dotnet build MSStore.CLI.sln --no-restore /p:Configuration=Release
- name: Test net10.0
env:
MSSTORE_RUN_PROCESS_TESTS: 'true'
run: dotnet run --project MSStore.CLI.UnitTests -f net10.0 --no-build -c Release --coverage --coverage-output-format cobertura --report-trx --results-directory ./TestResults
- name: Test net10.0-windows10.0.17763.0
if: ${{ matrix.os == 'windows-latest' }}
env:
MSSTORE_RUN_PROCESS_TESTS: 'true'
run: dotnet run --project MSStore.CLI.UnitTests -f net10.0-windows10.0.17763.0 --no-build -c Release --coverage --coverage-output-format cobertura --report-trx --results-directory ./TestResults
- name: Publish test results
if: ${{ !cancelled() }}
Expand Down
2 changes: 2 additions & 0 deletions .pipelines/templates/build-and-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ steps:
displayName: 'Tests net10.0'
env:
DISPLAY: :0.0
MSSTORE_RUN_PROCESS_TESTS: 'true'
inputs:
command: 'run'
projects: '**/*[Tt]est*/*.csproj'
Expand All @@ -48,6 +49,7 @@ steps:
condition: startsWith(variables.AgentOS, 'Windows_NT')
env:
DISPLAY: :0.0
MSSTORE_RUN_PROCESS_TESTS: 'true'
inputs:
command: 'run'
projects: '**/*[Tt]est*/*.csproj'
Expand Down
4 changes: 2 additions & 2 deletions MSStore.CLI.UnitTests/AppsCommandUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public async Task AppsListCommandShouldReturnZero()
"list"
]);

result.Output.Should().ContainAll(FakeApps.Select(a => a.Id));
result.Output.Should().ContainAll(FakeApps.Select(a => a.PrimaryName));
result.Error.Should().ContainAll(FakeApps.Select(a => a.Id));
result.Error.Should().ContainAll(FakeApps.Select(a => a.PrimaryName));
}

[TestMethod]
Expand Down
7 changes: 4 additions & 3 deletions MSStore.CLI.UnitTests/BaseCommandLineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,16 +802,17 @@ protected void SetupBasedOnTestDataProjectSubPath(DirectoryInfo dirInfo, string[
var outputCapture = new OutputCapture(Console.Out);
var errorCapture = RefreshAnsiConsole();

// Only stdout is redirected: the error capture is reached exclusively through
// ErrorAnsiConsole, mirroring how Program.cs keeps the two streams apart.
// Only stdout is redirected: it is reserved for StandardOutput payloads. Human-readable writes
// reach the error capture through either ErrorAnsiConsole or the static console, mirroring how
// Program.cs points both at the same instance.
Console.SetOut(outputCapture);

AnsiConsole.Console = AnsiConsole.Create(new AnsiConsoleSettings
{
Ansi = AnsiSupport.Yes,
ColorSystem = ColorSystemSupport.TrueColor,
Interactive = InteractionSupport.No,
Out = new CustomAnsiConsoleOutput(outputCapture),
Out = new CustomAnsiConsoleOutput(errorCapture),
Enrichment = new ProfileEnrichment
{
UseDefaultEnrichers = false
Expand Down
104 changes: 104 additions & 0 deletions MSStore.CLI.UnitTests/ConsoleFactoryUnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using MSStore.CLI.Helpers;
using Spectre.Console;

namespace MSStore.CLI.UnitTests
{
/// <summary>
/// Covers the console that <see cref="Program"/> builds, including the static
/// <see cref="AnsiConsole.Console"/> assignment that the ConsoleReader prompts and the browser launcher
/// confirmation depend on.
/// </summary>
[TestClass]
public class ConsoleFactoryUnitTests
{
private const string Marker = "console-factory-marker";

private IAnsiConsole _previousConsole = null!;
private TextWriter _previousOut = null!;
private TextWriter _previousError = null!;
private StringWriter _stdOut = null!;
private StringWriter _stdError = null!;

[TestInitialize]
public void Initialize()
{
_previousConsole = AnsiConsole.Console;
_previousOut = Console.Out;
_previousError = Console.Error;

// ConsoleFactory captures Console.Out/Console.Error when it builds the AnsiConsoleOutput, so the
// redirection has to be in place first.
_stdOut = new StringWriter();
_stdError = new StringWriter();
Console.SetOut(_stdOut);
Console.SetError(_stdError);
}

[TestCleanup]
public void Cleanup()
{
Console.SetOut(_previousOut);
Console.SetError(_previousError);
AnsiConsole.Console = _previousConsole;
_stdOut.Dispose();
_stdError.Dispose();
}

[TestMethod]
public void CreateAndInstallWritesToStandardErrorForStderr()
{
var console = ConsoleFactory.CreateAndInstall(OutputStream.Stderr);

console.WriteLine(Marker);

_stdError.ToString().Should().Contain(Marker);
_stdOut.ToString().Should().NotContain(Marker);
}

[TestMethod]
public void CreateAndInstallWritesToStandardOutputForStdout()
{
var console = ConsoleFactory.CreateAndInstall(OutputStream.Stdout);

console.WriteLine(Marker);

_stdOut.ToString().Should().Contain(Marker);
_stdError.ToString().Should().NotContain(Marker);
}

[TestMethod]
public void CreateAndInstallInstallsTheConsoleAsTheStaticConsole()
{
var console = ConsoleFactory.CreateAndInstall(OutputStream.Stderr);

AnsiConsole.Console.Should().BeSameAs(console);
}

[TestMethod]
public void StaticWritesFollowStderr()
{
// The ConsoleReader prompts and the BrowserLauncher confirmation write through the static
// console, so it has to honour the selected stream too.
ConsoleFactory.CreateAndInstall(OutputStream.Stderr);

AnsiConsole.WriteLine(Marker);

_stdError.ToString().Should().Contain(Marker);
_stdOut.ToString().Should().NotContain(Marker);
}

[TestMethod]
public void StaticWritesFollowStdout()
{
ConsoleFactory.CreateAndInstall(OutputStream.Stdout);

AnsiConsole.WriteLine(Marker);

_stdOut.ToString().Should().Contain(Marker);
_stdError.ToString().Should().NotContain(Marker);
}
}
}
4 changes: 2 additions & 2 deletions MSStore.CLI.UnitTests/EmptyCommandUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task InfoCommandShouldReturnZero()

var result = await ParseAndInvokeAsync(["info"]);

result.Output.Should().Contain("Current Config");
result.Error.Should().Contain("Current Config");
}

[TestMethod]
Expand All @@ -57,7 +57,7 @@ public async Task InfoCommandShouldReturnZeroWithCert()

var result = await ParseAndInvokeAsync(["info"]);

result.Output.Should().Contain("Current Config");
result.Error.Should().Contain("Current Config");
}
}
}
4 changes: 2 additions & 2 deletions MSStore.CLI.UnitTests/FlightsCommandUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public async Task FlightsListCommandShouldReturnZero()
FakeApps[0].Id!
]);

result.Output.Should().ContainAll(FakeFlights.Select(a => a.FlightId));
result.Output.Should().ContainAll(FakeFlights.Select(a => a.FriendlyName));
result.Error.Should().ContainAll(FakeFlights.Select(a => a.FlightId));
result.Error.Should().ContainAll(FakeFlights.Select(a => a.FriendlyName));
}

[TestMethod]
Expand Down
Loading