-
Notifications
You must be signed in to change notification settings - Fork 4
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 #725 from SkillsFundingAgency/CV-629-ChangeOfParty…
…-ViewDetails Cv 629 change of party view details
- Loading branch information
Showing
30 changed files
with
635 additions
and
59 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
22 changes: 22 additions & 0 deletions
22
...mmitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using SFA.DAS.CommitmentsV2.Types; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
{ | ||
public class GetChangeOfPartyRequestsResponse | ||
{ | ||
public IReadOnlyCollection<ChangeOfPartyRequest> ChangeOfPartyRequests { get; set; } | ||
|
||
public class ChangeOfPartyRequest | ||
{ | ||
public long Id { get; set; } | ||
public ChangeOfPartyRequestType ChangeOfPartyType { get; set; } | ||
public Party OriginatingParty { get; set; } | ||
public ChangeOfPartyRequestStatus Status { get; set; } | ||
public string EmployerName { get; set; } | ||
public DateTime StarDate { get; set; } | ||
public int Price { 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
72 changes: 72 additions & 0 deletions
72
...A.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.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,72 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using MediatR; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Controllers; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Requests; | ||
using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests | ||
{ | ||
[TestFixture] | ||
public class CreateTests | ||
{ | ||
private CreateTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new CreateTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task PostChangeOfPartyRequest() | ||
{ | ||
await _fixture.PostChangeOfPartyRequest(); | ||
_fixture.VerifyPost(); | ||
} | ||
|
||
private class CreateTestsFixture | ||
{ | ||
private readonly Mock<IMediator> _mediator; | ||
private readonly Mock<IModelMapper> _mapper; | ||
private readonly ChangeOfPartyController _controller; | ||
|
||
private readonly Fixture _autoFixture; | ||
private readonly long _apprenticeshipId; | ||
private readonly CreateChangeOfPartyRequestRequest _postRequest; | ||
|
||
public CreateTestsFixture() | ||
{ | ||
_mediator = new Mock<IMediator>(); | ||
_mapper = new Mock<IModelMapper>(); | ||
|
||
_autoFixture = new Fixture(); | ||
_apprenticeshipId = _autoFixture.Create<long>(); | ||
_postRequest = _autoFixture.Create<CreateChangeOfPartyRequestRequest>(); | ||
|
||
_controller = new ChangeOfPartyController(_mediator.Object, _mapper.Object); | ||
} | ||
|
||
public async Task PostChangeOfPartyRequest() | ||
{ | ||
await _controller.CreateChangeOfPartyRequest(_apprenticeshipId, _postRequest); | ||
} | ||
|
||
public void VerifyPost() | ||
{ | ||
_mediator.Verify( | ||
m => m.Send( | ||
It.Is<CreateChangeOfPartyRequestCommand>(p => | ||
p.ApprenticeshipId == _apprenticeshipId && | ||
p.ChangeOfPartyRequestType == _postRequest.ChangeOfPartyRequestType && | ||
p.NewPartyId == _postRequest.NewPartyId && p.NewStartDate == _postRequest.NewStartDate && | ||
p.NewPrice == _postRequest.NewPrice && p.UserInfo == _postRequest.UserInfo), | ||
It.IsAny<CancellationToken>()), Times.Once); | ||
} | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...A.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.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,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Api.Controllers; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Requests; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests | ||
{ | ||
[TestFixture] | ||
public class GetAllTests | ||
{ | ||
private GetAllTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void Arrange() | ||
{ | ||
_fixture = new GetAllTestsFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task GetAll() | ||
{ | ||
await _fixture.GetAll(); | ||
_fixture.VerifyResult(); | ||
} | ||
|
||
private class GetAllTestsFixture | ||
{ | ||
private readonly Mock<IMediator> _mediator; | ||
private readonly Mock<IModelMapper> _mapper; | ||
private readonly ChangeOfPartyController _controller; | ||
private readonly GetChangeOfPartyRequestsQueryResult _queryResult; | ||
private readonly GetChangeOfPartyRequestsResponse _mapperResult; | ||
|
||
private IActionResult _result; | ||
|
||
private readonly Fixture _autoFixture; | ||
private readonly long _apprenticeshipId; | ||
|
||
public GetAllTestsFixture() | ||
{ | ||
_mediator = new Mock<IMediator>(); | ||
_mapper = new Mock<IModelMapper>(); | ||
|
||
_queryResult = new GetChangeOfPartyRequestsQueryResult(); | ||
_mapperResult = new GetChangeOfPartyRequestsResponse(); | ||
|
||
_autoFixture = new Fixture(); | ||
|
||
_mediator.Setup(x => | ||
x.Send(It.Is<GetChangeOfPartyRequestsQuery>(q => q.ApprenticeshipId == _apprenticeshipId), | ||
It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(_queryResult); | ||
|
||
_mapper.Setup(x => x.Map<GetChangeOfPartyRequestsResponse>(_queryResult)).ReturnsAsync(_mapperResult); | ||
|
||
_apprenticeshipId = _autoFixture.Create<long>(); | ||
|
||
_controller = new ChangeOfPartyController(_mediator.Object, _mapper.Object); | ||
} | ||
|
||
public async Task GetAll() | ||
{ | ||
_result = await _controller.GetAll(_apprenticeshipId); | ||
} | ||
|
||
public void VerifyResult() | ||
{ | ||
Assert.IsNotNull(_result); | ||
var okObject = _result as OkObjectResult; | ||
Assert.IsNotNull(okObject); | ||
var objectValue = okObject.Value as GetChangeOfPartyRequestsResponse; | ||
Assert.IsNotNull(objectValue); | ||
|
||
Assert.AreEqual(_mapperResult, objectValue); | ||
} | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.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,52 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Requests; | ||
using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest; | ||
using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; | ||
using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.Controllers | ||
{ | ||
[ApiController] | ||
[Authorize] | ||
[Route("api/apprenticeships/{apprenticeshipId}/change-of-party-requests")] | ||
public class ChangeOfPartyController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly IModelMapper _modelMapper; | ||
|
||
public ChangeOfPartyController(IMediator mediator, IModelMapper modelMapper) | ||
{ | ||
_mediator = mediator; | ||
_modelMapper = modelMapper; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetAll(long apprenticeshipId, CancellationToken cancellationToken = default) | ||
{ | ||
var result = await _mediator.Send(new GetChangeOfPartyRequestsQuery(apprenticeshipId), cancellationToken); | ||
var response = await _modelMapper.Map<GetChangeOfPartyRequestsResponse>(result); | ||
return Ok(response); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
await _mediator.Send(new CreateChangeOfPartyRequestCommand | ||
{ | ||
ApprenticeshipId = apprenticeshipId, | ||
ChangeOfPartyRequestType = request.ChangeOfPartyRequestType, | ||
NewPartyId = request.NewPartyId, | ||
NewStartDate = request.NewStartDate, | ||
NewPrice = request.NewPrice, | ||
UserInfo = request.UserInfo | ||
}, cancellationToken); | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.