Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
james-hollinger committed Sep 9, 2024
2 parents 1db1ed4 + 41cd806 commit f18fdc0
Show file tree
Hide file tree
Showing 22 changed files with 1,965 additions and 166 deletions.
12 changes: 3 additions & 9 deletions backend/tools.do-work/DoWorkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ namespace DoWork;
using Pidp.Data;
using Pidp.Infrastructure.HttpClients.Keycloak;

public class DoWorkService : IDoWorkService
public class DoWorkService(IKeycloakAdministrationClient keycloakClient, PidpDbContext context) : IDoWorkService
{
private readonly IKeycloakAdministrationClient keycloakClient;
private readonly PidpDbContext context;

public DoWorkService(IKeycloakAdministrationClient keycloakClient, PidpDbContext context)
{
this.keycloakClient = keycloakClient;
this.context = context;
}
private readonly IKeycloakAdministrationClient keycloakClient = keycloakClient;
private readonly PidpDbContext context = context;

public async Task DoWorkAsync()
{
Expand Down
21 changes: 7 additions & 14 deletions backend/tools.do-work/HostedServiceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ namespace DoWork;
using Microsoft.Extensions.Logging;
using System.Diagnostics;

internal sealed class HostedServiceWrapper : IHostedService
internal sealed class HostedServiceWrapper(
IDoWorkService service,
IHostApplicationLifetime appLifetime,
ILogger<HostedServiceWrapper> logger) : IHostedService
{
private readonly IDoWorkService service;
private readonly IHostApplicationLifetime appLifetime;
private readonly ILogger logger;
private readonly IDoWorkService service = service;
private readonly IHostApplicationLifetime appLifetime = appLifetime;
private readonly ILogger logger = logger;
private int? exitCode;

public HostedServiceWrapper(
IDoWorkService service,
IHostApplicationLifetime appLifetime,
ILogger<HostedServiceWrapper> logger)
{
this.service = service;
this.appLifetime = appLifetime;
this.logger = logger;
}

public Task StartAsync(CancellationToken cancellationToken)
{
this.appLifetime.ApplicationStarted.Register(async () =>
Expand Down
25 changes: 20 additions & 5 deletions backend/webapi.tests/Features/AccessRequests/SAEforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ namespace PidpTests.Features.AccessRequests;
using Xunit;

using Pidp.Features.AccessRequests;
using Pidp.Infrastructure.Auth;
using Pidp.Infrastructure.HttpClients.Keycloak;
using Pidp.Infrastructure.HttpClients.Plr;
using Pidp.Models;
using PidpTests.TestingExtensions;

public class SAEformsTests : InMemoryDbTest
{
[Theory]
[MemberData(nameof(SAEformsIdentifierTypeTestData))]
public async void CreateSAEformsEnrolment_ValidProfileWithVaryingLicence_MatchesExcludedTypes(IdentifierType identifierType, bool expected)
public async Task CreateSAEformsEnrolment_ValidProfileWithVaryingLicence_MatchesExcludedTypes(IdentifierType identifierType, bool expected)
{
var party = this.TestDb.HasAParty(party =>
{
Expand All @@ -23,6 +25,10 @@ public async void CreateSAEformsEnrolment_ValidProfileWithVaryingLicence_Matches
party.Email = "[email protected]";
party.Phone = "5551234567";
party.Cpn = "Cpn";
party.Credentials = [
new Credential { UserId = Guid.NewGuid(), IdentityProvider = IdentityProviders.BCServicesCard},
new Credential { UserId = Guid.NewGuid(), IdentityProvider = IdentityProviders.BCProvider},
];
});
var client = A.Fake<IPlrClient>()
.ReturningAStandingsDigest(true, identifierType);
Expand All @@ -35,17 +41,26 @@ public async void CreateSAEformsEnrolment_ValidProfileWithVaryingLicence_Matches
Assert.Equal(expected, result.IsSuccess);
if (expected)
{
A.CallTo(() => keycloak.AssignAccessRoles(party.PrimaryUserId, MohKeycloakEnrolment.SAEforms)).MustHaveHappened();
foreach (var credential in party.Credentials)
{
A.CallTo(() => keycloak.AssignAccessRoles(credential.UserId, MohKeycloakEnrolment.SAEforms)).MustHaveHappened();
}
}
else
{
keycloak.AssertNoRolesAssigned();
}
}

public static IEnumerable<object[]> SAEformsIdentifierTypeTestData()
public static TheoryData<IdentifierType, bool> SAEformsIdentifierTypeTestData()
{
return TestData.AllIdentifierTypes
.Select(identifierType => new object[] { identifierType, !SAEforms.ExcludedIdentifierTypes.Contains(identifierType) });
var testData = new TheoryData<IdentifierType, bool>();

foreach (var identifierType in TestData.AllIdentifierTypes)
{
testData.Add(identifierType, !SAEforms.ExcludedIdentifierTypes.Contains(identifierType));
}

return testData;
}
}
Loading

0 comments on commit f18fdc0

Please sign in to comment.