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

Infra/DPPB-945 Integration tests #242

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 44 additions & 2 deletions .github/workflows/build_feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ jobs:
contents: read
packages: read
actions: read
services:
postgres:
image: postgres:14
ports:
- 5432:5432
env:
POSTGRES_USER: ${{ secrets.INTEGRATION_TEST_DB_USER }}
POSTGRES_PASSWORD: ${{ secrets.INTEGRATION_TEST_DB_PASSWORD }}
POSTGRES_DB: ${{ secrets.INTEGRATION_TEST_DB_NAME }}
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -31,15 +45,43 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.x'

- name: Install EF Core Tools
run: dotnet tool install --global dotnet-ef --version 6.0.0

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --verbosity normal
- name: Unit tests
run: |
pushd Src/Dft.DTRO.Tests
dotnet test --verbosity normal
popd

- name: Wait for PostgreSQL to be ready
run: |
for i in {1..10}; do
if pg_isready -h localhost -p 5432 -U postgres; then
echo "PostgreSQL is ready"
break
fi
echo "Waiting for PostgreSQL..."
sleep 5
done

- name: Integration tests
env:
ConnectionStrings__DefaultConnection: "Host=localhost;Port=5432;Database=${{ secrets.INTEGRATION_TEST_DB_NAME }};Username=${{ secrets.INTEGRATION_TEST_DB_USER }};Password=${{ secrets.INTEGRATION_TEST_DB_PASSWORD }}"
run: |
pushd Src/DfT.DTRO
dotnet ef database update
popd
pushd Src/DfT.DTRO.IntegrationTests
dotnet test
popd

- name: Format check
run: dotnet format
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
/Src/DfT.DTRO/.vs/DfT.DTRO/xs/project-cache/DfT.DTRO-Debug.json
/Src/DfT.DTRO/.vs/
/Src/DfT.DTRO/.vs/DfT.DTRO/xs/UserPrefs.xml
/Src/DfT.DTRO.IntegrationTests/bin/
/Src/DfT.DTRO.IntegrationTests/obj/

/Src/Dft.DTRO.Admin/obj/Debug/net6.0/ref/Dft.DTRO.Admin.dll
/Src/Dft.DTRO.Admin/bin/Debug/net6.0/Dft.DTRO.Admin.dll
Expand Down
20 changes: 20 additions & 0 deletions Src/DfT.DTRO.IntegrationTests/DfT.DTRO.IntegrationTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../DfT.DTRO/DfT.DTRO.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Mvc.Testing;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
using System;
using Microsoft.Extensions.DependencyInjection;
using DfT.DTRO.DAL;
using Microsoft.EntityFrameworkCore;

namespace DfT.DTRO.IntegrationTests.DtroUsersIntegrationTests
{
public class DtroUsersIntegrationTests : IClassFixture<WebApplicationFactory<DfT.DTRO.Startup>>
{
private readonly WebApplicationFactory<DfT.DTRO.Startup> _factory;
private readonly string _url;

public DtroUsersIntegrationTests(WebApplicationFactory<DfT.DTRO.Startup> factory)
{
_factory = factory;
_url = "/dtroUsers";

using (var scope = _factory.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<DtroContext>();
dbContext.Database.Migrate();
}
}

[Fact]
public async Task Test_No_X_App_Id_Returns_500()
{
var client = _factory.CreateClient();
var request = new HttpRequestMessage(HttpMethod.Get, _url);
var response = await client.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
Assert.Contains("Middleware, access denied: x-App-Id", responseBody);
}
}
}
Loading