Skip to content

Commit f408a40

Browse files
committed
v.0.0.1
1 parent d2c7627 commit f408a40

15 files changed

+180
-42
lines changed

.github/workflows/dotnet.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ jobs:
4141
- name: List coverage files
4242
run: ls '${{ github.workspace }}/coverage/'
4343

44-
- name: SonarCloud Scan
45-
uses: sonarsource/sonarcloud-github-action@master
46-
with:
47-
args: >
48-
-Dsonar.organization=managedcode
49-
-Dsonar.projectKey=managedcode_IntegrationTestBaseKit
50-
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
51-
-Dsonar.cs.opencover.reportsPaths=${{ github.workspace }}/coverage/
52-
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
44+
# - name: SonarCloud Scan
45+
# uses: sonarsource/sonarcloud-github-action@master
46+
# with:
47+
# args: >
48+
# -Dsonar.organization=managedcode
49+
# -Dsonar.projectKey=managedcode_IntegrationTestBaseKit
50+
# -Dsonar.token=${{ secrets.SONAR_TOKEN }}
51+
# -Dsonar.cs.opencover.reportsPaths=${{ github.workspace }}/coverage/
52+
# env:
53+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5555

5656
- name: NDepend
5757
uses: ndepend/ndepend-action@v1

.github/workflows/nuget.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: nuget
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
nuget-pack:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup .NET
16+
uses: actions/setup-dotnet@v4
17+
with:
18+
dotnet-version: '8.0.x'
19+
20+
- name: Restore dependencies
21+
run: dotnet restore
22+
23+
- name: Build
24+
run: dotnet build --configuration Release
25+
26+
- name: Test
27+
run: dotnet test --configuration Release
28+
29+
- name: Pack
30+
run: dotnet pack --configuration Release -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg -o "packages"
31+
32+
- name: Push
33+
run: dotnet nuget push "packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

Directory.Build.props

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<RepositoryUrl>https://github.com/managedcode/IntegrationTestBaseKit</RepositoryUrl>
2525
<PackageProjectUrl>https://github.com/managedcode/IntegrationTestBaseKit</PackageProjectUrl>
26-
<Product>Managed Code - Communication</Product>
26+
<Product>Managed Code - IntegrationTestBaseKit</Product>
2727
<Version>0.0.1</Version>
2828
<PackageVersion>0.0.1</PackageVersion>
2929

@@ -36,9 +36,9 @@
3636
<None Include="$(SolutionDir)\README.md" Pack="true" Visible="false" PackagePath="\"/>
3737
</ItemGroup>
3838
<ItemGroup>
39-
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1">
39+
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.4">
4040
<PrivateAssets>all</PrivateAssets>
4141
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4242
</PackageReference>
4343
</ItemGroup>
44-
</Project>
44+
</Project>

ManagedCode.IntegrationTestBaseKit.Tests/ManagedCode.IntegrationTestBaseKit.Tests.csproj

+15-5
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,36 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
87
<IsPackable>false</IsPackable>
98
<IsTestProject>true</IsTestProject>
109
</PropertyGroup>
1110

1211
<ItemGroup>
13-
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
12+
<PackageReference Include="coverlet.collector" Version="6.0.2">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0"/>
1517
<PackageReference Include="Testcontainers.Azurite" Version="3.9.0"/>
1618
<PackageReference Include="Testcontainers.PostgreSql" Version="3.9.0"/>
17-
<PackageReference Include="xunit" Version="2.5.3"/>
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
19+
<PackageReference Include="xunit" Version="2.9.0"/>
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
1924
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
25+
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.4">
26+
<PrivateAssets>all</PrivateAssets>
27+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
28+
</PackageReference>
2029
</ItemGroup>
2130

2231
<ItemGroup>
2332
<Using Include="Xunit"/>
2433
</ItemGroup>
2534

2635
<ItemGroup>
36+
<ProjectReference Include="..\ManagedCode.IntegrationTestBaseKit.XUnit\ManagedCode.IntegrationTestBaseKit.XUnit.csproj"/>
2737
<ProjectReference Include="..\ManagedCode.IntegrationTestBaseKit\ManagedCode.IntegrationTestBaseKit.csproj"/>
2838
<ProjectReference Include="..\TestBlazorApp\TestBlazorApp.csproj"/>
2939
</ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using FluentAssertions;
2+
using Microsoft.AspNetCore.SignalR.Client;
3+
using Xunit.Abstractions;
4+
5+
namespace ManagedCode.IntegrationTestBaseKit.Tests;
6+
7+
[Collection(nameof(TestApp))]
8+
public class SignalRTests(ITestOutputHelper log, TestApp testApplication)
9+
{
10+
[Fact]
11+
public async Task HealthTest()
12+
{
13+
var client = testApplication.CreateSignalRClient("/");
14+
await client.StartAsync();
15+
16+
client.State
17+
.Should()
18+
.Be(HubConnectionState.Connected);
19+
20+
var result = await client.InvokeAsync<string>("Health");
21+
result.Should()
22+
.Be("Healthy");
23+
}
24+
}

ManagedCode.IntegrationTestBaseKit.Tests/TestApp.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1+
using ManagedCode.IntegrationTestBaseKit.XUnit;
12
using TestBlazorApp;
23
using Testcontainers.Azurite;
34
using Testcontainers.PostgreSql;
45

56
namespace ManagedCode.IntegrationTestBaseKit.Tests;
67

78
[CollectionDefinition(nameof(TestApp))]
8-
public class TestApp : BaseTestApp<Program>, ICollectionFixture<TestApp>, IAsyncLifetime
9+
public class TestApp : BaseXUnitTestApp<Program>, ICollectionFixture<TestApp>
910
{
10-
public async Task DisposeAsync()
11-
{
12-
await base.DisposeAsync();
13-
}
14-
1511
protected override async Task ConfigureTestContainers()
1612
{
1713
AddContainer(new AzuriteBuilder().Build());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
namespace ManagedCode.IntegrationTestBaseKit.XUnit;
4+
5+
public abstract class BaseXUnitTestApp<TEntryPoint> : BaseTestApp<TEntryPoint>, IAsyncLifetime
6+
where TEntryPoint : class
7+
{
8+
async Task IAsyncLifetime.DisposeAsync()
9+
{
10+
await base.DisposeAsync();
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>true</IsPackable>
8+
</PropertyGroup>
9+
10+
<!--NuGet-->
11+
<PropertyGroup>
12+
<Title>ManagedCode.IntegrationTestBaseKit.XUnit</Title>
13+
<PackageId>ManagedCode.IntegrationTestBaseKit.XUnit</PackageId>
14+
<Description>Extensions for ASP.NET for managing Docker containers in integration tests.</Description>
15+
<PackageTags>managedcode, docker, integration testing, asp.net, containers, testcontainers, csharp</PackageTags>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\ManagedCode.IntegrationTestBaseKit\ManagedCode.IntegrationTestBaseKit.csproj"/>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="xunit" Version="2.9.0"/>
24+
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.4">
25+
<PrivateAssets>all</PrivateAssets>
26+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
27+
</PackageReference>
28+
</ItemGroup>
29+
30+
</Project>

ManagedCode.IntegrationTestBaseKit.sln

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.IntegrationTest
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestBlazorApp", "TestBlazorApp\TestBlazorApp.csproj", "{8841C369-320E-45F4-91C4-EA3BA5DA4E42}"
88
EndProject
9+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{30D912A3-BD4B-45F6-89B4-4E5F8EE7AB0A}"
10+
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.IntegrationTestBaseKit.XUnit", "ManagedCode.IntegrationTestBaseKit.XUnit\ManagedCode.IntegrationTestBaseKit.XUnit.csproj", "{6891405A-B47B-46F1-A760-ED5B6EAF47DF}"
12+
EndProject
913
Global
1014
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1115
Debug|Any CPU = Debug|Any CPU
@@ -24,5 +28,13 @@ Global
2428
{8841C369-320E-45F4-91C4-EA3BA5DA4E42}.Debug|Any CPU.Build.0 = Debug|Any CPU
2529
{8841C369-320E-45F4-91C4-EA3BA5DA4E42}.Release|Any CPU.ActiveCfg = Release|Any CPU
2630
{8841C369-320E-45F4-91C4-EA3BA5DA4E42}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Release|Any CPU.Build.0 = Release|Any CPU
35+
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{9ABD0D50-A2F4-4063-9E3F-A192C63F1919} = {30D912A3-BD4B-45F6-89B4-4E5F8EE7AB0A}
38+
{8841C369-320E-45F4-91C4-EA3BA5DA4E42} = {30D912A3-BD4B-45F6-89B4-4E5F8EE7AB0A}
2739
EndGlobalSection
2840
EndGlobal

ManagedCode.IntegrationTestBaseKit/BaseTestApp.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace ManagedCode.IntegrationTestBaseKit;
1313

14-
public abstract class BaseTestApp<TEntryPoint> : WebApplicationFactory<TEntryPoint> where TEntryPoint : class
14+
public abstract class BaseTestApp<TEntryPoint> : WebApplicationFactory<TEntryPoint>
15+
where TEntryPoint : class
1516
{
1617
private IHost? _host;
1718

ManagedCode.IntegrationTestBaseKit/ManagedCode.IntegrationTestBaseKit.csproj

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
87
<IsPackable>true</IsPackable>
9-
<IsTestProject>true</IsTestProject>
8+
</PropertyGroup>
9+
10+
<!--NuGet-->
11+
<PropertyGroup>
12+
<Title>ManagedCode.ManagedCode.IntegrationTestBaseKit</Title>
13+
<PackageId>ManagedCode.ManagedCode.IntegrationTestBaseKit</PackageId>
14+
<Description>Extensions for ASP.NET for managing Docker containers in integration tests.</Description>
15+
<PackageTags>managedcode, docker, integration testing, asp.net, containers, testcontainers, csharp</PackageTags>
1016
</PropertyGroup>
1117

1218
<ItemGroup>
1319
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8"/>
1420
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8"/>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0"/>
1622
<PackageReference Include="Microsoft.Playwright" Version="1.46.0"/>
1723
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.11.0"/>
1824
<PackageReference Include="Testcontainers" Version="3.9.0"/>

README.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ To install the library, use the following command:
2020
dotnet add package ManagedCode.IntegrationTestBaseKit
2121
```
2222

23+
for xUnit integration use the following command:
24+
```sh
25+
dotnet add package ManagedCode.ManagedCode.IntegrationTestBaseKit.XUnit
26+
```
27+
2328
## Usage
2429

2530
Creating a Test Application
26-
Define a TestApp class that inherits from `BaseTestApp<TestBlazorApp.Program>`, implements `ICollectionFixture<TestApp>`
27-
and `IAsyncLifetime`.
31+
Define a TestApp class that inherits from `BaseXUnitTestApp<TestBlazorApp.Program>`, add `ICollectionFixture<TestApp>`
2832

2933
```csharp
3034
using DotNet.Testcontainers.Containers;
@@ -35,23 +39,13 @@ using Xunit;
3539
namespace ManagedCode.IntegrationTestBaseKit.Tests
3640
{
3741
[CollectionDefinition(nameof(TestApp))]
38-
public class TestApp : BaseTestApp<TestBlazorApp.Program>, ICollectionFixture<TestApp>, IAsyncLifetime
42+
public class TestApp : BaseXUnitTestApp<TestBlazorApp.Program>, ICollectionFixture<TestApp>
3943
{
4044
protected override async Task ConfigureTestContainers()
4145
{
4246
AddContainer(new AzuriteBuilder().Build());
4347
AddContainer("postgree", new PostgreSqlBuilder().Build());
4448
}
45-
46-
public async Task DisposeAsync()
47-
{
48-
await base.DisposeAsync();
49-
}
50-
51-
public async Task InitializeAsync()
52-
{
53-
// Initialization logic if needed
54-
}
5549
}
5650
}
5751
```

TestBlazorApp/Hub/HealthHub.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TestBlazorApp.Hub;
2+
3+
public class HealthHub : Microsoft.AspNetCore.SignalR.Hub
4+
{
5+
public Task<string> Health()
6+
{
7+
return Task.FromResult("Healthy");
8+
}
9+
}

TestBlazorApp/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
22
using Microsoft.Extensions.Diagnostics.HealthChecks;
33
using TestBlazorApp.Components;
4+
using TestBlazorApp.Hub;
45

56
namespace TestBlazorApp;
67

@@ -41,6 +42,8 @@ public static void Main(string[] args)
4142
Predicate = r => r.Tags.Contains("live")
4243
});
4344

45+
app.MapHub<HealthHub>("/healthHub");
46+
4447
app.Run();
4548
}
4649
}

TestBlazorApp/TestBlazorApp.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

10+
<ItemGroup>
11+
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.4">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
</ItemGroup>
16+
917
</Project>

0 commit comments

Comments
 (0)