-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try and fix the errors that are happening in ci...
- Loading branch information
1 parent
277fe1a
commit 169afa5
Showing
24 changed files
with
279 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test/Sample.Classic.Restful.Tests/Sample.Classic.Restful.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
test/Sample.Classic.Restful.Tests/SqliteConnectionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.