-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from DFE-Digital/task/190887-project-integrati…
…on-tests task/190887-project-integration-tests
- Loading branch information
Showing
15 changed files
with
151 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Dfe.Complete.Application/Projects/EventHandlers/ProjectCreatedEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Microsoft.Extensions.DependencyInjection.Projects.EventHandlers; | ||
|
||
public class ProjectCreatedEventHandler | ||
{ | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/Tests/Dfe.Complete.Api.Tests.Integration/Controllers/ProjectsControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Net; | ||
using Dfe.Complete.Client.Contracts; | ||
using Dfe.Complete.Tests.Common.Customizations; | ||
using Dfe.Complete.Tests.Common.Customizations.Commands; | ||
using DfE.CoreLibs.Testing.AutoFixture.Attributes; | ||
using DfE.CoreLibs.Testing.Mocks.WebApplicationFactory; | ||
|
||
namespace Dfe.Complete.Api.Tests.Integration.Controllers; | ||
|
||
public class ProjectsControllerTests | ||
{ | ||
[Theory] | ||
[CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization), | ||
typeof(CreateConversionProjectCommandCustomization))] | ||
public async Task CreateProject_Async_ShouldCreateConversionProject( | ||
CustomWebApplicationDbContextFactory<Program> factory, | ||
CreateConversionProjectCommand createConversionProjectCommand, | ||
ICreateProjectClient createProjectClient) | ||
{ | ||
//todo: when auth is done, add this back in | ||
// factory.TestClaims = [new Claim(ClaimTypes.Role, "API.Write")]; | ||
|
||
var result = await createProjectClient.Projects_CreateProject_Async(createConversionProjectCommand); | ||
|
||
Assert.NotNull(result); | ||
Assert.IsType<ProjectId>(result); | ||
} | ||
|
||
[Theory] | ||
[CustomAutoData(typeof(CustomWebApplicationDbContextFactoryCustomization))] | ||
public async Task CreateProject_WithNullRequest_ThrowsException( | ||
CustomWebApplicationDbContextFactory<Program> factory, | ||
CreateConversionProjectCommand createConversionProjectCommand, | ||
ICreateProjectClient createProjectClient) | ||
{ | ||
//todo: when auth is done, add this back in | ||
// factory.TestClaims = [new Claim(ClaimTypes.Role, "API.Write")]; | ||
|
||
createConversionProjectCommand.Urn = null; | ||
|
||
|
||
//todo: change exception type? | ||
var exception = await Assert.ThrowsAsync<PersonsApiException>(async () => | ||
await createProjectClient.Projects_CreateProject_Async(createConversionProjectCommand)); | ||
|
||
Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)exception.StatusCode); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...plete.Tests.Common/Customizations/Commands/CreateConversionProjectCommandCustomization.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using AutoFixture; | ||
using Dfe.Complete.Application.Projects.Commands.CreateProject; | ||
using Dfe.Complete.Domain.ValueObjects; | ||
using Dfe.Complete.Domain.Enums; | ||
|
||
namespace Dfe.Complete.Tests.Common.Customizations.Commands | ||
{ | ||
public class CreateConversionProjectCommandCustomization : ICustomization | ||
{ | ||
public void Customize(IFixture fixture) | ||
{ | ||
fixture.Customize<CreateConversionProjectCommand>(composer => composer.FromFactory(() => | ||
{ | ||
var urn = new Urn(fixture.Create<int>()); | ||
var significantDate = fixture.Create<DateOnly>(); | ||
var isSignificantDateProvisional = fixture.Create<bool>(); | ||
var incomingTrustUkprn = new Ukprn(fixture.Create<int>()); | ||
var region = fixture.Create<Region>(); | ||
var isDueTo2Ri = fixture.Create<bool>(); | ||
var hasAcademyOrderBeenIssued = fixture.Create<bool>(); | ||
var advisoryBoardDate = fixture.Create<DateOnly>(); | ||
var advisoryBoardConditions = fixture.Create<string>(); | ||
var establishmentSharepointLink = fixture.Create<Uri>().ToString(); | ||
var incomingTrustSharepointLink = fixture.Create<Uri>().ToString(); | ||
|
||
return new CreateConversionProjectCommand( | ||
urn, | ||
significantDate, | ||
isSignificantDateProvisional, | ||
incomingTrustUkprn, | ||
region, | ||
isDueTo2Ri, | ||
hasAcademyOrderBeenIssued, | ||
advisoryBoardDate, | ||
advisoryBoardConditions, | ||
establishmentSharepointLink, | ||
incomingTrustSharepointLink | ||
); | ||
})); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/Tests/Dfe.Complete.Tests.Common/Seeders/CompleteContextSeeder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Dfe.Complete.Tests.Common.Seeders; | ||
|
||
public class CompleteContextSeeder | ||
{ | ||
//TODO: implement when needed | ||
} |