Skip to content

V4.0.0/additional functional testing #10

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

Merged
merged 7 commits into from
Apr 12, 2025
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
3 changes: 3 additions & 0 deletions .nuget/Codebelt.Bootstrapper.Web/PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Availability: .NET 9 and .NET 8
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs

# Breaking Changes
- REMOVED WebApplicationBuilderExtensions class in the Codebelt.Bootstrapper.Web namespace (UseBootstrapperLifetime extension method)

Version 3.0.1
Availability: .NET 9 and .NET 8

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This major release revisits and refines some of the earlier design decisions to
### Removed

- HostedServiceExtensions class in the Codebelt.Bootstrapper namespace (breaking change)
- WebApplicationBuilderExtensions class in the Codebelt.Bootstrapper.Web namespace (breaking change)

### Fixed

Expand Down
14 changes: 14 additions & 0 deletions Codebelt.Bootstrapper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codebelt.Bootstrapper.Funct
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codebelt.Bootstrapper.Console.FunctionalTests", "test\Codebelt.Bootstrapper.Console.FunctionalTests\Codebelt.Bootstrapper.Console.FunctionalTests.csproj", "{585A199C-4675-4A8A-89B7-EFF824377456}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codebelt.Bootstrapper.Worker.FunctionalTests", "test\Codebelt.Bootstrapper.Worker.FunctionalTests\Codebelt.Bootstrapper.Worker.FunctionalTests.csproj", "{42B4B4ED-95E4-4855-852D-8832E97202CD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codebelt.Bootstrapper.Web.FunctionalTests", "test\Codebelt.Bootstrapper.Web.FunctionalTests\Codebelt.Bootstrapper.Web.FunctionalTests.csproj", "{BD1FF180-06BC-4A5F-A746-A30648FEB509}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,6 +133,14 @@ Global
{585A199C-4675-4A8A-89B7-EFF824377456}.Debug|Any CPU.Build.0 = Debug|Any CPU
{585A199C-4675-4A8A-89B7-EFF824377456}.Release|Any CPU.ActiveCfg = Release|Any CPU
{585A199C-4675-4A8A-89B7-EFF824377456}.Release|Any CPU.Build.0 = Release|Any CPU
{42B4B4ED-95E4-4855-852D-8832E97202CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42B4B4ED-95E4-4855-852D-8832E97202CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42B4B4ED-95E4-4855-852D-8832E97202CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42B4B4ED-95E4-4855-852D-8832E97202CD}.Release|Any CPU.Build.0 = Release|Any CPU
{BD1FF180-06BC-4A5F-A746-A30648FEB509}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD1FF180-06BC-4A5F-A746-A30648FEB509}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD1FF180-06BC-4A5F-A746-A30648FEB509}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD1FF180-06BC-4A5F-A746-A30648FEB509}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -153,6 +165,8 @@ Global
{CC656409-7479-4553-8E9B-0854801E1590} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{8970491F-E0BD-489D-AA7E-617A67C2E39F} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{585A199C-4675-4A8A-89B7-EFF824377456} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{42B4B4ED-95E4-4855-852D-8832E97202CD} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{BD1FF180-06BC-4A5F-A746-A30648FEB509} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {72FB037E-3629-4CDB-812E-D577A3D4FD26}
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Codebelt.Extensions.Swashbuckle.AspNetCore" Version="9.0.1" />
<PackageVersion Include="Codebelt.Extensions.Xunit.App" Version="10.0.0-preview.2" />
<PackageVersion Include="Codebelt.Extensions.Xunit.App" Version="10.0.0-preview.3" />
<PackageVersion Include="Cuemon.Core" Version="9.0.4" />
<PackageVersion Include="Cuemon.Extensions.Hosting" Version="9.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
Expand Down
5 changes: 3 additions & 2 deletions src/Codebelt.Bootstrapper.Web/MinimalWebProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
/// <returns>The initialized <see cref="HostApplicationBuilder"/>.</returns>
protected static WebApplicationBuilder CreateHostBuilder(string[] args)
{
return WebApplication.CreateBuilder(args)
.UseBootstrapperLifetime();
var hb = WebApplication.CreateBuilder(args);
hb.UseBootstrapperLifetime();
return hb;

Check warning on line 20 in src/Codebelt.Bootstrapper.Web/MinimalWebProgram.cs

View check run for this annotation

Codecov / codecov/patch

src/Codebelt.Bootstrapper.Web/MinimalWebProgram.cs#L18-L20

Added lines #L18 - L20 were not covered by tests
}
}
}
26 changes: 0 additions & 26 deletions src/Codebelt.Bootstrapper.Web/WebApplicationBuilderExtensions.cs

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Codebelt.Bootstrapper.Console.Assets
{
public class TestHostFixture : GenericHostFixture
public class TestHostFixture : ManagedHostFixture
{
public override void ConfigureHost(Test hostTest)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Codebelt.Bootstrapper.Console.Assets;
using Codebelt.Extensions.Xunit;
using Codebelt.Extensions.Xunit.Hosting;
Expand All @@ -16,17 +14,6 @@ public class MinimalConsoleHostedServiceTest : Test
{
public MinimalConsoleHostedServiceTest(ITestOutputHelper output) : base(output)
{
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
var exception = e.ExceptionObject as Exception;
Debug.WriteLine($"Unhandled exception: {exception?.Message}");
};

TaskScheduler.UnobservedTaskException += (sender, e) =>
{
Debug.WriteLine($"Unobserved task exception: {e.Exception.Message}");
e.SetObserved();
};
}

[Fact]
Expand All @@ -42,30 +29,6 @@ public async Task StartAsync_ShouldInvokeRunAsyncInTestConsoleStartup()
.UseMinimalConsoleProgram();
});

//var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));

//if (SynchronizationContext.Current == null)
//{
// // normal ASP.Net Core environment does not have a synchronization context,
// // no problem with await here, it will be executed on the thread pool
// await test.Host.StartAsync();
// await test.Host.WaitForShutdownAsync();
//}
//else
//{
// // xunit uses it's own SynchronizationContext that allows a maximum thread count
// // equal to the logical cpu count (that is 1 on our single cpu build agents). So
// // when we're trying to await something here, the task get's scheduled to xunit's
// // synchronization context, which is already at it's limit running the test thread
// // so we end up in a deadlock here.
// // solution is to run the await explicitly on the thread pool by using Task.Run
// Task.Run(async () =>
// {
// await test.Host.StartAsync();
// await test.Host.WaitForShutdownAsync();
// }).Wait();
//}

await test.Host.WaitForShutdownAsync();

var loggerStore = test.Host.Services.GetRequiredService<ILogger<TestMinimalConsoleProgram>>().GetTestStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Codebelt.Bootstrapper.Assets
{
public class TestHostFixture : GenericHostFixture
public class TestHostFixture : ManagedHostFixture
{
public override void ConfigureHost(Test hostTest)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Cuemon.Extensions.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Codebelt.Bootstrapper.Web.Assets
{
public class TestStartup : WebStartup
{
public TestStartup(IConfiguration configuration, IHostEnvironment environment) : base(configuration, environment)
{
}

public override void ConfigureServices(IServiceCollection services)
{
}

public override void ConfigurePipeline(IApplicationBuilder app)
{
if (Environment.IsLocalDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Codebelt.Bootstrapper.Web</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Codebelt.Bootstrapper.Web\Codebelt.Bootstrapper.Web.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Threading.Tasks;
using Codebelt.Extensions.Xunit;
using Codebelt.Extensions.Xunit.Hosting;
using Codebelt.Extensions.Xunit.Hosting.AspNetCore;
using Cuemon.Extensions.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Xunit;
using Xunit.Abstractions;

namespace Codebelt.Bootstrapper.Web
{
public class MinimalWebProgramTest : Test
{
public MinimalWebProgramTest(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task ExecuteAsync_ShouldSimulateAMinimalWebApplication()
{
using var test = await MinimalWebHostTestFactory.RunWithHostBuilderContextAsync((context, services) =>
{
services.AddXunitTestLogging(TestOutput);
}, (context, app) =>
{
if (context.HostingEnvironment.IsLocalDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}, hb =>
{
hb.UseBootstrapperLifetime();
});

var helloWorld = await test.Content.ReadAsStringAsync();

Assert.Equal("Hello World!", helloWorld);
}
}
}
41 changes: 41 additions & 0 deletions test/Codebelt.Bootstrapper.Web.FunctionalTests/WebStartupTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Threading.Tasks;
using Codebelt.Bootstrapper.Web.Assets;
using Codebelt.Extensions.Xunit;
using Codebelt.Extensions.Xunit.Hosting;
using Codebelt.Extensions.Xunit.Hosting.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Hosting;
using Xunit;
using Xunit.Abstractions;

namespace Codebelt.Bootstrapper.Web
{
public class WebStartupTest : Test
{
public WebStartupTest(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task ConfigurePipeline_ShouldSimulateAWebApplication()
{
using var test = await WebHostTestFactory.RunWithHostBuilderContextAsync((context, services) =>
{
services.AddXunitTestLogging(TestOutput);
}, hostSetup: hb =>
{
hb.UseBootstrapperLifetime()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseTestServer(o => o.PreserveExecutionContext = true);
webBuilder.UseStartup<TestStartup>();
});
});

var helloWorld = await test.Content.ReadAsStringAsync();

Assert.Equal("Hello World!", helloWorld);
}
}
}
Loading
Loading