Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rocket Surgery Conventions to v12.2.4 #1184

Merged
merged 2 commits into from
Jul 3, 2022
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
20 changes: 10 additions & 10 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@
<PackageVersion Include="Polly" Version="7.2.3" />
<PackageVersion Include="StronglyTypedId" Version="1.0.0-beta06" />
<PackageVersion Include="Rocket.Surgery.Build.Information" Version="3.3.11" />
<PackageVersion Include="Rocket.Surgery.Conventions" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Conventions.Abstractions" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Conventions.Attributes" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Conventions.CommandLine" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Conventions.DependencyModel" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Conventions.DryIoc" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Conventions" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Conventions.Abstractions" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Conventions.Attributes" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Conventions.CommandLine" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Conventions.DependencyModel" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Conventions.DryIoc" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Extensions.Configuration" Version="11.4.2" />
<PackageVersion Include="Rocket.Surgery.Extensions.Configuration.Json" Version="11.4.2" />
<PackageVersion Include="Rocket.Surgery.Extensions.Configuration.Yaml" Version="11.4.2" />
<PackageVersion Include="Rocket.Surgery.DependencyInjection.Extensions" Version="11.4.2" />
<PackageVersion Include="Rocket.Surgery.Extensions" Version="11.4.2" />
<PackageVersion Include="Rocket.Surgery.Hosting" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Hosting.Abstractions" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Web.Hosting" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.WebAssembly.Hosting" Version="12.2.3" />
<PackageVersion Include="Rocket.Surgery.Hosting" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Hosting.Abstractions" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.Web.Hosting" Version="12.2.4" />
<PackageVersion Include="Rocket.Surgery.WebAssembly.Hosting" Version="12.2.4" />
<PackageVersion Include="Scrutor" Version="4.2.0" />
<PackageVersion Include="Serilog" Version="2.11.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="5.0.0" />
Expand Down
15 changes: 15 additions & 0 deletions LaunchPad.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
34 changes: 34 additions & 0 deletions test/Sample.Classic.Restful.Tests/ApiDescriptionData.cs
Original file line number Diff line number Diff line change
@@ -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<T> : TheoryData<ApiDescriptionData>
where T : WebApplicationFactory<Startup>, new()
{
public ApiDescriptionData()
{
using var host = new T();
var provider = host.Services.GetRequiredService<IApiDescriptionGroupCollectionProvider>();
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}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestWebHost<Startup>>
public class ClassicFoundationTests : AutoFakeTest, IClassFixture<TestWebHost>
{
private readonly ConventionTestWebHost<Startup> _factory;

public ClassicFoundationTests(ITestOutputHelper testOutputHelper, TestWebHost factory) : base(testOutputHelper)
{
_factory = factory.ConfigureLogger(SerilogLogger);
}

[Fact]
public void AutoMapper()
{
Expand All @@ -37,11 +43,4 @@ public void OpenApiDocument()
.GetSwagger(document).Should().NotBeNull();
}
}

public ClassicFoundationTests(ITestOutputHelper testOutputHelper, TestWebHost<Startup> factory) : base(testOutputHelper)
{
_factory = factory.ConfigureLogger(SerilogLogger);
}

private readonly ConventionTestWebHost<Startup> _factory;
}
Original file line number Diff line number Diff line change
@@ -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<TestWebHost<Startup>, Startup>))]
[ClassData(typeof(ApiDescriptionData<TestWebHost>))]
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<TestWebHost<Startup>, Startup>))]
[ClassData(typeof(ApiDescriptionData<TestWebHost>))]
public void Should_Have_Not_Found_Responses(ApiDescriptionData description)
{
var method = ( description.Description.ActionDescriptor as ControllerActionDescriptor )!.MethodInfo;
Expand All @@ -23,14 +22,14 @@ public void Should_Have_Not_Found_Responses(ApiDescriptionData description)
}

[Theory]
[ClassData(typeof(ApiDescriptionData<TestWebHost<Startup>, Startup>))]
[ClassData(typeof(ApiDescriptionData<TestWebHost>))]
public void Should_Have_Validation_Responses(ApiDescriptionData description)
{
description.Description.SupportedResponseTypes.Should().Contain(z => z.StatusCode == StatusCodes.Status422UnprocessableEntity);
}

[Theory]
[ClassData(typeof(ApiDescriptionData<TestWebHost<Startup>, Startup>))]
[ClassData(typeof(ApiDescriptionData<TestWebHost>))]
public void Should_Have_Bad_Request_Responses(ApiDescriptionData description)
{
description.Description.SupportedResponseTypes.Should().Contain(z => z.IsDefaultResponse);
Expand Down
32 changes: 32 additions & 0 deletions test/Sample.Classic.Restful.Tests/HandleWebHostBase.cs
Original file line number Diff line number Diff line change
@@ -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<TestWebHost>
{
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<RocketDbContext>().Database.EnsureCreatedAsync();
}

public async Task DisposeAsync()
{
await ServiceProvider.GetRequiredService<RocketDbContext>().Database.EnsureDeletedAsync();
Factory.Reset();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Include="System.Net.Http.Json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\sample\Sample.Restful.Client\Sample.Restful.Client.csproj" />
<ProjectReference Include="..\..\sample\Sample.Classic.Restful\Sample.Classic.Restful.csproj" />
<ProjectReference Include="..\..\src\AspNetCore.Testing\Rocket.Surgery.LaunchPad.AspNetCore.Testing.csproj" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions test/Sample.Classic.Restful.Tests/SqliteConnectionService.cs
Original file line number Diff line number Diff line change
@@ -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<RocketDbContext>()
.Invoke(z => z.Database.EnsureCreatedAsync(cancellationToken))
.ConfigureAwait(false);
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
62 changes: 62 additions & 0 deletions test/Sample.Classic.Restful.Tests/TestWebHost.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>, 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<SqliteConnectionService>();
services.AddDbContextPool<RocketDbContext>(
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<RocketDbContext>().Database.EnsureCreatedAsync();
}

async Task IAsyncLifetime.DisposeAsync()
{
await DisposeAsync();
}
}
5 changes: 2 additions & 3 deletions test/Sample.Restful.Tests/ApiDescriptionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace Sample.Restful.Tests;

internal class ApiDescriptionData<T, TProgramOrStartup> : TheoryData<ApiDescriptionData>
where TProgramOrStartup : class
where T : WebApplicationFactory<TProgramOrStartup>, new()
internal class ApiDescriptionData<T> : TheoryData<ApiDescriptionData>
where T : WebApplicationFactory<Program>, new()
{
public ApiDescriptionData()
{
Expand Down
6 changes: 3 additions & 3 deletions test/Sample.Restful.Tests/FoundationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Sample.Restful.Tests;

public class FoundationTests : AutoFakeTest, IClassFixture<TestWebHost<Program>>
public class FoundationTests : AutoFakeTest, IClassFixture<TestWebHost>
{
[Fact]
public void AutoMapper()
Expand All @@ -25,7 +25,7 @@ public async Task Starts()
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}

public FoundationTests(ITestOutputHelper testOutputHelper, TestWebHost<Program> factory) : base(testOutputHelper)
public FoundationTests(ITestOutputHelper testOutputHelper, TestWebHost factory) : base(testOutputHelper)
{
_factory = factory.ConfigureLoggerFactory(LoggerFactory);
}
Expand All @@ -44,7 +44,7 @@ private class OpenApiDocuments : TheoryData<string>
{
public OpenApiDocuments()
{
using var host = new TestWebHost<Program>();
using var host = new TestWebHost();
foreach (var item in host.Services.GetRequiredService<IOptions<SwaggerGeneratorOptions>>().Value.SwaggerDocs.Keys)
{
Add(item);
Expand Down
7 changes: 3 additions & 4 deletions test/Sample.Restful.Tests/HandleWebHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@

namespace Sample.Restful.Tests;

public abstract partial class HandleWebHostBase<TProgramOrStartup> : LoggerTest, IAsyncLifetime, IClassFixture<TestWebHost<TProgramOrStartup>>
where TProgramOrStartup : class
public abstract partial class HandleWebHostBase : LoggerTest, IAsyncLifetime, IClassFixture<TestWebHost>
{
protected HandleWebHostBase(
ITestOutputHelper outputHelper,
TestWebHost<TProgramOrStartup> host,
TestWebHost host,
LogLevel logLevel = LogLevel.Trace
) : base(outputHelper, logLevel)
{
Factory = host;
}

protected TestWebHost<TProgramOrStartup> Factory { get; private set; }
protected TestWebHost Factory { get; private set; }
protected IServiceProvider ServiceProvider => Factory.Services;

public async Task InitializeAsync()
Expand Down
Loading