From 47211323006d48bc2b5bb9d875000c46eab2aa60 Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 9 Oct 2024 22:38:33 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D0=B4=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20ITestOutputHelper=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20xUnit=20DI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Directory.Packages.props | 25 ++++++++++--------- .../VariableInitializationTests.cs | 9 +++---- .../HydraScript.IntegrationTests.csproj | 5 ++++ tests/HydraScript.IntegrationTests/Startup.cs | 7 ++++++ .../SuccessfulProgramsTests.cs | 7 ++---- .../TestHostFixture.cs | 17 +++++++++---- 6 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 tests/HydraScript.IntegrationTests/Startup.cs diff --git a/tests/Directory.Packages.props b/tests/Directory.Packages.props index cc1306b..f96787a 100644 --- a/tests/Directory.Packages.props +++ b/tests/Directory.Packages.props @@ -1,14 +1,15 @@ - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/HydraScript.IntegrationTests/ErrorPrograms/VariableInitializationTests.cs b/tests/HydraScript.IntegrationTests/ErrorPrograms/VariableInitializationTests.cs index f1bc804..848d944 100644 --- a/tests/HydraScript.IntegrationTests/ErrorPrograms/VariableInitializationTests.cs +++ b/tests/HydraScript.IntegrationTests/ErrorPrograms/VariableInitializationTests.cs @@ -1,19 +1,16 @@ using System.CommandLine.Parsing; using FluentAssertions; -using Xunit.Abstractions; namespace HydraScript.IntegrationTests.ErrorPrograms; -public class VariableInitializationTests( - TestHostFixture fixture, - ITestOutputHelper testOutputHelper) : IClassFixture +public class VariableInitializationTests(TestHostFixture fixture) : IClassFixture { [Theory, MemberData(nameof(VariableInitializationScripts))] public void VariableWithoutTypeDeclared_AccessedBeforeInitialization_ExitCodeHydraScriptError(string script) { var runner = fixture.GetRunner( - testOutputHelper, - configureTestServices: services => services.SetupInMemoryScript(script)); + configureTestServices: services => + services.SetupInMemoryScript(script)); var code = runner.Invoke(fixture.InMemoryScript); code.Should().Be(ExitCodes.HydraScriptError); fixture.LogMessages.Should() diff --git a/tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj b/tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj index 8c5cc03..28252b0 100644 --- a/tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj +++ b/tests/HydraScript.IntegrationTests/HydraScript.IntegrationTests.csproj @@ -1,5 +1,9 @@ + + CA1816 + + @@ -7,6 +11,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/HydraScript.IntegrationTests/Startup.cs b/tests/HydraScript.IntegrationTests/Startup.cs new file mode 100644 index 0000000..b2ae4aa --- /dev/null +++ b/tests/HydraScript.IntegrationTests/Startup.cs @@ -0,0 +1,7 @@ +namespace HydraScript.IntegrationTests; + +// ReSharper disable once UnusedType.Global +/// +/// https://github.com/pengweiqhca/Xunit.DependencyInjection#4-default-startup +/// +public class Startup; \ No newline at end of file diff --git a/tests/HydraScript.IntegrationTests/SuccessfulProgramsTests.cs b/tests/HydraScript.IntegrationTests/SuccessfulProgramsTests.cs index d0d80c7..b91af67 100644 --- a/tests/HydraScript.IntegrationTests/SuccessfulProgramsTests.cs +++ b/tests/HydraScript.IntegrationTests/SuccessfulProgramsTests.cs @@ -1,17 +1,14 @@ using System.CommandLine.Parsing; using FluentAssertions; -using Xunit.Abstractions; namespace HydraScript.IntegrationTests; -public class SuccessfulProgramsTests( - TestHostFixture fixture, - ITestOutputHelper testOutputHelper) : IClassFixture +public class SuccessfulProgramsTests(TestHostFixture fixture) : IClassFixture { [Theory, MemberData(nameof(SuccessfulProgramsNames))] public void Invoke_NoError_ReturnCodeIsZero(string fileName) { - var runner = fixture.GetRunner(testOutputHelper); + var runner = fixture.GetRunner(); var code = runner.Invoke([$"Samples/{fileName}"]); code.Should().Be(ExitCodes.Success); } diff --git a/tests/HydraScript.IntegrationTests/TestHostFixture.cs b/tests/HydraScript.IntegrationTests/TestHostFixture.cs index 92e8855..5255bd9 100644 --- a/tests/HydraScript.IntegrationTests/TestHostFixture.cs +++ b/tests/HydraScript.IntegrationTests/TestHostFixture.cs @@ -1,6 +1,7 @@ using System.CommandLine.Hosting; using System.CommandLine.Parsing; using HydraScript.Infrastructure; +using MartinCostello.Logging.XUnit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -8,19 +9,25 @@ namespace HydraScript.IntegrationTests; -public class TestHostFixture : IDisposable +public class TestHostFixture( + Xunit.DependencyInjection.ITestOutputHelperAccessor accessor) : + IDisposable, ITestOutputHelperAccessor { private readonly List _logMessages = []; public readonly string[] InMemoryScript = ["file.js"]; public IReadOnlyCollection LogMessages => _logMessages; - public Parser GetRunner( - ITestOutputHelper testOutputHelper, - Action? configureTestServices = null) => + public ITestOutputHelper? OutputHelper + { + get => accessor.Output; + set { } + } + + public Parser GetRunner(Action? configureTestServices = null) => Program.GetRunner(configureHost: builder => builder .ConfigureLogging(x => x.ClearProviders() - .AddXUnit(testOutputHelper) + .AddXUnit(this) .AddFakeLogging(options => { options.OutputSink = logMessage => _logMessages.Add(logMessage); From dfbdca50481e1326f65eb2c99fcc636296035a69 Mon Sep 17 00:00:00 2001 From: Stepami Date: Wed, 9 Oct 2024 22:44:26 +0300 Subject: [PATCH 2/2] re ident 4 spaces --- tests/Directory.Packages.props | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/Directory.Packages.props b/tests/Directory.Packages.props index f96787a..53ad6a3 100644 --- a/tests/Directory.Packages.props +++ b/tests/Directory.Packages.props @@ -1,15 +1,15 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file