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

.NET 8 Updates #151

Merged
merged 6 commits into from
Jan 21, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install .NET Core 7.0.x
- name: Install .NET Core 8.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20

- name: Setup Pages
uses: actions/configure-pages@v3
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup .NET
- name: Setup .NET 6
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
Expand All @@ -28,6 +28,11 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x

- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Test
run: ./build.ps1 test
4 changes: 2 additions & 2 deletions docs/guide/nunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Application
}
}
```
<sup><a href='https://github.com/JasperFx/alba/blob/master/src/NUnitSamples/UnitTest1.cs#L11-L33' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_nunit_application' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/alba/blob/master/src/NUnitSamples/UnitTest1.cs#L8-L30' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_nunit_application' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Then reference the `AlbaHost` in tests like this sample:
Expand All @@ -48,5 +48,5 @@ public class sample_integration_fixture
}
}
```
<sup><a href='https://github.com/JasperFx/alba/blob/master/src/NUnitSamples/UnitTest1.cs#L35-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_nunit_scenario_test' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/alba/blob/master/src/NUnitSamples/UnitTest1.cs#L32-L45' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_nunit_scenario_test' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
2 changes: 1 addition & 1 deletion docs/scenarios/formdata.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ There's a second overload that attempts to use an object and its properties to p
[Fact]
public async Task can_bind_to_form_data()
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();

var input = new InputModel {
One = "one",
Expand Down
32 changes: 14 additions & 18 deletions src/Alba.Testing/Acceptance/assertions_against_redirects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class assertions_against_redirects
[Fact]
public async Task redirect()
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();
await system.Scenario(_ =>
{
_.Get.Url("/auth/redirect");
Expand All @@ -24,15 +24,13 @@ public async Task not_redirected()
{
var result = await Exception<ScenarioAssertionException>.ShouldBeThrownBy(async () =>
{
using (var system = AlbaHost.ForStartup<Startup>())
await using var system = await AlbaHost.For<Startup>();
await system.Scenario(_ =>
{
await system.Scenario(_ =>
{
_.Get.Url("/api/values");
_.Get.Url("/api/values");

_.RedirectShouldBe("/else");
});
}
_.RedirectShouldBe("/else");
});
});

result.Message.ShouldContain("Expected to be redirected to '/else' but was ''.");
Expand All @@ -43,7 +41,7 @@ public async Task redirect_wrong_value()
{
var result = await Exception<ScenarioAssertionException>.ShouldBeThrownBy(async () =>
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();
await system.Scenario(_ =>
{
_.Get.Url("/auth/redirect");
Expand All @@ -58,23 +56,21 @@ await system.Scenario(_ =>
[Fact]
public async Task redirect_permanent()
{
using (var system = AlbaHost.ForStartup<Startup>())
await using var system = await AlbaHost.For<Startup>();
await system.Scenario(_ =>
{
await system.Scenario(_ =>
{
_.Get.Url("/auth/redirectpermanent");
_.Get.Url("/auth/redirectpermanent");

_.RedirectPermanentShouldBe("/api/values");
});
}
_.RedirectPermanentShouldBe("/api/values");
});
}

[Fact]
public async Task redirect_permanent_wrong_value()
{
var result = await Exception<ScenarioAssertionException>.ShouldBeThrownBy(async () =>
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();
await system.Scenario(_ =>
{
_.Get.Url("/auth/redirectpermanent");
Expand All @@ -91,7 +87,7 @@ public async Task redirect_permanent_non_permanent_result()
{
var result = await Exception<ScenarioAssertionException>.ShouldBeThrownBy(async () =>
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();
await system.Scenario(_ =>
{
_.Get.Url("/auth/redirect");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ public class customize_before_each_and_after_each
[Fact]
public async Task before_each_and_after_each_is_called()
{
await using var host = AlbaHost
.ForStartup<Startup>()
.BeforeEach(c =>
{
BeforeContext = c;
})
.AfterEach(c => AfterContext = c);
await using var host = await AlbaHost.For<Startup>();
host.BeforeEach(c =>
{
BeforeContext = c;
})
.AfterEach(c => AfterContext = c);

BeforeContext = AfterContext = null;

Expand Down
4 changes: 2 additions & 2 deletions src/Alba.Testing/Acceptance/data_binding_in_mvc_app.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class data_binding_in_mvc_app
[Fact]
public async Task can_bind_to_form_data()
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();

var input = new InputModel {
One = "one",
Expand All @@ -40,7 +40,7 @@ await system.Scenario(_ =>
[Fact]
public async Task can_bind_to_form_data_as_dictionary()
{
await using var system = AlbaHost.ForStartup<Startup>();
await using var system = await AlbaHost.For<Startup>();

var dict = new Dictionary<string, string> {{"One", "one"}, {"Two", "two"}, {"Three", "three"}};

Expand Down
19 changes: 12 additions & 7 deletions src/Alba.Testing/Acceptance/specs_against_aspnet_core_app.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@

namespace Alba.Testing.Acceptance
{
public class specs_against_aspnet_core_app : IDisposable
public class specs_against_aspnet_core_app : IAsyncLifetime
{
private readonly AlbaHost _system;
private IAlbaHost _system;

private Task<IScenarioResult> run(Action<Scenario> configuration)
{
return _system.Scenario(configuration);
}

public specs_against_aspnet_core_app()
{
_system = AlbaHost.ForStartup<Startup>();
}

public void Dispose()
{
_system?.Dispose();
Expand Down Expand Up @@ -386,5 +381,15 @@ public Task returns_successfully_when_passed_object_is_passed_to_Input()
_.ContentShouldContain("somevalue");
});
}

public async Task InitializeAsync()
{
_system = await AlbaHost.For<Startup>();
}

public async Task DisposeAsync()
{
await _system.DisposeAsync();
}
}
}
33 changes: 16 additions & 17 deletions src/Alba.Testing/Acceptance/using_custom_service_registrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,35 @@ public class using_custom_service_registrations
[Fact]
public async Task override_service_registration_in_bootstrapping()
{
ValuesController.LastWidget = new IWidget[0];
ValuesController.LastWidget = Array.Empty<IWidget>();

using (var system = AlbaHost.ForStartup<Startup>(builder =>
using var system = await AlbaHost.For<Startup>(builder =>
{
return builder.ConfigureServices((c, _) =>
builder.ConfigureServices((c, _) =>
{
_.AddTransient<IWidget, RedWidget>();
});
}))
{
ValuesController.LastWidget = null;
});

// The default registration is a GreenWidget
ValuesController.LastWidget = null;

await system.Scenario(_ =>
{

_.Put.Url("/api/values/foo").ContentType("application/json");
});
// The default registration is a GreenWidget

await system.Scenario(_ =>
{

_.Put.Url("/api/values/foo").ContentType("application/json");
});

ValuesController.LastWidget.Length.ShouldBe(2);
}
ValuesController.LastWidget.Length.ShouldBe(2);
}

[Fact]
public void can_request_services()
public async Task can_request_services()
{
using var system = AlbaHost.ForStartup<Startup>(builder =>
using var system = await AlbaHost.For<Startup>(builder =>
{
return builder.ConfigureServices((c, _) => { _.AddHttpContextAccessor(); });
builder.ConfigureServices((c, _) => { _.AddHttpContextAccessor(); });
});

var accessor1 = system.Services.GetService<IHttpContextAccessor>();
Expand Down
10 changes: 9 additions & 1 deletion src/Alba.Testing/ActivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@

namespace Alba.Testing;

public class ActivityTests
// activity listener cannot be tested in parallel with other tests
[CollectionDefinition(nameof(ActivityCollection), DisableParallelization = true)]
public class ActivityCollection
{

}

[Collection(nameof(ActivityCollection))]
public class ActivityTests
{
[Fact]
public async Task ActivityTagged_AsExpected()
Expand Down
17 changes: 8 additions & 9 deletions src/Alba.Testing/Alba.Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<DebugType>portable</DebugType>
<AssemblyName>Alba.Testing</AssemblyName>
<PackageId>Alba.Testing</PackageId>

</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Alba\Alba.csproj" />
<ProjectReference Include="..\IdentityServer\IdentityServer.csproj" />
<ProjectReference Include="..\IdentityServer.New\IdentityServer.New.csproj" />
<ProjectReference Include="..\WebAppSecuredWithJwt\WebAppSecuredWithJwt.csproj" />
<ProjectReference Include="..\WebApp\WebApp.csproj" />
<ProjectReference Include="..\WebApiAspNetCore3\WebApiStartupHostingModel.csproj" />
Expand All @@ -17,12 +17,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="NSubstitute" Version="4.4.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
1 change: 0 additions & 1 deletion src/Alba.Testing/Assertions/RedirectAssertionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Linq;
using Alba.Assertions;
using Baseline;
using Shouldly;
using Xunit;

Expand Down
4 changes: 2 additions & 2 deletions src/Alba.Testing/CrudeRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Baseline;
using Baseline.Reflection;
using JasperFx.Core;
using JasperFx.Core.Reflection;
using Microsoft.AspNetCore.Http;

namespace Alba.Testing
Expand Down
2 changes: 1 addition & 1 deletion src/Alba.Testing/FormDataExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Net;
using Baseline;
using JasperFx.Core;
using Microsoft.AspNetCore.Http;
using Shouldly;
using Xunit;
Expand Down
2 changes: 1 addition & 1 deletion src/Alba.Testing/Samples/Quickstart.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Baseline;
using JasperFx.Core;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down
2 changes: 1 addition & 1 deletion src/Alba.Testing/Security/IdentityServerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class IdentityServerFixture : IAsyncLifetime
public TestServer IdentityServer { get; set; }
public Task InitializeAsync()
{
IdentityServer = new WebApplicationFactory<IdentityServer.Program>().Server;
IdentityServer = new WebApplicationFactory<IdentityServer.New.Program>().Server;
return Task.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Alba.Security;
using IdentityServer;
using IdentityServer.New;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
Expand Down
2 changes: 1 addition & 1 deletion src/Alba.Testing/Security/OpenConnectUserPasswordTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using Alba.Security;
using IdentityServer;
using IdentityServer.New;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
Expand Down
2 changes: 1 addition & 1 deletion src/Alba.Testing/SpecificationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Baseline;
using JasperFx.Core;
using Shouldly;

namespace Alba.Testing
Expand Down
Loading
Loading