Skip to content

Commit

Permalink
v.0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KSemenenko committed Aug 24, 2024
1 parent d2c7627 commit f408a40
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 42 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ jobs:
- name: List coverage files
run: ls '${{ github.workspace }}/coverage/'

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
with:
args: >
-Dsonar.organization=managedcode
-Dsonar.projectKey=managedcode_IntegrationTestBaseKit
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.cs.opencover.reportsPaths=${{ github.workspace }}/coverage/
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# - name: SonarCloud Scan
# uses: sonarsource/sonarcloud-github-action@master
# with:
# args: >
# -Dsonar.organization=managedcode
# -Dsonar.projectKey=managedcode_IntegrationTestBaseKit
# -Dsonar.token=${{ secrets.SONAR_TOKEN }}
# -Dsonar.cs.opencover.reportsPaths=${{ github.workspace }}/coverage/
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: NDepend
uses: ndepend/ndepend-action@v1
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: nuget

on:
push:
branches: [ main ]

jobs:
nuget-pack:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release

- name: Test
run: dotnet test --configuration Release

- name: Pack
run: dotnet pack --configuration Release -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg -o "packages"

- name: Push
run: dotnet nuget push "packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<RepositoryUrl>https://github.com/managedcode/IntegrationTestBaseKit</RepositoryUrl>
<PackageProjectUrl>https://github.com/managedcode/IntegrationTestBaseKit</PackageProjectUrl>
<Product>Managed Code - Communication</Product>
<Product>Managed Code - IntegrationTestBaseKit</Product>
<Version>0.0.1</Version>
<PackageVersion>0.0.1</PackageVersion>

Expand All @@ -36,9 +36,9 @@
<None Include="$(SolutionDir)\README.md" Pack="true" Visible="false" PackagePath="\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1">
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0"/>
<PackageReference Include="Testcontainers.Azurite" Version="3.9.0"/>
<PackageReference Include="Testcontainers.PostgreSql" Version="3.9.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Include="xunit" Version="2.9.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ManagedCode.IntegrationTestBaseKit.XUnit\ManagedCode.IntegrationTestBaseKit.XUnit.csproj"/>
<ProjectReference Include="..\ManagedCode.IntegrationTestBaseKit\ManagedCode.IntegrationTestBaseKit.csproj"/>
<ProjectReference Include="..\TestBlazorApp\TestBlazorApp.csproj"/>
</ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions ManagedCode.IntegrationTestBaseKit.Tests/SignalRTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using FluentAssertions;
using Microsoft.AspNetCore.SignalR.Client;
using Xunit.Abstractions;

namespace ManagedCode.IntegrationTestBaseKit.Tests;

[Collection(nameof(TestApp))]
public class SignalRTests(ITestOutputHelper log, TestApp testApplication)

Check warning on line 8 in ManagedCode.IntegrationTestBaseKit.Tests/SignalRTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Parameter 'log' is unread.

Check warning on line 8 in ManagedCode.IntegrationTestBaseKit.Tests/SignalRTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Parameter 'log' is unread.

Check warning on line 8 in ManagedCode.IntegrationTestBaseKit.Tests/SignalRTests.cs

View workflow job for this annotation

GitHub Actions / nuget-pack

Parameter 'log' is unread.

Check warning on line 8 in ManagedCode.IntegrationTestBaseKit.Tests/SignalRTests.cs

View workflow job for this annotation

GitHub Actions / nuget-pack

Parameter 'log' is unread.
{
[Fact]
public async Task HealthTest()
{
var client = testApplication.CreateSignalRClient("/");
await client.StartAsync();

client.State
.Should()
.Be(HubConnectionState.Connected);

var result = await client.InvokeAsync<string>("Health");
result.Should()
.Be("Healthy");
}
}
8 changes: 2 additions & 6 deletions ManagedCode.IntegrationTestBaseKit.Tests/TestApp.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using ManagedCode.IntegrationTestBaseKit.XUnit;
using TestBlazorApp;
using Testcontainers.Azurite;
using Testcontainers.PostgreSql;

namespace ManagedCode.IntegrationTestBaseKit.Tests;

[CollectionDefinition(nameof(TestApp))]
public class TestApp : BaseTestApp<Program>, ICollectionFixture<TestApp>, IAsyncLifetime
public class TestApp : BaseXUnitTestApp<Program>, ICollectionFixture<TestApp>
{
public async Task DisposeAsync()
{
await base.DisposeAsync();
}

protected override async Task ConfigureTestContainers()

Check warning on line 11 in ManagedCode.IntegrationTestBaseKit.Tests/TestApp.cs

View workflow job for this annotation

GitHub Actions / build-and-test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in ManagedCode.IntegrationTestBaseKit.Tests/TestApp.cs

View workflow job for this annotation

GitHub Actions / build-and-test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in ManagedCode.IntegrationTestBaseKit.Tests/TestApp.cs

View workflow job for this annotation

GitHub Actions / nuget-pack

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 11 in ManagedCode.IntegrationTestBaseKit.Tests/TestApp.cs

View workflow job for this annotation

GitHub Actions / nuget-pack

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
AddContainer(new AzuriteBuilder().Build());
Expand Down
12 changes: 12 additions & 0 deletions ManagedCode.IntegrationTestBaseKit.XUnit/BaseXUnitTestApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Xunit;

namespace ManagedCode.IntegrationTestBaseKit.XUnit;

public abstract class BaseXUnitTestApp<TEntryPoint> : BaseTestApp<TEntryPoint>, IAsyncLifetime
where TEntryPoint : class
{
async Task IAsyncLifetime.DisposeAsync()
{
await base.DisposeAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
</PropertyGroup>

<!--NuGet-->
<PropertyGroup>
<Title>ManagedCode.IntegrationTestBaseKit.XUnit</Title>
<PackageId>ManagedCode.IntegrationTestBaseKit.XUnit</PackageId>
<Description>Extensions for ASP.NET for managing Docker containers in integration tests.</Description>
<PackageTags>managedcode, docker, integration testing, asp.net, containers, testcontainers, csharp</PackageTags>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ManagedCode.IntegrationTestBaseKit\ManagedCode.IntegrationTestBaseKit.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.9.0"/>
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions ManagedCode.IntegrationTestBaseKit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.IntegrationTest
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestBlazorApp", "TestBlazorApp\TestBlazorApp.csproj", "{8841C369-320E-45F4-91C4-EA3BA5DA4E42}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{30D912A3-BD4B-45F6-89B4-4E5F8EE7AB0A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.IntegrationTestBaseKit.XUnit", "ManagedCode.IntegrationTestBaseKit.XUnit\ManagedCode.IntegrationTestBaseKit.XUnit.csproj", "{6891405A-B47B-46F1-A760-ED5B6EAF47DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +28,13 @@ Global
{8841C369-320E-45F4-91C4-EA3BA5DA4E42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8841C369-320E-45F4-91C4-EA3BA5DA4E42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8841C369-320E-45F4-91C4-EA3BA5DA4E42}.Release|Any CPU.Build.0 = Release|Any CPU
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6891405A-B47B-46F1-A760-ED5B6EAF47DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9ABD0D50-A2F4-4063-9E3F-A192C63F1919} = {30D912A3-BD4B-45F6-89B4-4E5F8EE7AB0A}
{8841C369-320E-45F4-91C4-EA3BA5DA4E42} = {30D912A3-BD4B-45F6-89B4-4E5F8EE7AB0A}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion ManagedCode.IntegrationTestBaseKit/BaseTestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace ManagedCode.IntegrationTestBaseKit;

public abstract class BaseTestApp<TEntryPoint> : WebApplicationFactory<TEntryPoint> where TEntryPoint : class
public abstract class BaseTestApp<TEntryPoint> : WebApplicationFactory<TEntryPoint>
where TEntryPoint : class
{
private IHost? _host;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>true</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<!--NuGet-->
<PropertyGroup>
<Title>ManagedCode.ManagedCode.IntegrationTestBaseKit</Title>
<PackageId>ManagedCode.ManagedCode.IntegrationTestBaseKit</PackageId>
<Description>Extensions for ASP.NET for managing Docker containers in integration tests.</Description>
<PackageTags>managedcode, docker, integration testing, asp.net, containers, testcontainers, csharp</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0"/>
<PackageReference Include="Microsoft.Playwright" Version="1.46.0"/>
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.11.0"/>
<PackageReference Include="Testcontainers" Version="3.9.0"/>
Expand Down
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ To install the library, use the following command:
dotnet add package ManagedCode.IntegrationTestBaseKit
```

for xUnit integration use the following command:
```sh
dotnet add package ManagedCode.ManagedCode.IntegrationTestBaseKit.XUnit
```

## Usage

Creating a Test Application
Define a TestApp class that inherits from `BaseTestApp<TestBlazorApp.Program>`, implements `ICollectionFixture<TestApp>`
and `IAsyncLifetime`.
Define a TestApp class that inherits from `BaseXUnitTestApp<TestBlazorApp.Program>`, add `ICollectionFixture<TestApp>`

```csharp
using DotNet.Testcontainers.Containers;
Expand All @@ -35,23 +39,13 @@ using Xunit;
namespace ManagedCode.IntegrationTestBaseKit.Tests
{
[CollectionDefinition(nameof(TestApp))]
public class TestApp : BaseTestApp<TestBlazorApp.Program>, ICollectionFixture<TestApp>, IAsyncLifetime
public class TestApp : BaseXUnitTestApp<TestBlazorApp.Program>, ICollectionFixture<TestApp>
{
protected override async Task ConfigureTestContainers()
{
AddContainer(new AzuriteBuilder().Build());
AddContainer("postgree", new PostgreSqlBuilder().Build());
}

public async Task DisposeAsync()
{
await base.DisposeAsync();
}

public async Task InitializeAsync()
{
// Initialization logic if needed
}
}
}
```
Expand Down
9 changes: 9 additions & 0 deletions TestBlazorApp/Hub/HealthHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TestBlazorApp.Hub;

public class HealthHub : Microsoft.AspNetCore.SignalR.Hub
{
public Task<string> Health()
{
return Task.FromResult("Healthy");
}
}
3 changes: 3 additions & 0 deletions TestBlazorApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using TestBlazorApp.Components;
using TestBlazorApp.Hub;

namespace TestBlazorApp;

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

app.MapHub<HealthHub>("/healthHub");

app.Run();
}
}
8 changes: 8 additions & 0 deletions TestBlazorApp/TestBlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="DotNet.ReproducibleBuilds" Version="1.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>

0 comments on commit f408a40

Please sign in to comment.