-
Notifications
You must be signed in to change notification settings - Fork 3
Pv2 2849 apprenticeship statistics api endpoint #1034
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
Open
AkshayBanifatsyevichChugh
wants to merge
20
commits into
master
Choose a base branch
from
PV2-2849_ApprenticeshipStatisticsApiEndpoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
145d5fe
PV2-2849 draft controller + endpoint
AkshayBanifatsyevichChugh e3b6ac9
PV2-2849 initial GetApprenticeshipStatistics query added
AkshayBanifatsyevichChugh 8cf2d0a
PV2-2849 GetApprenticeshipStatisticsResponse api response dto
AkshayBanifatsyevichChugh a6cdf1d
PV2-2849 initial controller logic
AkshayBanifatsyevichChugh 612b5da
PV2-2849 ApprenticeshipStatisticsController GetStatistics action impl…
AkshayBanifatsyevichChugh 62f587f
PV2-2849 more GetApprenticeshipStatisticsQuery code
AkshayBanifatsyevichChugh 118c1f3
PV2-2849 extended existing ApprenticeshipStatusSummaryService
AkshayBanifatsyevichChugh 78dd62b
PV2-2849 GetApprenticeshipStatisticsQueryHandler implementation
AkshayBanifatsyevichChugh bbb573e
PV2-2849 Mapper implementation
AkshayBanifatsyevichChugh 66713c3
PV2-2849 controller empty line removed
AkshayBanifatsyevichChugh 99a65ec
PV2-2849 renamed response properties
AkshayBanifatsyevichChugh c47a7b2
PV2-2849 correcting GetApprenticeshipStatisticsFor method
AkshayBanifatsyevichChugh 47ab1d0
PV2-2849 controller final implementation + unit tests
AkshayBanifatsyevichChugh c3a986e
PV2-2849 GetApprenticeshipStatisticsQueryValidator unit tests
AkshayBanifatsyevichChugh 56dc480
PV2-2849 GetApprenticeshipStatisticsHandler unit tests
AkshayBanifatsyevichChugh fd15490
PV2-2849 ApprenticeshipStatisticsController unit tests amended
AkshayBanifatsyevichChugh 4581629
PV2-2849 GetApprenticeshipStatisticsResponseMapper unit tests
AkshayBanifatsyevichChugh b86507c
PV2-2849 WhenGettingApprenticeshipStatistics additional unit tests
AkshayBanifatsyevichChugh 619c5e4
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-c…
AkshayBanifatsyevichChugh 35ac13d
PV2-2849 ApprenticeshipStatusSummaryService now awaiting each query
AkshayBanifatsyevichChugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...tmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetApprenticeshipStatisticsResponse.cs
This file contains hidden or 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,13 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
| { | ||
| public class GetApprenticeshipStatisticsResponse | ||
| { | ||
| public long Approved { get; set; } | ||
| public long Paused { get; set; } | ||
| public long Stopped { get; set; } | ||
| } | ||
| } |
101 changes: 101 additions & 0 deletions
101
...FA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipStatisticsControllerTests.cs
This file contains hidden or 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,101 @@ | ||
| using FluentAssertions; | ||
| using MediatR; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Moq; | ||
| using NUnit.Framework; | ||
| using SFA.DAS.CommitmentsV2.Api.Controllers; | ||
| using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
| using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipStatistics; | ||
| using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using AutoFixture; | ||
|
|
||
| namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers | ||
| { | ||
| [TestFixture] | ||
| public class ApprenticeshipStatisticsControllerTests | ||
| { | ||
| private Fixture _fixture; | ||
| private int _lastNumberOfDays; | ||
| private Mock<IMediator> _mediatorMock; | ||
| private Mock<IModelMapper> _modelMapperMock; | ||
| private GetApprenticeshipStatisticsQueryResult _getApprenticeshipStatisticsQueryResult; | ||
| private GetApprenticeshipStatisticsResponse _getApprenticeshipStatisticsResponse; | ||
| private ApprenticeshipStatisticsController _sut; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _fixture = new Fixture(); | ||
| _lastNumberOfDays = _fixture.Create<int>(); | ||
| _mediatorMock = new Mock<IMediator>(); | ||
| _modelMapperMock = new Mock<IModelMapper>(); | ||
| _getApprenticeshipStatisticsQueryResult = _fixture.Freeze<GetApprenticeshipStatisticsQueryResult>(); | ||
| _getApprenticeshipStatisticsResponse = _fixture.Freeze<GetApprenticeshipStatisticsResponse>(); | ||
|
|
||
| _sut = new ApprenticeshipStatisticsController(_mediatorMock.Object, _modelMapperMock.Object); | ||
|
|
||
| _mediatorMock | ||
| .Setup(x => x.Send(It.Is<GetApprenticeshipStatisticsQuery>(x => x.LastNumberOfDays == _lastNumberOfDays), | ||
| CancellationToken.None)) | ||
| .ReturnsAsync(_getApprenticeshipStatisticsQueryResult); | ||
|
|
||
| _modelMapperMock | ||
| .Setup(x => x.Map<GetApprenticeshipStatisticsResponse>(_getApprenticeshipStatisticsQueryResult)) | ||
| .ReturnsAsync(_getApprenticeshipStatisticsResponse); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task WhenCallingGetStatistics_ThenSendsMediatorQueryCorrectly() | ||
| { | ||
| //Act | ||
| await _sut.GetStatistics(_lastNumberOfDays); | ||
|
|
||
| //Assert | ||
| _mediatorMock.Verify(x => x.Send(It.Is<GetApprenticeshipStatisticsQuery>(x => x.LastNumberOfDays == _lastNumberOfDays), default), Times.Once); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task WhenCallingGetStatistics_AndQueryReturnsNull_ThenReturnsNotFound() | ||
| { | ||
| //Arrange | ||
| _mediatorMock | ||
| .Setup(x => x.Send( | ||
| It.Is<GetApprenticeshipStatisticsQuery>(x => x.LastNumberOfDays == _lastNumberOfDays), | ||
| CancellationToken.None)) | ||
| .Returns(Task.FromResult<GetApprenticeshipStatisticsQueryResult>(null)); | ||
|
|
||
| //Act | ||
| var result = await _sut.GetStatistics(_lastNumberOfDays); | ||
|
|
||
| //Assert | ||
| Assert.True(result is NotFoundResult); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task WhenCallingGetStatistics_ThenMapsResultToResponseDto() | ||
| { | ||
| //Act | ||
| var result = await _sut.GetStatistics(_lastNumberOfDays); | ||
|
|
||
| //Assert | ||
| _modelMapperMock.Verify(x => x.Map<GetApprenticeshipStatisticsResponse>(_getApprenticeshipStatisticsQueryResult)); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task WhenCallingGetStatistics_ThenGeneratesOkResponse() | ||
| { | ||
| //Act | ||
| var result = await _sut.GetStatistics(_lastNumberOfDays) as OkObjectResult; | ||
| var resultResponse = result?.Value as GetApprenticeshipStatisticsResponse; | ||
|
|
||
| //Assert | ||
| result.Should().NotBeNull(); | ||
| resultResponse.Should().NotBeNull(); | ||
| resultResponse.Paused.Should().Be(_getApprenticeshipStatisticsResponse.Paused); | ||
| resultResponse.Stopped.Should().Be(_getApprenticeshipStatisticsResponse.Stopped); | ||
| resultResponse.Approved.Should().Be(_getApprenticeshipStatisticsResponse.Approved); | ||
| } | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ApprenticeshipStatisticsController.cs
This file contains hidden or 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,41 @@ | ||
| using MediatR; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using SFA.DAS.CommitmentsV2.Api.Types.Responses; | ||
| using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipStatistics; | ||
| using SFA.DAS.CommitmentsV2.Shared.Interfaces; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SFA.DAS.CommitmentsV2.Api.Controllers | ||
| { | ||
| [ApiController] | ||
| [Authorize] | ||
| [Route("api/apprenticeshipstatistics")] | ||
| public class ApprenticeshipStatisticsController : ControllerBase | ||
| { | ||
| private readonly IMediator _mediator; | ||
| private readonly IModelMapper _modelMapper; | ||
|
|
||
| public ApprenticeshipStatisticsController(IMediator mediator, IModelMapper modelMapper) | ||
| { | ||
| _mediator = mediator; | ||
| _modelMapper = modelMapper; | ||
| } | ||
|
|
||
| [HttpGet] | ||
| [Route("/stats")] | ||
| public async Task<IActionResult> GetStatistics(int lastNumberOfDays) | ||
| { | ||
| var result = await _mediator.Send(new GetApprenticeshipStatisticsQuery { LastNumberOfDays = lastNumberOfDays }); | ||
|
|
||
| if (result == null) | ||
| { | ||
| return NotFound(); | ||
| } | ||
|
|
||
| var response = await _modelMapper.Map<GetApprenticeshipStatisticsResponse>(result); | ||
|
|
||
| return Ok(response); | ||
| } | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
...ation/Queries/GetApprenticeshipStatisticsTests/GetApprenticeshipStatisticsHandlerTests.cs
This file contains hidden or 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,44 @@ | ||
| using System.Threading.Tasks; | ||
| using Moq; | ||
| using NUnit.Framework; | ||
| using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipStatistics; | ||
| using SFA.DAS.CommitmentsV2.Domain.Interfaces; | ||
|
|
||
| namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetApprenticeshipStatisticsTests | ||
| { | ||
| [TestFixture] | ||
| public class GetApprenticeshipStatisticsHandlerTests | ||
| { | ||
| private GetApprenticeshipStatisticsQuery _query; | ||
| private GetApprenticeshipStatisticsQueryResult _result; | ||
| private Mock<IApprenticeshipStatusSummaryService> _apprenticeshipStatusSummaryServiceMock; | ||
| private GetApprenticeshipStatisticsQueryHandler _sut; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _query = new GetApprenticeshipStatisticsQuery(); | ||
| _result = new GetApprenticeshipStatisticsQueryResult(); | ||
|
|
||
| _apprenticeshipStatusSummaryServiceMock = new Mock<IApprenticeshipStatusSummaryService>(); | ||
| _apprenticeshipStatusSummaryServiceMock | ||
| .Setup(x => x.GetApprenticeshipStatisticsFor(_query.LastNumberOfDays)) | ||
| .ReturnsAsync(_result); | ||
|
|
||
| _sut = new GetApprenticeshipStatisticsQueryHandler(_apprenticeshipStatusSummaryServiceMock.Object); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task WhenHandling_ThenCallsApprenticeshipStatusSummaryServiceWithCorrectValues() | ||
| { | ||
| //Arrange | ||
| _query.LastNumberOfDays = 30; | ||
|
|
||
| //Act | ||
| await _sut.Handle(_query, default); | ||
|
|
||
| //Assert | ||
| _apprenticeshipStatusSummaryServiceMock.Verify(x => x.GetApprenticeshipStatisticsFor(_query.LastNumberOfDays), Times.Once); | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ion/Queries/GetApprenticeshipStatisticsTests/GetApprenticeshipStatisticsValidatorTests.cs
This file contains hidden or 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,26 @@ | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
| using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipStatistics; | ||
|
|
||
| namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetApprenticeshipStatisticsTests | ||
| { | ||
| [TestFixture] | ||
| public class GetApprenticeshipStatisticsValidatorTests | ||
| { | ||
| [TestCase(-10, false)] | ||
| [TestCase(0, false)] | ||
| [TestCase(10, true)] | ||
| public void WhenCallingValidate_ThenCorrectlyValidatesLastNumberOfDays(int lastNumberOfDays, | ||
| bool expectedValid) | ||
| { | ||
| //Arrange | ||
| var validator = new GetApprenticeshipStatisticsQueryValidator(); | ||
|
|
||
| //Act | ||
| var result = validator.Validate(new GetApprenticeshipStatisticsQuery { LastNumberOfDays = lastNumberOfDays }); | ||
|
|
||
| //Assert | ||
| result.IsValid.Should().Be(expectedValid); | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...ntsV2.UnitTests/Mapping/ResponseMappers/GetApprenticeshipStatisticsResponseMapperTests.cs
This file contains hidden or 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,37 @@ | ||
| using AutoFixture; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
| using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipStatistics; | ||
| using SFA.DAS.CommitmentsV2.Mapping.ResponseMappers; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SFA.DAS.CommitmentsV2.UnitTests.Mapping.ResponseMappers | ||
| { | ||
| [TestFixture] | ||
| public class GetApprenticeshipStatisticsResponseMapperTests | ||
| { | ||
| private Fixture _fixture; | ||
| private GetApprenticeshipStatisticsQueryResult _queryResult; | ||
| private GetApprenticeshipStatisticsResponseMapper _sut; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _fixture = new Fixture(); | ||
| _queryResult = _fixture.Create<GetApprenticeshipStatisticsQueryResult>(); | ||
| _sut = new GetApprenticeshipStatisticsResponseMapper(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task WhenMapIsCalled_ThenResponseIsMappedCorrectly() | ||
| { | ||
| //Act | ||
| var response = await _sut.Map(_queryResult); | ||
|
|
||
| //Assert | ||
| response.Paused.Should().Be(_queryResult.PausedApprenticeshipCount); | ||
| response.Approved.Should().Be(_queryResult.ApprovedApprenticeshipCount); | ||
| response.Stopped.Should().Be(_queryResult.StoppedApprenticeshipCount); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this to "api/v1"