-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1831 from SkillsFundingAgency/APPMAN-1019-Add-LTM
APPMAN-1019 added LTM for selecting funding
- Loading branch information
Showing
10 changed files
with
232 additions
and
59 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...provals.Api.UnitTests/Controllers/SelectLevyConnection/WhenGettingSelectLevyConnection.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,57 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.Approvals.Api.Controllers; | ||
using SFA.DAS.Approvals.Application.LevyTransferMatching.Queries.GetApprovedAccountApplication; | ||
using SFA.DAS.Approvals.Application.SelectDirectTransferConnection.Queries; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.Approvals.Api.UnitTests.Controllers.SelectLevyConnection; | ||
|
||
public class WhenGettingSelectLevyConnection | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_Get_Returns_LevyConnections_From_Mediator( | ||
long accountId, | ||
GetAcceptedEmployerAccountApplicationsQueryResult mediatorResult, | ||
[Frozen] Mock<IMediator> mockMediator, | ||
[Greedy] SelectAcceptedLevyApplicationsController controller) | ||
{ | ||
mockMediator.Setup(mediator => mediator.Send( | ||
It.Is<GetAcceptedEmployerAccountApplicationsQuery>(x => x.EmployerAccountId == accountId), | ||
It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(mediatorResult); | ||
|
||
var controllerResult = await controller.Get(accountId) as ObjectResult; | ||
|
||
controllerResult.Should().NotBeNull(); | ||
controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK); | ||
var model = controllerResult.Value as GetAcceptedEmployerAccountApplicationsQueryResult; | ||
model.Should().NotBeNull(); | ||
model.Should().BeEquivalentTo(mediatorResult); | ||
} | ||
|
||
[Test, MoqAutoData] | ||
public async Task And_Exception_Then_Returns_Bad_Request( | ||
long accountId, | ||
[Frozen] Mock<IMediator> mockMediator, | ||
[Greedy] SelectAcceptedLevyApplicationsController controller) | ||
{ | ||
mockMediator | ||
.Setup(mediator => mediator.Send( | ||
It.IsAny<GetAcceptedEmployerAccountApplicationsQuery>(), | ||
It.IsAny<CancellationToken>())) | ||
.Throws<InvalidOperationException>(); | ||
|
||
var controllerResult = await controller.Get(accountId) as StatusCodeResult; | ||
|
||
controllerResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Approvals/SFA.DAS.Approvals.Api/Controllers/SelectAcceptedLevyApplicationsController.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,40 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using SFA.DAS.Approvals.Application.LevyTransferMatching.Queries.GetApprovedAccountApplication; | ||
|
||
namespace SFA.DAS.Approvals.Api.Controllers | ||
{ | ||
[ApiController] | ||
public class SelectAcceptedLevyApplicationsController : Controller | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ILogger<SelectAcceptedLevyApplicationsController> _logger; | ||
|
||
public SelectAcceptedLevyApplicationsController(IMediator mediator, ILogger<SelectAcceptedLevyApplicationsController> logger) | ||
{ | ||
_mediator = mediator; | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet] | ||
[Route("{accountId}/unapproved/add/select-funding/select-accepted-levy-connection")] | ||
public async Task<IActionResult> Get(long accountId) | ||
{ | ||
try | ||
{ | ||
_logger.LogInformation("Getting Levy Transfer Connections for Account {accountId}", accountId); | ||
var result = await _mediator.Send(new GetAcceptedEmployerAccountApplicationsQuery { EmployerAccountId = accountId}); | ||
return Ok(result); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Error when getting Levy Transfer Connections for Account {accountId}", accountId); | ||
return new StatusCodeResult((int) HttpStatusCode.InternalServerError); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...lectAcceptedEmployerAccountApplications/WhenGettingAcceptedEmployerAccountApplications.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,36 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.Approvals.Application.LevyTransferMatching.Queries.GetApprovedAccountApplication; | ||
using SFA.DAS.Approvals.InnerApi.Requests; | ||
using SFA.DAS.SharedOuterApi.Configuration; | ||
using SFA.DAS.SharedOuterApi.InnerApi.Responses.LevyTransferMatching; | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
using SFA.DAS.Testing.AutoFixture; | ||
|
||
namespace SFA.DAS.Approvals.UnitTests.Application.SelectAcceptedEmployerAccountApplications; | ||
|
||
public class WhenGettingAcceptedEmployerAccountApplications | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_The_Api_To_GetAcceptedEmployerAccountApplications_Returns_ExpectedValues( | ||
GetAcceptedEmployerAccountApplicationsQuery query, | ||
GetApplicationsResponse response, | ||
[Frozen] Mock<ILevyTransferMatchingApiClient<LevyTransferMatchingApiConfiguration>> client, | ||
GetAcceptedEmployerAccountApplicationsQueryHandler handler | ||
) | ||
{ | ||
client.Setup(x => | ||
x.Get<GetApplicationsResponse>( | ||
It.Is<GetAcceptedEmployerAccountPledgeApplicationsRequest>(x => | ||
x.EmployerAccountId == query.EmployerAccountId))) | ||
.ReturnsAsync(response); | ||
|
||
var actual = await handler.Handle(query, CancellationToken.None); | ||
|
||
actual.Applications.Should().BeEquivalentTo(response.Applications); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
...hing/Queries/GetApprovedAccountApplication/GetAcceptedEmployerAccountApplicationsQuery.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,9 @@ | ||
using MediatR; | ||
|
||
namespace SFA.DAS.Approvals.Application.LevyTransferMatching.Queries.GetApprovedAccountApplication | ||
{ | ||
public class GetAcceptedEmployerAccountApplicationsQuery : IRequest<GetAcceptedEmployerAccountApplicationsQueryResult> | ||
{ | ||
public long EmployerAccountId { get; set; } | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...eries/GetApprovedAccountApplication/GetAcceptedEmployerAccountApplicationsQueryHandler.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,33 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using SFA.DAS.Approvals.InnerApi.Requests; | ||
using SFA.DAS.SharedOuterApi.Configuration; | ||
using SFA.DAS.SharedOuterApi.InnerApi.Responses.LevyTransferMatching; | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
|
||
namespace SFA.DAS.Approvals.Application.LevyTransferMatching.Queries.GetApprovedAccountApplication | ||
{ | ||
public class GetAcceptedEmployerAccountApplicationsQueryHandler : IRequestHandler<GetAcceptedEmployerAccountApplicationsQuery, GetAcceptedEmployerAccountApplicationsQueryResult> | ||
{ | ||
private readonly ILevyTransferMatchingApiClient<LevyTransferMatchingApiConfiguration> _apiClient; | ||
|
||
public GetAcceptedEmployerAccountApplicationsQueryHandler(ILevyTransferMatchingApiClient<LevyTransferMatchingApiConfiguration> apiClient) | ||
{ | ||
_apiClient = apiClient; | ||
} | ||
|
||
public async Task<GetAcceptedEmployerAccountApplicationsQueryResult> Handle(GetAcceptedEmployerAccountApplicationsQuery request, CancellationToken cancellationToken) | ||
{ | ||
var result = await _apiClient.Get<GetApplicationsResponse>(new GetAcceptedEmployerAccountPledgeApplicationsRequest(request.EmployerAccountId)); | ||
|
||
if (result == null) | ||
return null; | ||
|
||
return new GetAcceptedEmployerAccountApplicationsQueryResult | ||
{ | ||
Applications = result.Applications | ||
}; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ueries/GetApprovedAccountApplication/GetAcceptedEmployerAccountApplicationsQueryResult.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,10 @@ | ||
using System.Collections.Generic; | ||
using SFA.DAS.SharedOuterApi.InnerApi.Responses.LevyTransferMatching; | ||
|
||
namespace SFA.DAS.Approvals.Application.LevyTransferMatching.Queries.GetApprovedAccountApplication | ||
{ | ||
public class GetAcceptedEmployerAccountApplicationsQueryResult | ||
{ | ||
public IEnumerable<GetApplicationsResponse.Application> Applications { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.