Skip to content
Merged
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
43 changes: 17 additions & 26 deletions test/Serilog.Settings.Configuration.Tests/PublishSingleFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,90 @@
using System.Text;
using CliWrap;
using CliWrap.Exceptions;
using FluentAssertions;
using FluentAssertions.Execution;
using Serilog.Settings.Configuration.Tests.Support;
using Xunit.Abstractions;

namespace Serilog.Settings.Configuration.Tests;

[Trait("Category", "Integration")]
public sealed class PublishSingleFileTests : IDisposable, IClassFixture<TestApp>
public sealed class PublishSingleFileTests : IClassFixture<TestApp>
{
readonly ITestOutputHelper _outputHelper;
readonly TestApp _testApp;
readonly AssertionScope _scope;

public PublishSingleFileTests(ITestOutputHelper outputHelper, TestApp testApp)
{
_outputHelper = outputHelper;
_testApp = testApp;
_scope = new AssertionScope();
}

public void Dispose()
{
_scope.Dispose();
}

[Theory]
[ClassData(typeof(PublishModeTheoryData))]
public async Task RunTestApp_NoUsingAndNoAssembly(PublishMode publishMode)
{
var (isSingleFile, stdOut, stdErr) = await RunTestAppAsync(publishMode);
stdOut.Should().Be(isSingleFile ? "Expected exception" : "(Main thread) [Information] Expected success");
stdErr.Should().BeEmpty();
Assert.Equal(stdOut, isSingleFile ? "Expected exception" : "(Main thread) [Information] Expected success");
Assert.Empty(stdErr);
}

[Theory]
[ClassData(typeof(PublishModeTheoryData))]
public async Task RunTestApp_UsingConsole(PublishMode publishMode)
{
var (isSingleFile, stdOut, stdErr) = await RunTestAppAsync(publishMode, "--using-console");
stdOut.Should().Be(isSingleFile ? "() [Information] Expected success" : "(Main thread) [Information] Expected success");
Assert.Equal(stdOut, isSingleFile ? "() [Information] Expected success" : "(Main thread) [Information] Expected success");
if (isSingleFile)
stdErr.Should().Contain("Unable to find a method called WithThreadName");
Assert.Contains("Unable to find a method called WithThreadName", stdErr);
else
stdErr.Should().BeEmpty();
Assert.Empty(stdErr);
}

[Theory]
[ClassData(typeof(PublishModeTheoryData))]
public async Task RunTestApp_UsingThread(PublishMode publishMode)
{
var (isSingleFile, stdOut, stdErr) = await RunTestAppAsync(publishMode, "--using-thread");
stdOut.Should().Be(isSingleFile ? "" : "(Main thread) [Information] Expected success");
Assert.Equal(stdOut, isSingleFile ? "" : "(Main thread) [Information] Expected success");
if (isSingleFile)
stdErr.Should().Contain("Unable to find a method called Console");
Assert.Contains("Unable to find a method called Console", stdErr);
else
stdErr.Should().BeEmpty();
Assert.Empty(stdErr);
}

[Theory]
[ClassData(typeof(PublishModeTheoryData))]
public async Task RunTestApp_AssemblyThread(PublishMode publishMode)
{
var (_, stdOut, stdErr) = await RunTestAppAsync(publishMode, "--assembly-thread");
stdOut.Should().BeEmpty();
stdErr.Should().Contain("Unable to find a method called Console");
Assert.Empty(stdOut);
Assert.Contains("Unable to find a method called Console", stdErr);
}

[Theory]
[ClassData(typeof(PublishModeTheoryData))]
public async Task RunTestApp_AssemblyConsole(PublishMode publishMode)
{
var (_, stdOut, stdErr) = await RunTestAppAsync(publishMode, "--assembly-console");
stdOut.Should().Be("() [Information] Expected success");
stdErr.Should().Contain("Unable to find a method called WithThreadName");
Assert.Equal("() [Information] Expected success", stdOut);
Assert.Contains("Unable to find a method called WithThreadName", stdErr);
}

[Theory]
[ClassData(typeof(PublishModeAndStrategyTheoryData))]
public async Task RunTestApp_ConsoleAndThread(PublishMode publishMode, string strategy)
{
var (_, stdOut, stdErr) = await RunTestAppAsync(publishMode, $"--{strategy}-console", $"--{strategy}-thread");
stdOut.Should().Be("(Main thread) [Information] Expected success");
stdErr.Should().BeEmpty();
Assert.Equal("(Main thread) [Information] Expected success", stdOut);
Assert.Empty(stdErr);
}

[Theory]
[ClassData(typeof(PublishModeTheoryData))]
public async Task RunTestApp_ConfigureMinimumLevelOnly(PublishMode publishMode)
{
var (_, stdOut, stdErr) = await RunTestAppAsync(publishMode, "--minimum-level-only");
stdOut.Should().Be("(Main thread) [Information] Expected success");
stdErr.Should().BeEmpty();
Assert.Equal("(Main thread) [Information] Expected success", stdOut);
Assert.Empty(stdErr);
}

async Task<(bool IsSingleFile, string StdOut, string StdErr)> RunTestAppAsync(PublishMode publishMode, params string[] args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.10.0" />
<PackageReference Include="FluentAssertions" Version="8.8.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NuGet.Frameworks" Version="7.0.0" />
Expand Down
11 changes: 6 additions & 5 deletions test/Serilog.Settings.Configuration.Tests/Support/TestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Text;
using CliWrap;
using CliWrap.Exceptions;
using FluentAssertions;
using Polly;
using Xunit.Abstractions;
using Xunit.Sdk;
Expand Down Expand Up @@ -108,16 +107,18 @@ async Task PublishAsync(PublishMode publishMode)

var executableFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "TestApp.exe" : "TestApp";
var executableFile = new FileInfo(Path.Combine(outputDirectory.FullName, executableFileName));
executableFile.Exists.Should().BeTrue();
Assert.True(executableFile.Exists);
var dlls = executableFile.Directory!.EnumerateFiles("*.dll");
if (publishMode == PublishMode.Standard)
{
dlls.Should().NotBeEmpty(because: $"the test app was _not_ published as single-file ({publishMode})");
// the test app was _not_ published as single-file
Assert.NotEmpty(dlls);
}
else
{
dlls.Should().BeEmpty(because: $"the test app was published as single-file ({publishMode})");
executableFile.Directory.EnumerateFiles().Should().ContainSingle().Which.FullName.Should().Be(executableFile.FullName);
// the test app was published as single-file
Assert.Empty(dlls);
Assert.Single(executableFile.Directory.EnumerateFiles(), f => f.FullName == executableFile.FullName);
}

_executables[publishMode] = executableFile;
Expand Down