From 9ff1260c12cd741265645340f3a10f7f49e2da46 Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Sun, 3 Jul 2022 01:31:33 -0400 Subject: [PATCH] try and fix the errors that are happening in ci... --- LaunchPad.sln | 15 +++++ .../ApiDescriptionData.cs | 34 ++++++++++ .../ClassicFoundationTests.cs | 19 +++--- .../ClassicRestfulConventionTests.cs | 11 ++-- .../HandleWebHostBase.cs | 32 ++++++++++ .../Sample.Classic.Restful.Tests.csproj | 14 +++++ .../SqliteConnectionService.cs | 27 ++++++++ .../TestWebHost.cs | 62 +++++++++++++++++++ .../ApiDescriptionData.cs | 5 +- test/Sample.Restful.Tests/FoundationTests.cs | 6 +- .../Sample.Restful.Tests/HandleWebHostBase.cs | 7 +-- .../LaunchRecords/CreateLaunchRecordTests.cs | 14 ++--- .../LaunchRecords/GetLaunchRecordTests.cs | 14 ++--- .../LaunchRecords/ListLaunchRecordsTests.cs | 14 ++--- .../LaunchRecords/RemoveLaunchRecordsTests.cs | 14 ++--- .../LaunchRecords/UpdateLaunchRecordTests.cs | 14 ++--- .../RestfulConventionTests.cs | 8 +-- .../Rockets/CreateRocketTests.cs | 10 +-- .../Rockets/GetRocketTests.cs | 14 ++--- .../Rockets/ListRocketsTests.cs | 14 ++--- .../Rockets/RemoveRocketsTests.cs | 14 ++--- .../Rockets/UpdateRocketTests.cs | 14 ++--- .../Sample.Restful.Tests.csproj | 1 - test/Sample.Restful.Tests/TestWebHost.cs | 18 +----- 24 files changed, 279 insertions(+), 116 deletions(-) create mode 100644 test/Sample.Classic.Restful.Tests/ApiDescriptionData.cs rename test/{Sample.Restful.Tests => Sample.Classic.Restful.Tests}/ClassicFoundationTests.cs (89%) rename test/{Sample.Restful.Tests => Sample.Classic.Restful.Tests}/ClassicRestfulConventionTests.cs (77%) create mode 100644 test/Sample.Classic.Restful.Tests/HandleWebHostBase.cs create mode 100644 test/Sample.Classic.Restful.Tests/Sample.Classic.Restful.Tests.csproj create mode 100644 test/Sample.Classic.Restful.Tests/SqliteConnectionService.cs create mode 100644 test/Sample.Classic.Restful.Tests/TestWebHost.cs diff --git a/LaunchPad.sln b/LaunchPad.sln index 933144f0b..e17252c40 100644 --- a/LaunchPad.sln +++ b/LaunchPad.sln @@ -125,6 +125,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.LaunchPad.We EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Classic.Restful", "sample\Sample.Classic.Restful\Sample.Classic.Restful.csproj", "{2C09FAF6-434D-442F-94B2-02AB906B477C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Classic.Restful.Tests", "test\Sample.Classic.Restful.Tests\Sample.Classic.Restful.Tests.csproj", "{2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -729,6 +731,18 @@ Global {2C09FAF6-434D-442F-94B2-02AB906B477C}.Release|x64.Build.0 = Release|Any CPU {2C09FAF6-434D-442F-94B2-02AB906B477C}.Release|x86.ActiveCfg = Release|Any CPU {2C09FAF6-434D-442F-94B2-02AB906B477C}.Release|x86.Build.0 = Release|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Debug|x64.ActiveCfg = Debug|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Debug|x64.Build.0 = Debug|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Debug|x86.ActiveCfg = Debug|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Debug|x86.Build.0 = Debug|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Release|Any CPU.Build.0 = Release|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Release|x64.ActiveCfg = Release|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Release|x64.Build.0 = Release|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Release|x86.ActiveCfg = Release|Any CPU + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -787,5 +801,6 @@ Global {A2C670CA-EFDD-468E-BEA1-D6D5A97270C4} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1} {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3} {2C09FAF6-434D-442F-94B2-02AB906B477C} = {5D11C19B-E8E4-4CE3-9C8A-1D368578EBCB} + {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1} EndGlobalSection EndGlobal diff --git a/test/Sample.Classic.Restful.Tests/ApiDescriptionData.cs b/test/Sample.Classic.Restful.Tests/ApiDescriptionData.cs new file mode 100644 index 000000000..11889d62d --- /dev/null +++ b/test/Sample.Classic.Restful.Tests/ApiDescriptionData.cs @@ -0,0 +1,34 @@ +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.DependencyInjection; + +namespace Sample.Classic.Restful.Tests; + +internal class ApiDescriptionData : TheoryData + where T : WebApplicationFactory, new() +{ + public ApiDescriptionData() + { + using var host = new T(); + var provider = host.Services.GetRequiredService(); + foreach (var item in provider.ApiDescriptionGroups.Items.SelectMany(z => z.Items)) + { + Add(new ApiDescriptionData(item)); + } + } +} + +public class ApiDescriptionData +{ + public ApiDescriptionData(ApiDescription description) + { + Description = description; + } + + public ApiDescription Description { get; } + + public override string ToString() + { + return $"[{Description.HttpMethod}] {Description.RelativePath}"; + } +} diff --git a/test/Sample.Restful.Tests/ClassicFoundationTests.cs b/test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs similarity index 89% rename from test/Sample.Restful.Tests/ClassicFoundationTests.cs rename to test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs index 13ec9ff01..1c1461dfe 100644 --- a/test/Sample.Restful.Tests/ClassicFoundationTests.cs +++ b/test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs @@ -4,14 +4,20 @@ using Microsoft.Extensions.Options; using Rocket.Surgery.Extensions.Testing; using Rocket.Surgery.LaunchPad.AspNetCore.Testing; -using Sample.Classic.Restful; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; -namespace Sample.Restful.Tests; +namespace Sample.Classic.Restful.Tests; -public class ClassicFoundationTests : AutoFakeTest, IClassFixture> +public class ClassicFoundationTests : AutoFakeTest, IClassFixture { + private readonly ConventionTestWebHost _factory; + + public ClassicFoundationTests(ITestOutputHelper testOutputHelper, TestWebHost factory) : base(testOutputHelper) + { + _factory = factory.ConfigureLogger(SerilogLogger); + } + [Fact] public void AutoMapper() { @@ -37,11 +43,4 @@ public void OpenApiDocument() .GetSwagger(document).Should().NotBeNull(); } } - - public ClassicFoundationTests(ITestOutputHelper testOutputHelper, TestWebHost factory) : base(testOutputHelper) - { - _factory = factory.ConfigureLogger(SerilogLogger); - } - - private readonly ConventionTestWebHost _factory; } diff --git a/test/Sample.Restful.Tests/ClassicRestfulConventionTests.cs b/test/Sample.Classic.Restful.Tests/ClassicRestfulConventionTests.cs similarity index 77% rename from test/Sample.Restful.Tests/ClassicRestfulConventionTests.cs rename to test/Sample.Classic.Restful.Tests/ClassicRestfulConventionTests.cs index eedc74093..450ec30bd 100644 --- a/test/Sample.Restful.Tests/ClassicRestfulConventionTests.cs +++ b/test/Sample.Classic.Restful.Tests/ClassicRestfulConventionTests.cs @@ -1,20 +1,19 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; -using Sample.Classic.Restful; -namespace Sample.Restful.Tests; +namespace Sample.Classic.Restful.Tests; public class ClassicRestfulConventionTests { [Theory] - [ClassData(typeof(ApiDescriptionData, Startup>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Success_Response_Types(ApiDescriptionData description) { description.Description.SupportedResponseTypes.Should().Contain(z => z.StatusCode >= 200 && z.StatusCode < 300); } [Theory] - [ClassData(typeof(ApiDescriptionData, Startup>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Not_Found_Responses(ApiDescriptionData description) { var method = ( description.Description.ActionDescriptor as ControllerActionDescriptor )!.MethodInfo; @@ -23,14 +22,14 @@ public void Should_Have_Not_Found_Responses(ApiDescriptionData description) } [Theory] - [ClassData(typeof(ApiDescriptionData, Startup>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Validation_Responses(ApiDescriptionData description) { description.Description.SupportedResponseTypes.Should().Contain(z => z.StatusCode == StatusCodes.Status422UnprocessableEntity); } [Theory] - [ClassData(typeof(ApiDescriptionData, Startup>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Bad_Request_Responses(ApiDescriptionData description) { description.Description.SupportedResponseTypes.Should().Contain(z => z.IsDefaultResponse); diff --git a/test/Sample.Classic.Restful.Tests/HandleWebHostBase.cs b/test/Sample.Classic.Restful.Tests/HandleWebHostBase.cs new file mode 100644 index 000000000..235f8d3a5 --- /dev/null +++ b/test/Sample.Classic.Restful.Tests/HandleWebHostBase.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Rocket.Surgery.Extensions.Testing; +using Sample.Core.Domain; + +namespace Sample.Classic.Restful.Tests; + +public abstract partial class HandleWebHostBase : LoggerTest, IAsyncLifetime, IClassFixture +{ + protected HandleWebHostBase( + ITestOutputHelper outputHelper, + TestWebHost host, + LogLevel logLevel = LogLevel.Trace + ) : base(outputHelper, logLevel) + { + Factory = host; + } + + protected TestWebHost Factory { get; private set; } + protected IServiceProvider ServiceProvider => Factory.Services; + + public async Task InitializeAsync() + { + await ServiceProvider.GetRequiredService().Database.EnsureCreatedAsync(); + } + + public async Task DisposeAsync() + { + await ServiceProvider.GetRequiredService().Database.EnsureDeletedAsync(); + Factory.Reset(); + } +} diff --git a/test/Sample.Classic.Restful.Tests/Sample.Classic.Restful.Tests.csproj b/test/Sample.Classic.Restful.Tests/Sample.Classic.Restful.Tests.csproj new file mode 100644 index 000000000..b96d7d588 --- /dev/null +++ b/test/Sample.Classic.Restful.Tests/Sample.Classic.Restful.Tests.csproj @@ -0,0 +1,14 @@ + + + net6.0 + + + + + + + + + + + diff --git a/test/Sample.Classic.Restful.Tests/SqliteConnectionService.cs b/test/Sample.Classic.Restful.Tests/SqliteConnectionService.cs new file mode 100644 index 000000000..8009cda97 --- /dev/null +++ b/test/Sample.Classic.Restful.Tests/SqliteConnectionService.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.Hosting; +using Rocket.Surgery.DependencyInjection; +using Sample.Core.Domain; + +namespace Sample.Classic.Restful.Tests; + +internal class SqliteConnectionService : IHostedService +{ + private readonly IServiceProvider _serviceProvider; + + public SqliteConnectionService(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + await _serviceProvider.WithScoped() + .Invoke(z => z.Database.EnsureCreatedAsync(cancellationToken)) + .ConfigureAwait(false); + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } +} diff --git a/test/Sample.Classic.Restful.Tests/TestWebHost.cs b/test/Sample.Classic.Restful.Tests/TestWebHost.cs new file mode 100644 index 000000000..223476668 --- /dev/null +++ b/test/Sample.Classic.Restful.Tests/TestWebHost.cs @@ -0,0 +1,62 @@ +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Rocket.Surgery.LaunchPad.AspNetCore.Testing; +using Sample.Core.Domain; + +namespace Sample.Classic.Restful.Tests; + +public class TestWebHost : ConventionTestWebHost, IAsyncLifetime +{ + private SqliteConnection _connection; + + public TestWebHost() + { + _connection = new SqliteConnection("DataSource=:memory:"); + _connection.Open(); + } + + + protected override IHost CreateHost(IHostBuilder builder) + { + return base.CreateHost( + builder + .ConfigureServices( + (_, services) => + { + services.AddHostedService(); + services.AddDbContextPool( + x => x + .EnableDetailedErrors() + .EnableSensitiveDataLogging() + .UseSqlite(_connection) + ); + } + ) + ); + } + + public void Reset() + { + _connection.Close(); + _connection.Open(); + } + + protected override void Dispose(bool disposing) + { + _connection.Close(); + _connection.Dispose(); + base.Dispose(disposing); + } + + public async Task InitializeAsync() + { + await Services.GetRequiredService().Database.EnsureCreatedAsync(); + } + + async Task IAsyncLifetime.DisposeAsync() + { + await DisposeAsync(); + } +} diff --git a/test/Sample.Restful.Tests/ApiDescriptionData.cs b/test/Sample.Restful.Tests/ApiDescriptionData.cs index 19394b94d..e8506da16 100644 --- a/test/Sample.Restful.Tests/ApiDescriptionData.cs +++ b/test/Sample.Restful.Tests/ApiDescriptionData.cs @@ -4,9 +4,8 @@ namespace Sample.Restful.Tests; -internal class ApiDescriptionData : TheoryData - where TProgramOrStartup : class - where T : WebApplicationFactory, new() +internal class ApiDescriptionData : TheoryData + where T : WebApplicationFactory, new() { public ApiDescriptionData() { diff --git a/test/Sample.Restful.Tests/FoundationTests.cs b/test/Sample.Restful.Tests/FoundationTests.cs index 0038b9529..f5b293dab 100644 --- a/test/Sample.Restful.Tests/FoundationTests.cs +++ b/test/Sample.Restful.Tests/FoundationTests.cs @@ -9,7 +9,7 @@ namespace Sample.Restful.Tests; -public class FoundationTests : AutoFakeTest, IClassFixture> +public class FoundationTests : AutoFakeTest, IClassFixture { [Fact] public void AutoMapper() @@ -25,7 +25,7 @@ public async Task Starts() response.StatusCode.Should().Be(HttpStatusCode.NotFound); } - public FoundationTests(ITestOutputHelper testOutputHelper, TestWebHost factory) : base(testOutputHelper) + public FoundationTests(ITestOutputHelper testOutputHelper, TestWebHost factory) : base(testOutputHelper) { _factory = factory.ConfigureLoggerFactory(LoggerFactory); } @@ -44,7 +44,7 @@ private class OpenApiDocuments : TheoryData { public OpenApiDocuments() { - using var host = new TestWebHost(); + using var host = new TestWebHost(); foreach (var item in host.Services.GetRequiredService>().Value.SwaggerDocs.Keys) { Add(item); diff --git a/test/Sample.Restful.Tests/HandleWebHostBase.cs b/test/Sample.Restful.Tests/HandleWebHostBase.cs index 83b3eab3d..d54a28e70 100644 --- a/test/Sample.Restful.Tests/HandleWebHostBase.cs +++ b/test/Sample.Restful.Tests/HandleWebHostBase.cs @@ -5,19 +5,18 @@ namespace Sample.Restful.Tests; -public abstract partial class HandleWebHostBase : LoggerTest, IAsyncLifetime, IClassFixture> - where TProgramOrStartup : class +public abstract partial class HandleWebHostBase : LoggerTest, IAsyncLifetime, IClassFixture { protected HandleWebHostBase( ITestOutputHelper outputHelper, - TestWebHost host, + TestWebHost host, LogLevel logLevel = LogLevel.Trace ) : base(outputHelper, logLevel) { Factory = host; } - protected TestWebHost Factory { get; private set; } + protected TestWebHost Factory { get; private set; } protected IServiceProvider ServiceProvider => Factory.Services; public async Task InitializeAsync() diff --git a/test/Sample.Restful.Tests/LaunchRecords/CreateLaunchRecordTests.cs b/test/Sample.Restful.Tests/LaunchRecords/CreateLaunchRecordTests.cs index a75ee1b11..d8c895953 100644 --- a/test/Sample.Restful.Tests/LaunchRecords/CreateLaunchRecordTests.cs +++ b/test/Sample.Restful.Tests/LaunchRecords/CreateLaunchRecordTests.cs @@ -7,14 +7,8 @@ namespace Sample.Restful.Tests.LaunchRecords; -public class CreateLaunchRecordTests : HandleWebHostBase +public class CreateLaunchRecordTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public CreateLaunchRecordTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Create_A_LaunchRecord() { @@ -50,4 +44,10 @@ public async Task Should_Create_A_LaunchRecord() response.Result.Id.Should().NotBeEmpty(); } + + public CreateLaunchRecordTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } diff --git a/test/Sample.Restful.Tests/LaunchRecords/GetLaunchRecordTests.cs b/test/Sample.Restful.Tests/LaunchRecords/GetLaunchRecordTests.cs index 46d3774cf..a89f480f1 100644 --- a/test/Sample.Restful.Tests/LaunchRecords/GetLaunchRecordTests.cs +++ b/test/Sample.Restful.Tests/LaunchRecords/GetLaunchRecordTests.cs @@ -8,14 +8,8 @@ namespace Sample.Restful.Tests.LaunchRecords; -public class GetLaunchRecordTests : HandleWebHostBase +public class GetLaunchRecordTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public GetLaunchRecordTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Get_A_LaunchRecord() { @@ -67,4 +61,10 @@ await action.Should().ThrowAsync>() z => z.StatusCode == 404 && z.Result.Status == 404 && z.Result.Title == "Not Found" ); } + + public GetLaunchRecordTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } diff --git a/test/Sample.Restful.Tests/LaunchRecords/ListLaunchRecordsTests.cs b/test/Sample.Restful.Tests/LaunchRecords/ListLaunchRecordsTests.cs index b0da46e62..d17a59fa6 100644 --- a/test/Sample.Restful.Tests/LaunchRecords/ListLaunchRecordsTests.cs +++ b/test/Sample.Restful.Tests/LaunchRecords/ListLaunchRecordsTests.cs @@ -7,14 +7,8 @@ namespace Sample.Restful.Tests.LaunchRecords; -public class ListLaunchRecordsTests : HandleWebHostBase +public class ListLaunchRecordsTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public ListLaunchRecordsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_List_LaunchRecords() { @@ -57,5 +51,11 @@ await ServiceProvider.WithScoped() var response = await client.ListLaunchRecordsAsync(RocketType.FalconHeavy); response.Result.Should().HaveCount(3); } + + public ListLaunchRecordsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } #endif diff --git a/test/Sample.Restful.Tests/LaunchRecords/RemoveLaunchRecordsTests.cs b/test/Sample.Restful.Tests/LaunchRecords/RemoveLaunchRecordsTests.cs index 8168344e9..9e4e06216 100644 --- a/test/Sample.Restful.Tests/LaunchRecords/RemoveLaunchRecordsTests.cs +++ b/test/Sample.Restful.Tests/LaunchRecords/RemoveLaunchRecordsTests.cs @@ -6,14 +6,8 @@ namespace Sample.Restful.Tests.LaunchRecords; -public class RemoveLaunchRecordsTests : HandleWebHostBase +public class RemoveLaunchRecordsTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public RemoveLaunchRecordsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Remove_LaunchRecord() { @@ -64,4 +58,10 @@ await ServiceProvider.WithScoped() await action.Should().ThrowAsync>() .Where(z => z.StatusCode == 403 && z.Result.Status == 403 && z.Result.Title == "Forbidden"); } + + public RemoveLaunchRecordsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } diff --git a/test/Sample.Restful.Tests/LaunchRecords/UpdateLaunchRecordTests.cs b/test/Sample.Restful.Tests/LaunchRecords/UpdateLaunchRecordTests.cs index a59ed717d..bd980967d 100644 --- a/test/Sample.Restful.Tests/LaunchRecords/UpdateLaunchRecordTests.cs +++ b/test/Sample.Restful.Tests/LaunchRecords/UpdateLaunchRecordTests.cs @@ -9,14 +9,8 @@ namespace Sample.Restful.Tests.LaunchRecords; -public class UpdateLaunchRecordTests : HandleWebHostBase +public class UpdateLaunchRecordTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public UpdateLaunchRecordTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Update_A_LaunchRecord() { @@ -66,4 +60,10 @@ await client.EditLaunchRecordAsync( response.Result.ScheduledLaunchDate.Should().Be(( record.ScheduledLaunchDate.ToInstant() + Duration.FromSeconds(1) ).ToDateTimeOffset()); response.Result.PayloadWeightKg.Should().Be(200); } + + public UpdateLaunchRecordTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } diff --git a/test/Sample.Restful.Tests/RestfulConventionTests.cs b/test/Sample.Restful.Tests/RestfulConventionTests.cs index 44e4597d4..b44d1c728 100644 --- a/test/Sample.Restful.Tests/RestfulConventionTests.cs +++ b/test/Sample.Restful.Tests/RestfulConventionTests.cs @@ -6,14 +6,14 @@ namespace Sample.Restful.Tests; public class RestfulConventionTests { [Theory] - [ClassData(typeof(ApiDescriptionData, Program>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Success_Response_Types(ApiDescriptionData description) { description.Description.SupportedResponseTypes.Should().Contain(z => z.StatusCode >= 200 && z.StatusCode < 300); } [Theory] - [ClassData(typeof(ApiDescriptionData, Program>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Not_Found_Responses(ApiDescriptionData description) { var method = ( description.Description.ActionDescriptor as ControllerActionDescriptor )!.MethodInfo; @@ -22,14 +22,14 @@ public void Should_Have_Not_Found_Responses(ApiDescriptionData description) } [Theory] - [ClassData(typeof(ApiDescriptionData, Program>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Validation_Responses(ApiDescriptionData description) { description.Description.SupportedResponseTypes.Should().Contain(z => z.StatusCode == StatusCodes.Status422UnprocessableEntity); } [Theory] - [ClassData(typeof(ApiDescriptionData, Program>))] + [ClassData(typeof(ApiDescriptionData))] public void Should_Have_Bad_Request_Responses(ApiDescriptionData description) { description.Description.SupportedResponseTypes.Should().Contain(z => z.IsDefaultResponse); diff --git a/test/Sample.Restful.Tests/Rockets/CreateRocketTests.cs b/test/Sample.Restful.Tests/Rockets/CreateRocketTests.cs index fecbcc0e0..d64f77894 100644 --- a/test/Sample.Restful.Tests/Rockets/CreateRocketTests.cs +++ b/test/Sample.Restful.Tests/Rockets/CreateRocketTests.cs @@ -2,12 +2,8 @@ namespace Sample.Restful.Tests.Rockets; -public class CreateRocketTests : HandleWebHostBase +public class CreateRocketTests : HandleWebHostBase { - public CreateRocketTests(ITestOutputHelper testOutputHelper, TestWebHost host) : base(testOutputHelper, host) - { - } - [Fact] public async Task Should_Create_A_Rocket() { @@ -47,4 +43,8 @@ await client.CreateRocketAsync( .And.Result; r.Title.Should().Be("Rocket Creation Failed"); } + + public CreateRocketTests(ITestOutputHelper testOutputHelper, TestWebHost host) : base(testOutputHelper, host) + { + } } diff --git a/test/Sample.Restful.Tests/Rockets/GetRocketTests.cs b/test/Sample.Restful.Tests/Rockets/GetRocketTests.cs index 92f53901c..21291f626 100644 --- a/test/Sample.Restful.Tests/Rockets/GetRocketTests.cs +++ b/test/Sample.Restful.Tests/Rockets/GetRocketTests.cs @@ -6,14 +6,8 @@ namespace Sample.Restful.Tests.Rockets; -public class GetRocketTests : HandleWebHostBase +public class GetRocketTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public GetRocketTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Get_A_Rocket() { @@ -51,4 +45,10 @@ await action.Should().ThrowAsync>() z => z.StatusCode == 404 && z.Result.Status == 404 && z.Result.Title == "Not Found" ); } + + public GetRocketTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } diff --git a/test/Sample.Restful.Tests/Rockets/ListRocketsTests.cs b/test/Sample.Restful.Tests/Rockets/ListRocketsTests.cs index 97a1be68d..5ab646912 100644 --- a/test/Sample.Restful.Tests/Rockets/ListRocketsTests.cs +++ b/test/Sample.Restful.Tests/Rockets/ListRocketsTests.cs @@ -7,14 +7,8 @@ namespace Sample.Restful.Tests.Rockets; -public class ListRocketsTests : HandleWebHostBase +public class ListRocketsTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public ListRocketsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_List_Rockets() { @@ -54,5 +48,11 @@ await ServiceProvider.WithScoped() response.Result.Should().HaveCount(5); } + + public ListRocketsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } #endif diff --git a/test/Sample.Restful.Tests/Rockets/RemoveRocketsTests.cs b/test/Sample.Restful.Tests/Rockets/RemoveRocketsTests.cs index 6bd9684a6..21661d047 100644 --- a/test/Sample.Restful.Tests/Rockets/RemoveRocketsTests.cs +++ b/test/Sample.Restful.Tests/Rockets/RemoveRocketsTests.cs @@ -5,14 +5,8 @@ namespace Sample.Restful.Tests.Rockets; -public class RemoveRocketsTests : HandleWebHostBase +public class RemoveRocketsTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public RemoveRocketsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Remove_Rocket() { @@ -34,4 +28,10 @@ public async Task Should_Remove_Rocket() ServiceProvider.WithScoped().Invoke(c => c.Rockets.Should().BeEmpty()); } + + public RemoveRocketsTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); } diff --git a/test/Sample.Restful.Tests/Rockets/UpdateRocketTests.cs b/test/Sample.Restful.Tests/Rockets/UpdateRocketTests.cs index 563f4c0a6..2a6fe58ad 100644 --- a/test/Sample.Restful.Tests/Rockets/UpdateRocketTests.cs +++ b/test/Sample.Restful.Tests/Rockets/UpdateRocketTests.cs @@ -6,14 +6,8 @@ namespace Sample.Restful.Tests.Rockets; -public class UpdateRocketTests : HandleWebHostBase +public class UpdateRocketTests : HandleWebHostBase { - private static readonly Faker Faker = new(); - - public UpdateRocketTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) - { - } - [Fact] public async Task Should_Update_A_Rocket() { @@ -155,6 +149,12 @@ public async Task Should_Patch_A_Rocket_Type() response.Result.Sn.Should().Be("12345678901234"); } + public UpdateRocketTests(ITestOutputHelper outputHelper, TestWebHost host) : base(outputHelper, host) + { + } + + private static readonly Faker Faker = new(); + [Theory] [ClassData(typeof(ShouldValidateUsersRequiredFieldData))] public async Task Should_Validate_Required_Fields(EditRocketRequest request, string propertyName) diff --git a/test/Sample.Restful.Tests/Sample.Restful.Tests.csproj b/test/Sample.Restful.Tests/Sample.Restful.Tests.csproj index 17bb74d97..50aa77833 100644 --- a/test/Sample.Restful.Tests/Sample.Restful.Tests.csproj +++ b/test/Sample.Restful.Tests/Sample.Restful.Tests.csproj @@ -9,7 +9,6 @@ - diff --git a/test/Sample.Restful.Tests/TestWebHost.cs b/test/Sample.Restful.Tests/TestWebHost.cs index ab3de0bb3..64df7a679 100644 --- a/test/Sample.Restful.Tests/TestWebHost.cs +++ b/test/Sample.Restful.Tests/TestWebHost.cs @@ -5,13 +5,11 @@ using Rocket.Surgery.Conventions; using Rocket.Surgery.LaunchPad.AspNetCore; using Rocket.Surgery.LaunchPad.AspNetCore.Testing; -using Sample.Classic.Restful; using Sample.Core.Domain; namespace Sample.Restful.Tests; -public class TestWebHost : ConventionTestWebHost, IAsyncLifetime - where TProgramOrStartup : class +public class TestWebHost : ConventionTestWebHost, IAsyncLifetime { private SqliteConnection _connection; @@ -19,20 +17,6 @@ public TestWebHost() { _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); - - ConfigureHostBuilder( - builder => - { - var excludeConvention = typeof(TProgramOrStartup) == typeof(Program) ? typeof(Startup).Assembly : typeof(Program).Assembly; - builder.ExceptConvention(excludeConvention) - .Set( - new AspNetCoreOptions - { - AssemblyPartFilter = assembly => assembly != excludeConvention - } - ); - } - ); }