From f677c26483d9891b247d2b5e3ba2c89aa6c09263 Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Wed, 15 Apr 2020 08:24:34 +0100 Subject: [PATCH 01/21] Moves change of party post into its own controller Moves test for same, and refactors to agreed style --- .../ApprenticeshipsControllerTests.cs | 16 ----- .../ChangeOfPartyControllerTests.cs | 71 +++++++++++++++++++ .../Controllers/ApprenticeshipController.cs | 19 ----- .../Controllers/ChangeOfPartyController.cs | 43 +++++++++++ 4 files changed, 114 insertions(+), 35 deletions(-) create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs index b28367e417..236b4002f8 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs @@ -167,21 +167,5 @@ public async Task ReturnNotFoundIfNullIsReturned() //Assert Assert.IsNotNull(result); } - - [Test, MoqAutoData] - public async Task PostChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request) - { - await _controller.CreateChangeOfPartyRequest(apprenticeshipId, request); - - //Assert - _mediator.Verify( - m => m.Send( - It.Is(p => - p.ApprenticeshipId == apprenticeshipId && - p.ChangeOfPartyRequestType == request.ChangeOfPartyRequestType && - p.NewPartyId == request.NewPartyId && p.NewStartDate == request.NewStartDate && - p.NewPrice == request.NewPrice && p.UserInfo == request.UserInfo), - It.IsAny()), Times.Once); - } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs new file mode 100644 index 0000000000..7eb584f8a9 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs @@ -0,0 +1,71 @@ +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.ChangeOfPartyRequest; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; + +namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests +{ + public class ChangeOfPartyControllerTests + { + private ChangeOfPartyControllerTestsFixture _fixture; + + [SetUp] + public void Arrange() + { + _fixture = new ChangeOfPartyControllerTestsFixture(); + } + + [Test] + public async Task PostChangeOfPartyRequest() + { + await _fixture.PostChangeOfPartyRequest(); + _fixture.VerifyPost(); + } + + private class ChangeOfPartyControllerTestsFixture + { + private readonly Mock _mediator; + private readonly Mock _mapper; + private readonly ChangeOfPartyController _controller; + + private readonly Fixture _autoFixture; + private readonly long _apprenticeshipId; + private readonly CreateChangeOfPartyRequestRequest _postRequest; + + public ChangeOfPartyControllerTestsFixture() + { + _mediator = new Mock(); + _mapper = new Mock(); + + _autoFixture = new Fixture(); + _apprenticeshipId = _autoFixture.Create(); + _postRequest = _autoFixture.Create(); + + _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(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()), Times.Once); + } + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ApprenticeshipController.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ApprenticeshipController.cs index 9a70ea5049..fa0c986a18 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ApprenticeshipController.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ApprenticeshipController.cs @@ -1,5 +1,4 @@ using System; -using System.Threading; using System.Threading.Tasks; using MediatR; using Microsoft.AspNetCore.Authorization; @@ -7,7 +6,6 @@ using Microsoft.Extensions.Logging; using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Api.Types.Responses; -using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeship; using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships; using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipsFilterValues; @@ -102,22 +100,5 @@ public async Task GetApprenticeshipsFilterValues([FromQuery]GetAp return Ok(response); } - - [HttpPost] - [Route("{apprenticeshipId}/change-of-party-requests")] - public async Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default) - { - await _mediator.Send(new ChangeOfPartyRequestCommand - { - ApprenticeshipId = apprenticeshipId, - ChangeOfPartyRequestType = request.ChangeOfPartyRequestType, - NewPartyId = request.NewPartyId, - NewStartDate = request.NewStartDate, - NewPrice = request.NewPrice, - UserInfo = request.UserInfo - }, cancellationToken); - - return Ok(); - } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs new file mode 100644 index 0000000000..c700d469d7 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs @@ -0,0 +1,43 @@ +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.Application.Commands.ChangeOfPartyRequest; +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; + } + + [HttpPost] + [Route("{apprenticeshipId}/change-of-party-requests")] + public async Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default) + { + await _mediator.Send(new ChangeOfPartyRequestCommand + { + ApprenticeshipId = apprenticeshipId, + ChangeOfPartyRequestType = request.ChangeOfPartyRequestType, + NewPartyId = request.NewPartyId, + NewStartDate = request.NewStartDate, + NewPrice = request.NewPrice, + UserInfo = request.UserInfo + }, cancellationToken); + + return Ok(); + } + } +} From 48289f30bf6caa47996a6685261b81c54154261c Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Wed, 15 Apr 2020 09:00:56 +0100 Subject: [PATCH 02/21] Route fix --- .../Controllers/ChangeOfPartyController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs index c700d469d7..347b4cd138 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs @@ -24,7 +24,6 @@ public ChangeOfPartyController(IMediator mediator, IModelMapper modelMapper) } [HttpPost] - [Route("{apprenticeshipId}/change-of-party-requests")] public async Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default) { await _mediator.Send(new ChangeOfPartyRequestCommand From d3cde290143197aa410bce1039ef6cec206053db Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Wed, 15 Apr 2020 11:37:52 +0100 Subject: [PATCH 03/21] WIP --- .../GetChangeOfPartyRequestsResponse.cs | 18 +++ ...PartyControllerTests.cs => CreateTests.cs} | 11 +- .../GetAllTests.cs | 90 +++++++++++++++ .../Controllers/ChangeOfPartyController.cs | 10 ++ .../ObjectExtensions.cs | 11 ++ ...tChangeOfPartyRequestsQueryHandlerTests.cs | 103 ++++++++++++++++++ ...hangeOfPartyRequestsResponseMapperTests.cs | 39 +++++++ .../SFA.DAS.CommitmentsV2.UnitTests.csproj | 1 + .../GetChangeOfPartyRequestsQuery.cs | 14 +++ .../GetChangeOfPartyRequestsQueryHandler.cs | 35 ++++++ .../GetChangeOfPartyRequestsQueryResult.cs | 18 +++ .../GetChangeOfPartyRequestsQueryValidator.cs | 8 ++ .../GetChangeOfPartyRequestsResponseMapper.cs | 26 +++++ 13 files changed, 379 insertions(+), 5 deletions(-) create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/{ChangeOfPartyControllerTests.cs => CreateTests.cs} (88%) create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapperTests.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQuery.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs new file mode 100644 index 0000000000..ea6e6306aa --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using SFA.DAS.CommitmentsV2.Types; + +namespace SFA.DAS.CommitmentsV2.Api.Types.Responses +{ + public class GetChangeOfPartyRequestsResponse + { + public IReadOnlyCollection 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; } + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs similarity index 88% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs index 7eb584f8a9..6bcf536800 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/ChangeOfPartyControllerTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs @@ -11,14 +11,15 @@ namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests { - public class ChangeOfPartyControllerTests + [TestFixture] + public class CreateTests { - private ChangeOfPartyControllerTestsFixture _fixture; + private CreateTestsFixture _fixture; [SetUp] public void Arrange() { - _fixture = new ChangeOfPartyControllerTestsFixture(); + _fixture = new CreateTestsFixture(); } [Test] @@ -28,7 +29,7 @@ public async Task PostChangeOfPartyRequest() _fixture.VerifyPost(); } - private class ChangeOfPartyControllerTestsFixture + private class CreateTestsFixture { private readonly Mock _mediator; private readonly Mock _mapper; @@ -38,7 +39,7 @@ private class ChangeOfPartyControllerTestsFixture private readonly long _apprenticeshipId; private readonly CreateChangeOfPartyRequestRequest _postRequest; - public ChangeOfPartyControllerTestsFixture() + public CreateTestsFixture() { _mediator = new Mock(); _mapper = new Mock(); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs new file mode 100644 index 0000000000..28f0ca6687 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs @@ -0,0 +1,90 @@ +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.Commands.ChangeOfPartyRequest; +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 _mediator; + private readonly Mock _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(); + _mapper = new Mock(); + + _queryResult = new GetChangeOfPartyRequestsQueryResult(); + _mapperResult = new GetChangeOfPartyRequestsResponse(); + + _autoFixture = new Fixture(); + + _mediator.Setup(x => + x.Send(It.Is(q => q.ApprenticeshipId == _apprenticeshipId), + It.IsAny())) + .ReturnsAsync(_queryResult); + + _mapper.Setup(x => x.Map(_queryResult)).ReturnsAsync(_mapperResult); + + _apprenticeshipId = _autoFixture.Create(); + + _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); + } + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs index 347b4cd138..3b66799f5c 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs @@ -4,7 +4,9 @@ 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.ChangeOfPartyRequest; +using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; namespace SFA.DAS.CommitmentsV2.Api.Controllers @@ -23,6 +25,14 @@ public ChangeOfPartyController(IMediator mediator, IModelMapper modelMapper) _modelMapper = modelMapper; } + [HttpGet] + public async Task GetAll(long apprenticeshipId, CancellationToken cancellationToken = default) + { + var result = await _mediator.Send(new GetChangeOfPartyRequestsQuery(apprenticeshipId), cancellationToken); + var response = await _modelMapper.Map(result); + return Ok(response); + } + [HttpPost] public async Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default) { diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs new file mode 100644 index 0000000000..228f166868 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs @@ -0,0 +1,11 @@ +namespace SFA.DAS.CommitmentsV2.TestHelpers +{ + public static class ObjectExtensions + { + public static void SetValue(this object o, string propertyName, object value) + { + var t = o.GetType(); + t.GetProperty(propertyName).SetValue(o, value, null); + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs new file mode 100644 index 0000000000..d8deb57875 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using AutoFixture; +using Microsoft.EntityFrameworkCore; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; +using SFA.DAS.CommitmentsV2.Data; +using SFA.DAS.CommitmentsV2.Models; +using SFA.DAS.CommitmentsV2.TestHelpers; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.Testing.Builders; + +namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetChangeOfPartyRequests +{ + [TestFixture] + public class GetChangeOfPartyRequestsQueryHandlerTests + { + private ChangeOfPartyRequestsQueryHandlersTestsFixture _fixture; + + [SetUp] + public void Arrange() + { + _fixture = new ChangeOfPartyRequestsQueryHandlersTestsFixture(); + } + + [Test] + public async Task Handle_ThenShouldReturnResult() + { + await _fixture.Handle(); + _fixture.VerifyResultMapping(); + } + + public class ChangeOfPartyRequestsQueryHandlersTestsFixture + { + private readonly GetChangeOfPartyRequestsQueryHandler _handler; + private readonly ProviderCommitmentsDbContext _db; + private readonly GetChangeOfPartyRequestsQuery _request; + private GetChangeOfPartyRequestsQueryResult _result; + private readonly Fixture _autoFixture; + private List _changeOfPartyRequests; + private readonly long _apprenticeshipId; + + public ChangeOfPartyRequestsQueryHandlersTestsFixture() + { + _autoFixture = new Fixture(); + + _apprenticeshipId = _autoFixture.Create(); + _request = new GetChangeOfPartyRequestsQuery(_apprenticeshipId); + + _db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options); + SeedData(); + _handler = new GetChangeOfPartyRequestsQueryHandler(new Lazy(() => _db)); + } + + + public async Task Handle() + { + _result = await _handler.Handle(TestHelper.Clone(_request), new CancellationToken()); + return _result; + } + + private void SeedData() + { + _changeOfPartyRequests = new List(); + + for (var i = 1; i <= 10; i++) + { + var request = new ChangeOfPartyRequest(); + request.SetValue("Id", i); + request.SetValue("ApprenticeshipId", _apprenticeshipId); + request.SetValue("ChangeOfPartyType", _autoFixture.Create()); + request.SetValue("OriginatingParty", _autoFixture.Create()); + request.SetValue("Status", _autoFixture.Create()); + _changeOfPartyRequests.Add(request); + } + + _db.ChangeOfPartyRequests.AddRange(_changeOfPartyRequests); + _db.SaveChanges(); + } + + public void VerifyResultMapping() + { + Assert.AreEqual(_changeOfPartyRequests.Count(), _result.ChangeOfPartyRequests.Count); + + foreach (var sourceItem in _changeOfPartyRequests) + { + AssertEquality(sourceItem, _result.ChangeOfPartyRequests.Single(x => x.Id == sourceItem.Id)); + } + } + } + + private static void AssertEquality(ChangeOfPartyRequest source, GetChangeOfPartyRequestsQueryResult.ChangeOfPartyRequest result) + { + Assert.AreEqual(source.Id, result.Id); + Assert.AreEqual(source.ChangeOfPartyType, result.ChangeOfPartyType); + Assert.AreEqual(source.OriginatingParty, result.OriginatingParty); + Assert.AreEqual(source.Status, result.Status); + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapperTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapperTests.cs new file mode 100644 index 0000000000..8d1a2d1f8d --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapperTests.cs @@ -0,0 +1,39 @@ +using System.Threading.Tasks; +using AutoFixture; +using KellermanSoftware.CompareNetObjects; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; +using SFA.DAS.CommitmentsV2.Mapping.ResponseMappers; + +namespace SFA.DAS.CommitmentsV2.UnitTests.Mapping.ResponseMappers +{ + [TestFixture] + public class GetChangeOfPartyRequestsResponseMapperTests + { + private readonly GetChangeOfPartyRequestsResponseMapper _mapper; + private GetChangeOfPartyRequestsQueryResult _source; + private GetChangeOfPartyRequestsResponse _result; + + public GetChangeOfPartyRequestsResponseMapperTests() + { + _mapper = new GetChangeOfPartyRequestsResponseMapper(); + } + + [SetUp] + public async Task Arrange() + { + var autoFixture = new Fixture(); + _source = autoFixture.Create(); + _result = await _mapper.Map(TestHelper.Clone(_source)); + } + + [Test] + public void RequestsAreMappedCorrectly() + { + var compare = new CompareLogic(new ComparisonConfig { IgnoreObjectTypes = true }); + var compareResult = compare.Compare(_source.ChangeOfPartyRequests, _result.ChangeOfPartyRequests); + Assert.IsTrue(compareResult.AreEqual); + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/SFA.DAS.CommitmentsV2.UnitTests.csproj b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/SFA.DAS.CommitmentsV2.UnitTests.csproj index 382d052803..787c4afca2 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/SFA.DAS.CommitmentsV2.UnitTests.csproj +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/SFA.DAS.CommitmentsV2.UnitTests.csproj @@ -30,6 +30,7 @@ + diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQuery.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQuery.cs new file mode 100644 index 0000000000..1ca1ec20fc --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQuery.cs @@ -0,0 +1,14 @@ +using MediatR; + +namespace SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests +{ + public class GetChangeOfPartyRequestsQuery : IRequest + { + public long ApprenticeshipId { get; } + + public GetChangeOfPartyRequestsQuery(long apprenticeshipId) + { + ApprenticeshipId = apprenticeshipId; + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs new file mode 100644 index 0000000000..8b75110eef --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs @@ -0,0 +1,35 @@ +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.EntityFrameworkCore; +using SFA.DAS.CommitmentsV2.Data; + +namespace SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests +{ + public class GetChangeOfPartyRequestsQueryHandler : IRequestHandler + { + private readonly Lazy _dbContext; + + public GetChangeOfPartyRequestsQueryHandler(Lazy dbContext) + { + _dbContext = dbContext; + } + + public async Task Handle(GetChangeOfPartyRequestsQuery request, CancellationToken cancellationToken) + { + return new GetChangeOfPartyRequestsQueryResult + { + ChangeOfPartyRequests = await _dbContext.Value.ChangeOfPartyRequests.Where(x => x.ApprenticeshipId == request.ApprenticeshipId) + .Select(r => new GetChangeOfPartyRequestsQueryResult.ChangeOfPartyRequest + { + Id = r.Id, + OriginatingParty = r.OriginatingParty, + ChangeOfPartyType = r.ChangeOfPartyType, + Status = r.Status + }).ToListAsync(cancellationToken) + }; + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs new file mode 100644 index 0000000000..cd7001e689 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using SFA.DAS.CommitmentsV2.Types; + +namespace SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests +{ + public class GetChangeOfPartyRequestsQueryResult + { + public IReadOnlyCollection 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; } + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs new file mode 100644 index 0000000000..8ca8f5b28b --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs @@ -0,0 +1,8 @@ +using FluentValidation; + +namespace SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests +{ + public class GetChangeOfPartyRequestsQueryValidator : AbstractValidator + { + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs new file mode 100644 index 0000000000..8d8bae984b --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs @@ -0,0 +1,26 @@ +using System.Linq; +using System.Threading.Tasks; +using SFA.DAS.CommitmentsV2.Api.Types.Responses; +using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; +using SFA.DAS.CommitmentsV2.Shared.Interfaces; + +namespace SFA.DAS.CommitmentsV2.Mapping.ResponseMappers +{ + public class GetChangeOfPartyRequestsResponseMapper : IMapper + { + public Task Map(GetChangeOfPartyRequestsQueryResult source) + { + return Task.FromResult(new GetChangeOfPartyRequestsResponse + { + ChangeOfPartyRequests = source.ChangeOfPartyRequests.Select(r => + new GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest + { + Id = r.Id, + ChangeOfPartyType = r.ChangeOfPartyType, + OriginatingParty = r.OriginatingParty, + Status = r.Status + }).ToList() + }); + } + } +} \ No newline at end of file From ed802fab615de35de8060527665ab9cb657ae3a6 Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Wed, 15 Apr 2020 11:42:45 +0100 Subject: [PATCH 04/21] Request validator and test --- ...hangeOfPartyRequestsQueryValidatorTests.cs | 49 +++++++++++++++++++ .../GetChangeOfPartyRequestsQueryValidator.cs | 4 ++ 2 files changed, 53 insertions(+) create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidatorTests.cs diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidatorTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidatorTests.cs new file mode 100644 index 0000000000..efdf1cbc81 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidatorTests.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Text; +using FluentValidation.Results; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Application.Queries.GetApprovedProviders; +using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; +using SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetProvider; + +namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetChangeOfPartyRequests +{ + [TestFixture] + [Parallelizable] + public class GetChangeOfPartyRequestsQueryValidatorTests + { + private GetChangeOfPartyRequestsQueryValidatorTestsFixture _fixture; + + [SetUp] + public void SetUp() + { + _fixture = new GetChangeOfPartyRequestsQueryValidatorTestsFixture(); + } + + [TestCase(-1, false)] + [TestCase(0, false)] + [TestCase(1, true)] + public void Validate_WhenValidating_ThenShouldValidate(int accountId, bool isValid) + { + var validationResult = _fixture.Validate(accountId); + + Assert.AreEqual(isValid, validationResult.IsValid); + } + } + + public class GetChangeOfPartyRequestsQueryValidatorTestsFixture + { + public GetChangeOfPartyRequestsQueryValidator Validator { get; set; } + + public GetChangeOfPartyRequestsQueryValidatorTestsFixture() + { + Validator = new GetChangeOfPartyRequestsQueryValidator(); + } + + public ValidationResult Validate(long apprenticeshipId) + { + return Validator.Validate(new GetChangeOfPartyRequestsQuery(apprenticeshipId)); + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs index 8ca8f5b28b..877f329904 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryValidator.cs @@ -4,5 +4,9 @@ namespace SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests { public class GetChangeOfPartyRequestsQueryValidator : AbstractValidator { + public GetChangeOfPartyRequestsQueryValidator() + { + RuleFor(x => x.ApprenticeshipId).GreaterThan(0); + } } } From e59fad2ffa5aac80202628b6c9ad5fe817decfce Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Wed, 15 Apr 2020 14:23:24 +0100 Subject: [PATCH 05/21] Adds client method --- .../CommitmentsApiClient/WhenCallingTheEndpoints.cs | 7 +++++++ .../CommitmentsApiClient.cs | 5 +++++ .../ICommitmentsApiClient.cs | 1 + 3 files changed, 13 insertions(+) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client.UnitTests/CommitmentsApiClient/WhenCallingTheEndpoints.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client.UnitTests/CommitmentsApiClient/WhenCallingTheEndpoints.cs index 92cc2a7cf9..0e0c937cfa 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client.UnitTests/CommitmentsApiClient/WhenCallingTheEndpoints.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client.UnitTests/CommitmentsApiClient/WhenCallingTheEndpoints.cs @@ -456,6 +456,13 @@ public async Task GetApprenticeshipUpdates_WithNullStatus_VerifyUrlAndData() await _fixture.CommitmentsApiClient.GetApprenticeshipUpdates(1, request); _fixture.MockRestHttpClient.Verify(x => x.Get($"api/apprenticeships/{1}/updates", null, CancellationToken.None)); } + + [Test] + public async Task GetChangeOfPartyRequests_VerifyUrlAndData() + { + await _fixture.CommitmentsApiClient.GetChangeOfPartyRequests(123); + _fixture.MockRestHttpClient.Verify(x => x.Get("api/apprenticeships/123/change-of-party-requests", null, CancellationToken.None)); + } } public class WhenCallingTheEndpointsFixture diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/CommitmentsApiClient.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/CommitmentsApiClient.cs index de306cf14f..df701cbf2a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/CommitmentsApiClient.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/CommitmentsApiClient.cs @@ -302,5 +302,10 @@ public Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPart { return _client.PostAsJson($"api/apprenticeships/{apprenticeshipId}/change-of-party-requests", request, cancellationToken); } + + public Task GetChangeOfPartyRequests(long apprenticeshipId, CancellationToken cancellationToken = default) + { + return _client.Get($"api/apprenticeships/{apprenticeshipId}/change-of-party-requests", null, cancellationToken); + } } } \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/ICommitmentsApiClient.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/ICommitmentsApiClient.cs index ce9b330c38..eb153546ed 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/ICommitmentsApiClient.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Client/ICommitmentsApiClient.cs @@ -39,5 +39,6 @@ public interface ICommitmentsApiClient Task GetApprenticeshipUpdates(long apprenticeshipId, GetApprenticeshipUpdatesRequest request, CancellationToken cancellationToken = default); Task GetApprenticeshipDatalocksStatus(long apprenticeshipId, CancellationToken cancellationToken = default); Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default); + Task GetChangeOfPartyRequests(long apprenticeshipId, CancellationToken cancellationToken = default); } } From 1adfc35c9edace0e5c2e113b96410f6cb27f3bac Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 15 Apr 2020 15:26:21 +0100 Subject: [PATCH 06/21] Split WithAlerts between providers and employers, added tests --- ...loyerAppernticeshipsWithOrWithoutAlerts.cs | 162 ++++++++++++++++++ ...iderApprenticeshipsWithOrWithoutAlerts.cs} | 9 +- .../Services/ApprenticeshipSearchService.cs | 2 +- .../OrderedApprenticeshipSearchService.cs | 2 +- ...verseOrderedApprenticeshipSearchService.cs | 2 +- .../Domain/Extensions/AlertsExtensions.cs | 4 +- .../QueryableApprenticeshipsExtensions.cs | 33 +++- 7 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/{WhenGettingApprenticeshipsWithOrWithoutAlerts.cs => WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs} (89%) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs new file mode 100644 index 0000000000..d5fff9ea32 --- /dev/null +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -0,0 +1,162 @@ +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Services.Parameters; +using SFA.DAS.CommitmentsV2.Domain.Interfaces; +using SFA.DAS.CommitmentsV2.Extensions; +using SFA.DAS.CommitmentsV2.Models; +using SFA.DAS.CommitmentsV2.Types; + +namespace SFA.DAS.CommitmentsV2.UnitTests.Extensions.QueryableApprenticeshipsExtensions +{ + public class WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts + { + private IQueryable _apprenticeships; + private readonly ApprenticeshipSearchParameters _parameters = new ApprenticeshipSearchParameters { EmployerAccountId = 1 }; + + [SetUp] + public void Arrange() + { + _apprenticeships = GetTestData(); + } + + [Test] + public void ThenWillReturnApprenticeshipsWithAlerts() + { + //Act + var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); + + //Assert + Assert.AreEqual(1, result.Count); + Assert.AreEqual(3, result[0].Id); + } + + [Test] + public void ThenWillReturnApprenticeshipsWithoutAlerts() + { + //Act + var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); + + //Assert + Assert.AreEqual(6, result.Count); + + Assert.AreEqual(1, result[0].Id); + Assert.AreEqual(2, result[1].Id); + Assert.AreEqual(4, result[2].Id); + Assert.AreEqual(5, result[3].Id); + Assert.AreEqual(6, result[4].Id); + Assert.AreEqual(7, result[5].Id); + } + + private static IQueryable GetTestData() + { + var apprenticeships = new List + { + new Apprenticeship + { + Id = 1, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = false, + Status = Status.Fail, + EventStatus = EventStatus.New + } + } + }, + new Apprenticeship {Id = 2}, + new Apprenticeship + { + Id = 3, + ApprenticeshipUpdate = new List + { + new ApprenticeshipUpdate + { + Status = ApprenticeshipUpdateStatus.Pending, + Originator = Originator.Provider + } + } + }, + new Apprenticeship + { + Id = 4, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = true, + Status = Status.Fail, + EventStatus = EventStatus.New + } + } + }, + new Apprenticeship + { + Id = 5, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = false, + Status = Status.Pass, + EventStatus = EventStatus.New + } + } + }, + new Apprenticeship + { + Id = 6, + DataLockStatus = new List + { + new DataLockStatus + { + IsResolved = false, + Status = Status.Fail, + EventStatus = EventStatus.Removed + } + } + }, + new Apprenticeship + { + Id = 7, + ApprenticeshipUpdate = new List + { + new ApprenticeshipUpdate + { + Status = ApprenticeshipUpdateStatus.Deleted, + Originator = Originator.Provider + } + } + }, + new Apprenticeship + { + Id = 8, + ApprenticeshipUpdate = new List + { + new ApprenticeshipUpdate + { + Status = ApprenticeshipUpdateStatus.Pending, + Originator = Originator.Unknown + } + } + }, + new Apprenticeship + { + Id = 9, + DataLockStatus = new List + { + new DataLockStatus + { + ErrorCode = DataLockErrorCode.Dlock03, + TriageStatus = TriageStatus.Unknown, + IsResolved = false + + } + } + } + }.AsQueryable(); + return apprenticeships; + } + } +} diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs similarity index 89% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeshipsWithOrWithoutAlerts.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs index 2bd8898dbf..315c93d943 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs @@ -1,15 +1,18 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; +using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Services.Parameters; +using SFA.DAS.CommitmentsV2.Domain.Interfaces; using SFA.DAS.CommitmentsV2.Extensions; using SFA.DAS.CommitmentsV2.Models; using SFA.DAS.CommitmentsV2.Types; namespace SFA.DAS.CommitmentsV2.UnitTests.Extensions.QueryableApprenticeshipsExtensions { - public class WhenGettingApprenticeshipsWithOrWithoutAlerts + public class WhenGettingProviderApprenticeshipsWithOrWithoutAlerts { private IQueryable _apprenticeships; + private readonly ApprenticeshipSearchParameters _parameters = new ApprenticeshipSearchParameters { ProviderId = 1 }; [SetUp] public void Arrange() @@ -21,7 +24,7 @@ public void Arrange() public void ThenWillReturnApprenticeshipsWithAlerts() { //Act - var result = _apprenticeships.WithAlerts(true).ToList(); + var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); //Assert Assert.AreEqual(2, result.Count); @@ -33,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts() public void ThenWillReturnApprenticeshipsWithoutAlerts() { //Act - var result = _apprenticeships.WithAlerts(false).ToList(); + var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); //Assert Assert.AreEqual(5, result.Count); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs index 92ad651b93..9dbdae7eff 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs @@ -223,7 +223,7 @@ private IQueryable GetApprenticeshipsQuery(ApprenticeshipSearchP private IQueryable GetApprenticeshipsWithFiltersQuery(ApprenticeshipSearchParameters searchParameters, bool withAlerts) { return GetApprenticeshipsQuery(searchParameters) - .WithAlerts(withAlerts) + .WithAlertsProviderOrEmployer(withAlerts, searchParameters) .Filter(searchParameters.Filters); } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 383a7bf9b3..9ec696575d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -27,7 +27,7 @@ public async Task Find(OrderedApprenticeshipSearchPa apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderBy(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index 613b582eb5..b681f9b303 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -27,7 +27,7 @@ public async Task Find(ReverseOrderedApprenticeshipS apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderByDescending(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index c1e1ca8cb4..ecf756def4 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -51,7 +51,7 @@ public static IEnumerable MapAlerts(this Apprenticeship source) return result; } - private static bool HasCourseDataLock(Apprenticeship source) + public static bool HasCourseDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.WithCourseError() && @@ -59,7 +59,7 @@ private static bool HasCourseDataLock(Apprenticeship source) !x.IsResolved); } - private static bool HasPriceDataLock(Apprenticeship source) + public static bool HasPriceDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.IsPriceOnly() && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 07b778523a..242c45c755 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using SFA.DAS.CommitmentsV2.Domain.Extensions; using SFA.DAS.CommitmentsV2.Domain.Interfaces; using SFA.DAS.CommitmentsV2.Models; using SFA.DAS.CommitmentsV2.Types; @@ -105,7 +106,14 @@ public static IQueryable Filter(this IQueryable return apprenticeships; } - public static IQueryable WithAlerts(this IQueryable apprenticeships, bool hasAlerts) + public static IQueryable WithAlertsProviderOrEmployer( + this IQueryable apprenticeships, bool hasAlerts, + IEmployerProviderIdentifier identifier) + { + return identifier.ProviderId.HasValue ? WithAlertsProvider(apprenticeships, hasAlerts) : WithAlertsEmployer(apprenticeships, hasAlerts); + } + + public static IQueryable WithAlertsProvider(this IQueryable apprenticeships, bool hasAlerts) { if (hasAlerts) { @@ -122,6 +130,29 @@ public static IQueryable WithAlerts(this IQueryable c.Status != ApprenticeshipUpdateStatus.Pending))); } + public static IQueryable WithAlertsEmployer(this IQueryable apprenticeships, bool hasAlerts) + { + if (hasAlerts) + { + return apprenticeships.Where(apprenticeship => apprenticeship.DataLockStatus.Any(c => !c.IsResolved + && c.Status == Status.Fail + && c.TriageStatus != TriageStatus.Unknown + && c.EventStatus != EventStatus.Removed) || + apprenticeship.ApprenticeshipUpdate != null && + apprenticeship.ApprenticeshipUpdate.Any( + c => c.Status == ApprenticeshipUpdateStatus.Pending + && (c.Originator == Originator.Employer + || c.Originator == Originator.Provider))); + } + var apprenticesWithAlerts = apprenticeships.Where(apprenticeship => + !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed && c.TriageStatus != TriageStatus.Unknown) + && + (apprenticeship.ApprenticeshipUpdate == null || + apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); + return apprenticesWithAlerts.Where + (x => !AlertsExtensions.HasCourseDataLock(x) + && !AlertsExtensions.HasPriceDataLock(x)); + } public static IQueryable WithProviderOrEmployerId( this IQueryable apprenticeships, IEmployerProviderIdentifier identifier) From 7dbac3f1f1eb30e3539fc4a521508a452859dff2 Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Thu, 16 Apr 2020 14:01:23 +0100 Subject: [PATCH 07/21] Corrected some names --- .../ApprenticeshipsControllerTests.cs | 1 - .../ChangeOfPartyControllerTests/CreateTests.cs | 4 ++-- .../ChangeOfPartyControllerTests/GetAllTests.cs | 1 - .../Controllers/ChangeOfPartyController.cs | 4 ++-- .../Commands/ChangeOfPartyCommandHandlerTests.cs | 10 +++++----- .../Commands/ChangeOfPartyRequestValidatorTests.cs | 6 +++--- .../CreateChangeOfPartyRequestCommand.cs} | 4 ++-- .../CreateChangeOfPartyRequestCommandHandler.cs} | 8 ++++---- .../CreateChangeOfPartyRequestValidator.cs} | 6 +++--- 9 files changed, 21 insertions(+), 23 deletions(-) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/{ChangeOfPartyRequest/ChangeOfPartyRequestCommand.cs => CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommand.cs} (73%) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/{ChangeOfPartyRequest/ChangeOfPartyRequestCommandHandler.cs => CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommandHandler.cs} (58%) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/{ChangeOfPartyRequest/ChangeOfPartyRequestValidator.cs => CreateChangeOfPartyRequest/CreateChangeOfPartyRequestValidator.cs} (62%) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs index 236b4002f8..dc348c05a0 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ApprenticeshipControllerTests/ApprenticeshipsControllerTests.cs @@ -8,7 +8,6 @@ using NUnit.Framework; using SFA.DAS.CommitmentsV2.Api.Controllers; using SFA.DAS.CommitmentsV2.Api.Types.Requests; -using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships; using SFA.DAS.CommitmentsV2.Shared.Interfaces; using SFA.DAS.Testing.AutoFixture; diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs index 6bcf536800..04390dde48 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/CreateTests.cs @@ -6,7 +6,7 @@ using NUnit.Framework; using SFA.DAS.CommitmentsV2.Api.Controllers; using SFA.DAS.CommitmentsV2.Api.Types.Requests; -using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest; +using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Shared.Interfaces; namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests @@ -60,7 +60,7 @@ public void VerifyPost() { _mediator.Verify( m => m.Send( - It.Is(p => + It.Is(p => p.ApprenticeshipId == _apprenticeshipId && p.ChangeOfPartyRequestType == _postRequest.ChangeOfPartyRequestType && p.NewPartyId == _postRequest.NewPartyId && p.NewStartDate == _postRequest.NewStartDate && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs index 28f0ca6687..b1f2f00252 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.UnitTests/Controllers/ChangeOfPartyControllerTests/GetAllTests.cs @@ -11,7 +11,6 @@ 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.Commands.ChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs index 3b66799f5c..a40a8d7244 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/Controllers/ChangeOfPartyController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Mvc; using SFA.DAS.CommitmentsV2.Api.Types.Requests; using SFA.DAS.CommitmentsV2.Api.Types.Responses; -using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest; +using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests; using SFA.DAS.CommitmentsV2.Shared.Interfaces; @@ -36,7 +36,7 @@ public async Task GetAll(long apprenticeshipId, CancellationToken [HttpPost] public async Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default) { - await _mediator.Send(new ChangeOfPartyRequestCommand + await _mediator.Send(new CreateChangeOfPartyRequestCommand { ApprenticeshipId = apprenticeshipId, ChangeOfPartyRequestType = request.ChangeOfPartyRequestType, diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs index 86c9fe4a08..72e06a42b2 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs @@ -4,7 +4,7 @@ using MediatR; using Moq; using NUnit.Framework; -using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest; +using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Domain.Interfaces; namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Commands @@ -30,16 +30,16 @@ public class ChangeOfPartyCommandHandlerTestsFixture { public Fixture AutoFixture { get; set; } public Mock ChangeOfPartyDomainService { get; set; } - public IRequestHandler Handler { get; set; } - public ChangeOfPartyRequestCommand Command { get; set; } + public IRequestHandler Handler { get; set; } + public CreateChangeOfPartyRequestCommand Command { get; set; } public CancellationToken CancellationToken { get; set; } public ChangeOfPartyCommandHandlerTestsFixture() { AutoFixture = new Fixture(); ChangeOfPartyDomainService = new Mock(); - Handler = new ChangeOfPartyRequestCommandHandler(ChangeOfPartyDomainService.Object); - Command = AutoFixture.Create(); + Handler = new CreateChangeOfPartyRequestCommandHandler(ChangeOfPartyDomainService.Object); + Command = AutoFixture.Create(); CancellationToken = new CancellationToken(); } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs index 2a22ee0242..fc76e1442a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs @@ -2,7 +2,7 @@ using System.Linq.Expressions; using FluentValidation.TestHelper; using NUnit.Framework; -using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest; +using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest; using SFA.DAS.CommitmentsV2.Types; namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Commands @@ -32,9 +32,9 @@ public void Validate_UserInfo_ShouldBeValidated(bool isSet, bool isValid) AssertValidationResult(r => r.UserInfo, isSet ? new UserInfo() : null, isValid); } - private void AssertValidationResult(Expression> property, T value, bool isValid) + private void AssertValidationResult(Expression> property, T value, bool isValid) { - var validator = new ChangeOfPartyRequestValidator(); + var validator = new CreateChangeOfPartyRequestValidator(); if (isValid) { diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestCommand.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommand.cs similarity index 73% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestCommand.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommand.cs index c1cf035ea2..510735109a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestCommand.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommand.cs @@ -2,9 +2,9 @@ using MediatR; using SFA.DAS.CommitmentsV2.Types; -namespace SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest +namespace SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest { - public class ChangeOfPartyRequestCommand : IRequest + public class CreateChangeOfPartyRequestCommand : IRequest { public long ApprenticeshipId { get; set; } public ChangeOfPartyRequestType ChangeOfPartyRequestType { get; set; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestCommandHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommandHandler.cs similarity index 58% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestCommandHandler.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommandHandler.cs index afece5f41d..5fe90aabdc 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestCommandHandler.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestCommandHandler.cs @@ -3,18 +3,18 @@ using MediatR; using SFA.DAS.CommitmentsV2.Domain.Interfaces; -namespace SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest +namespace SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest { - public class ChangeOfPartyRequestCommandHandler : AsyncRequestHandler + public class CreateChangeOfPartyRequestCommandHandler : AsyncRequestHandler { private readonly IChangeOfPartyRequestDomainService _changeOfPartyRequestDomainService; - public ChangeOfPartyRequestCommandHandler(IChangeOfPartyRequestDomainService changeOfPartyRequestDomainService) + public CreateChangeOfPartyRequestCommandHandler(IChangeOfPartyRequestDomainService changeOfPartyRequestDomainService) { _changeOfPartyRequestDomainService = changeOfPartyRequestDomainService; } - protected override Task Handle(ChangeOfPartyRequestCommand command, CancellationToken cancellationToken) + protected override Task Handle(CreateChangeOfPartyRequestCommand command, CancellationToken cancellationToken) { return _changeOfPartyRequestDomainService.CreateChangeOfPartyRequest(command.ApprenticeshipId, command.ChangeOfPartyRequestType, command.NewPartyId, command.NewPrice, command.NewStartDate, null, diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestValidator.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestValidator.cs similarity index 62% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestValidator.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestValidator.cs index aaec04e42e..32e8ed1034 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/ChangeOfPartyRequest/ChangeOfPartyRequestValidator.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Commands/CreateChangeOfPartyRequest/CreateChangeOfPartyRequestValidator.cs @@ -1,10 +1,10 @@ using FluentValidation; -namespace SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest +namespace SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest { - public class ChangeOfPartyRequestValidator : AbstractValidator + public class CreateChangeOfPartyRequestValidator : AbstractValidator { - public ChangeOfPartyRequestValidator() + public CreateChangeOfPartyRequestValidator() { RuleFor(model => model.UserInfo).NotNull().WithMessage("The UserInfo cannot be empty"); RuleFor(model => model.NewPartyId).Must(id => id > 0).WithMessage("The NewPartyId must be positive"); From f145f8b7e668ff6359182a67503245304b393ef4 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Fri, 17 Apr 2020 09:28:31 +0100 Subject: [PATCH 08/21] Change employer query Changed so that the DataLockStatus that have a TriageStatus of Unkown are not included for employer search. --- ...ingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 12 ++++++------ .../Domain/Extensions/AlertsExtensions.cs | 4 ++-- .../QueryableApprenticeshipsExtensions.cs | 13 +++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index d5fff9ea32..e658d68851 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -40,12 +40,12 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() //Assert Assert.AreEqual(6, result.Count); - Assert.AreEqual(1, result[0].Id); - Assert.AreEqual(2, result[1].Id); - Assert.AreEqual(4, result[2].Id); - Assert.AreEqual(5, result[3].Id); - Assert.AreEqual(6, result[4].Id); - Assert.AreEqual(7, result[5].Id); + Assert.AreEqual(2, result[0].Id); + Assert.AreEqual(4, result[1].Id); + Assert.AreEqual(5, result[2].Id); + Assert.AreEqual(6, result[3].Id); + Assert.AreEqual(7, result[4].Id); + Assert.AreEqual(9, result[5].Id); } private static IQueryable GetTestData() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index ecf756def4..c1e1ca8cb4 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -51,7 +51,7 @@ public static IEnumerable MapAlerts(this Apprenticeship source) return result; } - public static bool HasCourseDataLock(Apprenticeship source) + private static bool HasCourseDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.WithCourseError() && @@ -59,7 +59,7 @@ public static bool HasCourseDataLock(Apprenticeship source) !x.IsResolved); } - public static bool HasPriceDataLock(Apprenticeship source) + private static bool HasPriceDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.IsPriceOnly() && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 242c45c755..767c76eab1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -136,22 +136,19 @@ public static IQueryable WithAlertsEmployer(this IQueryable apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail - && c.TriageStatus != TriageStatus.Unknown - && c.EventStatus != EventStatus.Removed) || + && c.EventStatus != EventStatus.Removed ) && + apprenticeship.DataLockStatus.All(c=>c.TriageStatus!= TriageStatus.Unknown) || apprenticeship.ApprenticeshipUpdate != null && apprenticeship.ApprenticeshipUpdate.Any( c => c.Status == ApprenticeshipUpdateStatus.Pending && (c.Originator == Originator.Employer || c.Originator == Originator.Provider))); } - var apprenticesWithAlerts = apprenticeships.Where(apprenticeship => - !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed && c.TriageStatus != TriageStatus.Unknown) - && + return apprenticeships.Where(apprenticeship => + !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed) && + apprenticeship.DataLockStatus.All(c=>c.TriageStatus == TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); - return apprenticesWithAlerts.Where - (x => !AlertsExtensions.HasCourseDataLock(x) - && !AlertsExtensions.HasPriceDataLock(x)); } public static IQueryable WithProviderOrEmployerId( From 6adfd0272862eed81dbb512d625cb0cbe6112881 Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Fri, 17 Apr 2020 13:59:38 +0100 Subject: [PATCH 09/21] Adds new fields to api response, query, mapper, etc. --- .../GetChangeOfPartyRequestsResponse.cs | 6 ++++- .../ObjectExtensions.cs | 11 ++++++--- ...tChangeOfPartyRequestsQueryHandlerTests.cs | 24 +++++++++++++------ .../GetChangeOfPartyRequestsQueryHandler.cs | 9 +++++-- .../GetChangeOfPartyRequestsQueryResult.cs | 6 ++++- .../ChangeOfPartyRequestConfiguration.cs | 5 ++++ .../GetChangeOfPartyRequestsResponseMapper.cs | 5 +++- .../Models/AccountLegalEntity.cs | 1 + .../Models/ChangeOfPartyRequest.cs | 1 + .../SFA.DAS.CommitmentsV2/Models/Cohort.cs | 1 - 10 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs index ea6e6306aa..5ff67eee38 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetChangeOfPartyRequestsResponse.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using SFA.DAS.CommitmentsV2.Types; namespace SFA.DAS.CommitmentsV2.Api.Types.Responses @@ -13,6 +14,9 @@ public class ChangeOfPartyRequest 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; } } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs index 228f166868..59ab980b28 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.TestHelpers/ObjectExtensions.cs @@ -1,11 +1,16 @@ -namespace SFA.DAS.CommitmentsV2.TestHelpers +using System; +using System.Linq.Expressions; + +namespace SFA.DAS.CommitmentsV2.TestHelpers { public static class ObjectExtensions { - public static void SetValue(this object o, string propertyName, object value) + public static void SetValue(this T o, Expression> propertySelector, object value) { var t = o.GetType(); - t.GetProperty(propertyName).SetValue(o, value, null); + var body = (MemberExpression)propertySelector.Body; + t.GetProperty(body.Member.Name).SetValue(o, value, null); } + } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs index d8deb57875..d5fe7a4bc5 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandlerTests.cs @@ -42,11 +42,13 @@ public class ChangeOfPartyRequestsQueryHandlersTestsFixture private readonly Fixture _autoFixture; private List _changeOfPartyRequests; private readonly long _apprenticeshipId; + private readonly string _employerName; public ChangeOfPartyRequestsQueryHandlersTestsFixture() { _autoFixture = new Fixture(); + _employerName = _autoFixture.Create(); _apprenticeshipId = _autoFixture.Create(); _request = new GetChangeOfPartyRequestsQuery(_apprenticeshipId); @@ -55,7 +57,6 @@ public ChangeOfPartyRequestsQueryHandlersTestsFixture() _handler = new GetChangeOfPartyRequestsQueryHandler(new Lazy(() => _db)); } - public async Task Handle() { _result = await _handler.Handle(TestHelper.Clone(_request), new CancellationToken()); @@ -64,19 +65,24 @@ public async Task Handle() private void SeedData() { + var employer = new AccountLegalEntity(); + employer.SetValue(x => x.Name, _employerName); + _changeOfPartyRequests = new List(); for (var i = 1; i <= 10; i++) { var request = new ChangeOfPartyRequest(); - request.SetValue("Id", i); - request.SetValue("ApprenticeshipId", _apprenticeshipId); - request.SetValue("ChangeOfPartyType", _autoFixture.Create()); - request.SetValue("OriginatingParty", _autoFixture.Create()); - request.SetValue("Status", _autoFixture.Create()); + request.SetValue(x => x.Id, i); + request.SetValue(x => x.ApprenticeshipId, _apprenticeshipId); + request.SetValue(x => x.ChangeOfPartyType, _autoFixture.Create()); + request.SetValue(x => x.OriginatingParty, _autoFixture.Create()); + request.SetValue(x => x.Status, _autoFixture.Create()); + request.SetValue(x => x.AccountLegalEntity, employer); _changeOfPartyRequests.Add(request); } + _db.AccountLegalEntities.Add(employer); _db.ChangeOfPartyRequests.AddRange(_changeOfPartyRequests); _db.SaveChanges(); } @@ -87,7 +93,9 @@ public void VerifyResultMapping() foreach (var sourceItem in _changeOfPartyRequests) { - AssertEquality(sourceItem, _result.ChangeOfPartyRequests.Single(x => x.Id == sourceItem.Id)); + var resultItem = _result.ChangeOfPartyRequests.Single(x => x.Id == sourceItem.Id); + AssertEquality(sourceItem, resultItem); + Assert.AreEqual(_employerName, resultItem.EmployerName); } } } @@ -98,6 +106,8 @@ private static void AssertEquality(ChangeOfPartyRequest source, GetChangeOfParty Assert.AreEqual(source.ChangeOfPartyType, result.ChangeOfPartyType); Assert.AreEqual(source.OriginatingParty, result.OriginatingParty); Assert.AreEqual(source.Status, result.Status); + Assert.AreEqual(source.StartDate, result.StartDate); + Assert.AreEqual(source.Price, result.Price); } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs index 8b75110eef..360ea5e99f 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryHandler.cs @@ -21,13 +21,18 @@ public async Task Handle(GetChangeOfPartyRe { return new GetChangeOfPartyRequestsQueryResult { - ChangeOfPartyRequests = await _dbContext.Value.ChangeOfPartyRequests.Where(x => x.ApprenticeshipId == request.ApprenticeshipId) + ChangeOfPartyRequests = await _dbContext.Value + .ChangeOfPartyRequests.Where(x => x.ApprenticeshipId == request.ApprenticeshipId) + .Include(a => a.Apprenticeship.Cohort.AccountLegalEntity) .Select(r => new GetChangeOfPartyRequestsQueryResult.ChangeOfPartyRequest { Id = r.Id, OriginatingParty = r.OriginatingParty, ChangeOfPartyType = r.ChangeOfPartyType, - Status = r.Status + Status = r.Status, + StartDate = r.StartDate, + Price = r.Price, + EmployerName = r.AccountLegalEntity.Name }).ToListAsync(cancellationToken) }; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs index cd7001e689..674c59d716 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetChangeOfPartyRequests/GetChangeOfPartyRequestsQueryResult.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using SFA.DAS.CommitmentsV2.Types; namespace SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests @@ -13,6 +14,9 @@ public class ChangeOfPartyRequest public ChangeOfPartyRequestType ChangeOfPartyType { get; set; } public Party OriginatingParty { get; set; } public ChangeOfPartyRequestStatus Status { get; set; } + public string EmployerName { get; set; } + public int Price { get; set; } + public DateTime StartDate { get; set; } } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/Configuration/ChangeOfPartyRequestConfiguration.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/Configuration/ChangeOfPartyRequestConfiguration.cs index 59f393c9a8..490f86613c 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/Configuration/ChangeOfPartyRequestConfiguration.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/Configuration/ChangeOfPartyRequestConfiguration.cs @@ -16,6 +16,11 @@ public void Configure(EntityTypeBuilder builder) .WithMany(p => p.ChangeOfPartyRequests) .HasForeignKey(d => d.ApprenticeshipId) .OnDelete(DeleteBehavior.ClientSetNull); + + builder.HasOne(d => d.AccountLegalEntity) + .WithMany(p => p.ChangeOfPartyRequests) + .HasForeignKey(d => d.AccountLegalEntityId) + .OnDelete(DeleteBehavior.ClientSetNull); } } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs index 8d8bae984b..eec164498d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Mapping/ResponseMappers/GetChangeOfPartyRequestsResponseMapper.cs @@ -18,7 +18,10 @@ public Task Map(GetChangeOfPartyRequestsQueryR Id = r.Id, ChangeOfPartyType = r.ChangeOfPartyType, OriginatingParty = r.OriginatingParty, - Status = r.Status + Status = r.Status, + EmployerName = r.EmployerName, + StarDate = r.StartDate, + Price = r.Price }).ToList() }); } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/AccountLegalEntity.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/AccountLegalEntity.cs index fcccc0c198..eff5b64642 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/AccountLegalEntity.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/AccountLegalEntity.cs @@ -21,6 +21,7 @@ public class AccountLegalEntity : ICohortOriginator public DateTime? Deleted { get; private set; } public virtual ICollection Cohorts { get; set; } + public virtual ICollection ChangeOfPartyRequests { get; set; } public AccountLegalEntity(Account account, long id, long maLegalEntityId, string legalEntityId, string publicHashedId, string name, OrganisationType organisationType, string address, DateTime created) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/ChangeOfPartyRequest.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/ChangeOfPartyRequest.cs index 3adacfc83c..c4fb698e8a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/ChangeOfPartyRequest.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/ChangeOfPartyRequest.cs @@ -25,6 +25,7 @@ public class ChangeOfPartyRequest : Aggregate, ITrackableEntity public DateTime LastUpdatedOn { get; private set; } public virtual Apprenticeship Apprenticeship { get; private set; } + public virtual AccountLegalEntity AccountLegalEntity { get; private set; } public ChangeOfPartyRequest() { diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/Cohort.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/Cohort.cs index 36209d4c0c..6294561d5c 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/Cohort.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Models/Cohort.cs @@ -374,7 +374,6 @@ public void DeleteDraftApprenticeship(long draftApprenticeshipId, Party modifyin StartTrackingSession(UserAction.DeleteDraftApprenticeship, modifyingParty, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); - ChangeTrackingSession.TrackDelete(draftApprenticeship); RemoveDraftApprenticeship(draftApprenticeship); From 050d7e51b1895b6dae5a55d1864900070948c00f Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 17 Apr 2020 15:09:23 +0100 Subject: [PATCH 10/21] modified employer with alerts logic --- ...WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 3 ++- .../Domain/Extensions/AlertsExtensions.cs | 6 +++--- .../Extensions/QueryableApprenticeshipsExtensions.cs | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index d5fff9ea32..70a224e2ff 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -38,7 +38,7 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); //Assert - Assert.AreEqual(6, result.Count); + Assert.AreEqual(7, result.Count); Assert.AreEqual(1, result[0].Id); Assert.AreEqual(2, result[1].Id); @@ -46,6 +46,7 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() Assert.AreEqual(5, result[3].Id); Assert.AreEqual(6, result[4].Id); Assert.AreEqual(7, result[5].Id); + Assert.AreEqual(9, result[6].Id); } private static IQueryable GetTestData() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index ecf756def4..9d09e7714e 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -51,7 +51,7 @@ public static IEnumerable MapAlerts(this Apprenticeship source) return result; } - public static bool HasCourseDataLock(Apprenticeship source) + private static bool HasCourseDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.WithCourseError() && @@ -59,7 +59,7 @@ public static bool HasCourseDataLock(Apprenticeship source) !x.IsResolved); } - public static bool HasPriceDataLock(Apprenticeship source) + private static bool HasPriceDataLock(Apprenticeship source) { return source.DataLockStatus.Any(x => x.IsPriceOnly() && @@ -92,7 +92,7 @@ private static bool HasCourseDataLockChangesRequested(Apprenticeship source) } - private static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) + public static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) { return !source.IsProviderSearch && source.DataLockStatus.Any(x => x.Status == Status.Fail && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 242c45c755..cff4f7349e 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -150,8 +150,7 @@ public static IQueryable WithAlertsEmployer(this IQueryable c.Status != ApprenticeshipUpdateStatus.Pending))); return apprenticesWithAlerts.Where - (x => !AlertsExtensions.HasCourseDataLock(x) - && !AlertsExtensions.HasPriceDataLock(x)); + (x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); } public static IQueryable WithProviderOrEmployerId( From db4bd5615a70f951dc3b831035495986495272ed Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 17 Apr 2020 15:13:53 +0100 Subject: [PATCH 11/21] slight change to employer with alerts --- .../Extensions/QueryableApprenticeshipsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 72675bb248..52d6462ea6 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -149,7 +149,7 @@ public static IQueryable WithAlertsEmployer(this IQueryablec.TriageStatus == TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); - (x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); + return apprenticesWithAlerts.Where(x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); } public static IQueryable WithProviderOrEmployerId( From 128c39223c122dadad62d3a1baf31162f94f80fb Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Fri, 17 Apr 2020 17:12:37 +0100 Subject: [PATCH 12/21] more with alerts stuff --- ...WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 3 +-- .../Domain/Extensions/AlertsExtensions.cs | 6 +++--- .../Extensions/QueryableApprenticeshipsExtensions.cs | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index 88f88d2a2c..e658d68851 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -38,7 +38,7 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); //Assert - Assert.AreEqual(7, result.Count); + Assert.AreEqual(6, result.Count); Assert.AreEqual(2, result[0].Id); Assert.AreEqual(4, result[1].Id); @@ -46,7 +46,6 @@ public void ThenWillReturnApprenticeshipsWithoutAlerts() Assert.AreEqual(6, result[3].Id); Assert.AreEqual(7, result[4].Id); Assert.AreEqual(9, result[5].Id); - Assert.AreEqual(9, result[6].Id); } private static IQueryable GetTestData() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index 9d09e7714e..90cd7376a3 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -61,7 +61,7 @@ private static bool HasCourseDataLock(Apprenticeship source) private static bool HasPriceDataLock(Apprenticeship source) { - return source.DataLockStatus.Any(x => + return source.IsProviderSearch && source.DataLockStatus.Any(x => x.IsPriceOnly() && x.TriageStatus == TriageStatus.Unknown && !x.IsResolved); @@ -69,7 +69,7 @@ private static bool HasPriceDataLock(Apprenticeship source) private static bool HasCourseDataLockPendingChanges(Apprenticeship source) { - return source.DataLockStatus.Any(x => + return source.IsProviderSearch && source.DataLockStatus.Any(x => x.WithCourseError() && x.TriageStatus == TriageStatus.Change && !x.IsResolved); @@ -92,7 +92,7 @@ private static bool HasCourseDataLockChangesRequested(Apprenticeship source) } - public static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) + private static bool EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(Apprenticeship source) { return !source.IsProviderSearch && source.DataLockStatus.Any(x => x.Status == Status.Fail && diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 52d6462ea6..767c76eab1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -144,12 +144,11 @@ public static IQueryable WithAlertsEmployer(this IQueryable + return apprenticeships.Where(apprenticeship => !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed) && apprenticeship.DataLockStatus.All(c=>c.TriageStatus == TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); - return apprenticesWithAlerts.Where(x => !AlertsExtensions.EmployerHasUnresolvedErrorsThatHaveKnownTriageStatus(x)); } public static IQueryable WithProviderOrEmployerId( From b3b1ad7752d46f9f597f3aa3adabb9163b017bec Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Mon, 20 Apr 2020 07:09:52 +0100 Subject: [PATCH 13/21] Adds datetime extension methods for all variations --- .../Extensions/DateTimeExtensionsTests.cs | 15 +++++++++++++++ .../Extensions/DateTimeExtensions.cs | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared.UnitTests/Extensions/DateTimeExtensionsTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared.UnitTests/Extensions/DateTimeExtensionsTests.cs index 7b650264f0..3a01b6accf 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared.UnitTests/Extensions/DateTimeExtensionsTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared.UnitTests/Extensions/DateTimeExtensionsTests.cs @@ -14,11 +14,26 @@ public void ToGdsFormatReturnsFormattedResultCorrectly(DateTime value, string ex Assert.AreEqual(expectedResult, value.ToGdsFormat()); } + [TestCase("2019-03-01", "1 March 2019")] + [TestCase("2020-10-20", "20 October 2020")] + public void ToGdsFormatLongMonthReturnsFormattedResultCorrectly(DateTime value, string expectedResult) + { + Assert.AreEqual(expectedResult, value.ToGdsFormatLongMonth()); + } + [TestCase("2019-03-01", "Mar 2019")] [TestCase("2020-10-20", "Oct 2020")] public void ToGdsFormatWithoutDayReturnsFormattedResultCorrectly(DateTime value, string expectedResult) { Assert.AreEqual(expectedResult, value.ToGdsFormatWithoutDay()); } + + [TestCase("2019-03-01", "March 2019")] + [TestCase("2020-10-20", "October 2020")] + public void ToGdsFormatLongMonthWithoutDayReturnsFormattedResultCorrectly(DateTime value, string expectedResult) + { + Assert.AreEqual(expectedResult, value.ToGdsFormatLongMonthWithoutDay()); + } + } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared/Extensions/DateTimeExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared/Extensions/DateTimeExtensions.cs index ae41ef68ab..55bcecbe0d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared/Extensions/DateTimeExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Shared/Extensions/DateTimeExtensions.cs @@ -8,9 +8,17 @@ public static string ToGdsFormat(this DateTime value) { return $"{value:d MMM yyyy}"; } + public static string ToGdsFormatLongMonth(this DateTime value) + { + return $"{value:d MMMM yyyy}"; + } public static string ToGdsFormatWithoutDay(this DateTime value) { return $"{value:MMM yyyy}"; } + public static string ToGdsFormatLongMonthWithoutDay(this DateTime value) + { + return $"{value:MMMM yyyy}"; + } } } From b3242c869d10167033d9546085e23f6bd808d1ac Mon Sep 17 00:00:00 2001 From: chrisfoster186 Date: Mon, 20 Apr 2020 08:59:07 +0100 Subject: [PATCH 14/21] Renamed some classes --- ...Tests.cs => CreateChangeOfPartyCommandHandlerTests.cs} | 8 ++++---- ...sts.cs => CreateChangeOfPartyRequestValidatorTests.cs} | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/{ChangeOfPartyCommandHandlerTests.cs => CreateChangeOfPartyCommandHandlerTests.cs} (87%) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/{ChangeOfPartyRequestValidatorTests.cs => CreateChangeOfPartyRequestValidatorTests.cs} (96%) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/CreateChangeOfPartyCommandHandlerTests.cs similarity index 87% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/CreateChangeOfPartyCommandHandlerTests.cs index 72e06a42b2..f18463f6df 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyCommandHandlerTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/CreateChangeOfPartyCommandHandlerTests.cs @@ -11,12 +11,12 @@ namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Commands { [TestFixture] [Parallelizable] - public class ChangeOfPartyCommandHandlerTests + public class CreateChangeOfPartyCommandHandlerTests { [Test] public async Task Handle_WhenHandlingCommand_ThenShouldCallDomainServiceCorrectly() { - var f = new ChangeOfPartyCommandHandlerTestsFixture(); + var f = new CreateChangeOfPartyCommandHandlerTestsFixture(); await f.Handle(); @@ -26,7 +26,7 @@ public async Task Handle_WhenHandlingCommand_ThenShouldCallDomainServiceCorrectl } } - public class ChangeOfPartyCommandHandlerTestsFixture + public class CreateChangeOfPartyCommandHandlerTestsFixture { public Fixture AutoFixture { get; set; } public Mock ChangeOfPartyDomainService { get; set; } @@ -34,7 +34,7 @@ public class ChangeOfPartyCommandHandlerTestsFixture public CreateChangeOfPartyRequestCommand Command { get; set; } public CancellationToken CancellationToken { get; set; } - public ChangeOfPartyCommandHandlerTestsFixture() + public CreateChangeOfPartyCommandHandlerTestsFixture() { AutoFixture = new Fixture(); ChangeOfPartyDomainService = new Mock(); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/CreateChangeOfPartyRequestValidatorTests.cs similarity index 96% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/CreateChangeOfPartyRequestValidatorTests.cs index fc76e1442a..f6c3b395cb 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/ChangeOfPartyRequestValidatorTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Commands/CreateChangeOfPartyRequestValidatorTests.cs @@ -9,7 +9,7 @@ namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Commands { [TestFixture] [Parallelizable] - public class ChangeOfPartyRequestValidatorTests + public class CreateChangeOfPartyRequestValidatorTests { [TestCase(0, false)] [TestCase(1, true)] From 4998195b61b89595be720cf7d5d28a301bdfb092 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Mon, 20 Apr 2020 14:31:47 +0100 Subject: [PATCH 15/21] Correct query for employer alerts and non alerts --- .../SearchTests/SearchParameterServiceTestBase.cs | 6 ------ .../Extensions/QueryableApprenticeshipsExtensions.cs | 9 +++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs index 44839959d3..796f0f9596 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/SearchParameterServiceTestBase.cs @@ -62,8 +62,6 @@ protected static List GetTestApprenticeshipsWithAlerts(Apprentic CourseName = "Course", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(12), - ProviderRef = searchParameters.ProviderId.ToString(), - EmployerRef = searchParameters.EmployerAccountId.ToString(), Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")}, ApprenticeshipUpdate = new List(), DataLockStatus = new List() @@ -76,8 +74,6 @@ protected static List GetTestApprenticeshipsWithAlerts(Apprentic CourseName = "Course", StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(12), - ProviderRef = searchParameters.ProviderId.ToString(), - EmployerRef = searchParameters.EmployerAccountId.ToString(), Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")}, ApprenticeshipUpdate = new List(), DataLockStatus = new List() @@ -89,8 +85,6 @@ protected static List GetTestApprenticeshipsWithAlerts(Apprentic Uln = "Uln", CourseName = "Course", StartDate = DateTime.UtcNow, - ProviderRef = searchParameters.ProviderId.ToString(), - EmployerRef = searchParameters.EmployerAccountId.ToString(), Cohort = new Cohort {AccountLegalEntity = CreateAccountLegalEntity("Employer")}, ApprenticeshipUpdate = new List(), DataLockStatus = new List() diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 767c76eab1..938c50385d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -136,8 +136,8 @@ public static IQueryable WithAlertsEmployer(this IQueryable apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail - && c.EventStatus != EventStatus.Removed ) && - apprenticeship.DataLockStatus.All(c=>c.TriageStatus!= TriageStatus.Unknown) || + && c.EventStatus != EventStatus.Removed + || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) || apprenticeship.ApprenticeshipUpdate != null && apprenticeship.ApprenticeshipUpdate.Any( c => c.Status == ApprenticeshipUpdateStatus.Pending @@ -145,8 +145,9 @@ public static IQueryable WithAlertsEmployer(this IQueryable - !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed) && - apprenticeship.DataLockStatus.All(c=>c.TriageStatus == TriageStatus.Unknown) && + !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed + || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) && + (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); } From 3444bff1068645eb8c2d930b3f6a353437bd7d0e Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Tue, 21 Apr 2020 15:36:09 +0100 Subject: [PATCH 16/21] slight unit test fix --- .../WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index e658d68851..53fd39d592 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -27,8 +27,9 @@ public void ThenWillReturnApprenticeshipsWithAlerts() var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); //Assert - Assert.AreEqual(1, result.Count); - Assert.AreEqual(3, result[0].Id); + Assert.AreEqual(2, result.Count); + Assert.AreEqual(1, result[0].Id); + Assert.AreEqual(3, result[1].Id); } [Test] From 15b5bad1359216bad4746f24fe6742ee8f074412 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Tue, 21 Apr 2020 17:33:57 +0100 Subject: [PATCH 17/21] fixed incorrect extension change --- .../SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs index 90cd7376a3..fe19e7cb75 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Extensions/AlertsExtensions.cs @@ -69,7 +69,7 @@ private static bool HasPriceDataLock(Apprenticeship source) private static bool HasCourseDataLockPendingChanges(Apprenticeship source) { - return source.IsProviderSearch && source.DataLockStatus.Any(x => + return source.DataLockStatus.Any(x => x.WithCourseError() && x.TriageStatus == TriageStatus.Change && !x.IsResolved); From 8a429bedbf607ce93ae7ff6a08fe579bdd53a622 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Wed, 22 Apr 2020 10:58:04 +0100 Subject: [PATCH 18/21] Correct employer query for search --- .../WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs | 3 ++- .../Extensions/QueryableApprenticeshipsExtensions.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs index 53fd39d592..6537874848 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs @@ -62,7 +62,8 @@ private static IQueryable GetTestData() { IsResolved = false, Status = Status.Fail, - EventStatus = EventStatus.New + EventStatus = EventStatus.New, + TriageStatus = TriageStatus.Change } } }, diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 938c50385d..a5e78457bc 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -137,7 +137,7 @@ public static IQueryable WithAlertsEmployer(this IQueryable apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed - || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) || + && c.TriageStatus != TriageStatus.Unknown) || apprenticeship.ApprenticeshipUpdate != null && apprenticeship.ApprenticeshipUpdate.Any( c => c.Status == ApprenticeshipUpdateStatus.Pending @@ -146,7 +146,7 @@ public static IQueryable WithAlertsEmployer(this IQueryable !apprenticeship.DataLockStatus.Any(c => !c.IsResolved && c.Status == Status.Fail && c.EventStatus != EventStatus.Removed - || (!c.IsResolved && c.TriageStatus != TriageStatus.Unknown)) && + && c.TriageStatus != TriageStatus.Unknown) && (apprenticeship.ApprenticeshipUpdate == null || apprenticeship.ApprenticeshipUpdate.All(c => c.Status != ApprenticeshipUpdateStatus.Pending))); From 44f10b3e56dea18643ce0de3a9c5ea10726b0e88 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Apr 2020 11:54:07 +0100 Subject: [PATCH 19/21] Renamed unhelpfully named function. Also fixed some incorrect accessibility modifiers. --- .../WhenGettingApprenticeships.cs | 6 +++--- ...ttingEmployerApprenticeshipsWithOrWithoutAlerts.cs} | 4 ++-- ...ettingProviderApprenticeshipsWithOrWithoutAlerts.cs | 4 ++-- .../Search/Services/ApprenticeshipSearchService.cs | 2 +- .../Services/OrderedApprenticeshipSearchService.cs | 4 ++-- .../ReverseOrderedApprenticeshipSearchService.cs | 4 ++-- .../GetApprenticeshipsFilterValuesQueryHandler.cs | 10 +++++----- .../Extensions/QueryableApprenticeshipsExtensions.cs | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) rename src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/{WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs => WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs} (96%) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs index 1dce4a1c89..3261aea00b 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs @@ -28,7 +28,7 @@ public void Then_Returns_Provider_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.ProviderId == searchParameters.ProviderId); - var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); + var result = apprenticeships.AsQueryable().WithId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -53,7 +53,7 @@ public void Then_Returns_Employer_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.EmployerAccountId == searchParameters.EmployerAccountId); - var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); + var result = apprenticeships.AsQueryable().WithId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -73,7 +73,7 @@ public void Then_Returns_All_Apprenticeships_If_No_Provider_Or_Employer_Id_Found searchParameters.ProviderId = null; searchParameters.EmployerAccountId = null; - var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); + var result = apprenticeships.AsQueryable().WithId(searchParameters); result.Should().BeEquivalentTo(apprenticeships); } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs similarity index 96% rename from src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs rename to src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs index 53fd39d592..f2ce8b967a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerAppernticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingEmployerApprenticeshipsWithOrWithoutAlerts.cs @@ -24,7 +24,7 @@ public void Arrange() public void ThenWillReturnApprenticeshipsWithAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(true, _parameters).ToList(); //Assert Assert.AreEqual(2, result.Count); @@ -36,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts() public void ThenWillReturnApprenticeshipsWithoutAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(false, _parameters).ToList(); //Assert Assert.AreEqual(6, result.Count); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs index 315c93d943..a98ef73336 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingProviderApprenticeshipsWithOrWithoutAlerts.cs @@ -24,7 +24,7 @@ public void Arrange() public void ThenWillReturnApprenticeshipsWithAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(true, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(true, _parameters).ToList(); //Assert Assert.AreEqual(2, result.Count); @@ -36,7 +36,7 @@ public void ThenWillReturnApprenticeshipsWithAlerts() public void ThenWillReturnApprenticeshipsWithoutAlerts() { //Act - var result = _apprenticeships.WithAlertsProviderOrEmployer(false, _parameters).ToList(); + var result = _apprenticeships.WithAlerts(false, _parameters).ToList(); //Assert Assert.AreEqual(5, result.Count); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs index 9dbdae7eff..fa987c67ef 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs @@ -223,7 +223,7 @@ private IQueryable GetApprenticeshipsQuery(ApprenticeshipSearchP private IQueryable GetApprenticeshipsWithFiltersQuery(ApprenticeshipSearchParameters searchParameters, bool withAlerts) { return GetApprenticeshipsQuery(searchParameters) - .WithAlertsProviderOrEmployer(withAlerts, searchParameters) + .WithAlerts(withAlerts, searchParameters) .Filter(searchParameters.Filters); } } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 9ec696575d..334a545e1b 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -20,14 +20,14 @@ public async Task Find(OrderedApprenticeshipSearchPa { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithProviderOrEmployerId(searchParameters) + .WithId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderBy(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index b681f9b303..67034d6624 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -20,14 +20,14 @@ public async Task Find(ReverseOrderedApprenticeshipS { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithProviderOrEmployerId(searchParameters) + .WithId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery.Filter(searchParameters.Filters); - var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlertsProviderOrEmployer(true, searchParameters).CountAsync(searchParameters.CancellationToken); + var totalApprenticeshipsWithAlertsFound = await apprenticeshipsQuery.WithAlerts(true, searchParameters).CountAsync(searchParameters.CancellationToken); apprenticeshipsQuery = apprenticeshipsQuery .OrderByDescending(GetOrderByField(searchParameters.FieldName)) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs index c392f47965..20fd7d7820 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs @@ -101,7 +101,7 @@ public async Task Handle(GetApprentic private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Select(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Distinct() @@ -111,7 +111,7 @@ private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValu private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.Provider.Name) .Select(apprenticeship => apprenticeship.Cohort.Provider.Name) .Distinct() @@ -121,7 +121,7 @@ private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValu private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .OrderBy(apprenticeship => apprenticeship.CourseName) .Select(apprenticeship => apprenticeship.CourseName) .Distinct() @@ -131,7 +131,7 @@ private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValues private Task> GetDistinctStartDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .Where(apprenticeship => apprenticeship.StartDate.HasValue) .OrderBy(apprenticeship => apprenticeship.StartDate) .Select(apprenticeship => apprenticeship.StartDate.Value) @@ -142,7 +142,7 @@ private Task> GetDistinctStartDates(GetApprenticeshipsFilterValue private Task> GetDistinctEndDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithProviderOrEmployerId(request) + .WithId(request) .Where(apprenticeship => apprenticeship.EndDate.HasValue) .OrderBy(apprenticeship => apprenticeship.EndDate) .Select(apprenticeship => apprenticeship.EndDate.Value) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs index 938c50385d..47df6214de 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Extensions/QueryableApprenticeshipsExtensions.cs @@ -106,14 +106,14 @@ public static IQueryable Filter(this IQueryable return apprenticeships; } - public static IQueryable WithAlertsProviderOrEmployer( + public static IQueryable WithAlerts( this IQueryable apprenticeships, bool hasAlerts, IEmployerProviderIdentifier identifier) { return identifier.ProviderId.HasValue ? WithAlertsProvider(apprenticeships, hasAlerts) : WithAlertsEmployer(apprenticeships, hasAlerts); } - public static IQueryable WithAlertsProvider(this IQueryable apprenticeships, bool hasAlerts) + private static IQueryable WithAlertsProvider(this IQueryable apprenticeships, bool hasAlerts) { if (hasAlerts) { @@ -130,7 +130,7 @@ public static IQueryable WithAlertsProvider(this IQueryable c.Status != ApprenticeshipUpdateStatus.Pending))); } - public static IQueryable WithAlertsEmployer(this IQueryable apprenticeships, bool hasAlerts) + private static IQueryable WithAlertsEmployer(this IQueryable apprenticeships, bool hasAlerts) { if (hasAlerts) { From 3679d94f7a4587659e996ebffba2dbb00a0286c5 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Apr 2020 12:04:27 +0100 Subject: [PATCH 20/21] fixed poorly done refactoring --- .../WhenGettingApprenticeships.cs | 6 +++--- .../Services/OrderedApprenticeshipSearchService.cs | 2 +- .../ReverseOrderedApprenticeshipSearchService.cs | 2 +- .../GetApprenticeshipsFilterValuesQueryHandler.cs | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs index 3261aea00b..1dce4a1c89 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Extensions/QueryableApprenticeshipsExtensions/WhenGettingApprenticeships.cs @@ -28,7 +28,7 @@ public void Then_Returns_Provider_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.ProviderId == searchParameters.ProviderId); - var result = apprenticeships.AsQueryable().WithId(searchParameters); + var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -53,7 +53,7 @@ public void Then_Returns_Employer_Apprenticeships( var expectedApprenticeships = apprenticeships.Where(app => app.Cohort.EmployerAccountId == searchParameters.EmployerAccountId); - var result = apprenticeships.AsQueryable().WithId(searchParameters); + var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); result.Count() .Should().Be(apprenticeships @@ -73,7 +73,7 @@ public void Then_Returns_All_Apprenticeships_If_No_Provider_Or_Employer_Id_Found searchParameters.ProviderId = null; searchParameters.EmployerAccountId = null; - var result = apprenticeships.AsQueryable().WithId(searchParameters); + var result = apprenticeships.AsQueryable().WithProviderOrEmployerId(searchParameters); result.Should().BeEquivalentTo(apprenticeships); } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 334a545e1b..99ff875fa7 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -20,7 +20,7 @@ public async Task Find(OrderedApprenticeshipSearchPa { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithId(searchParameters) + .WithProviderOrEmployerId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index 67034d6624..72cf89b1dd 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -20,7 +20,7 @@ public async Task Find(ReverseOrderedApprenticeshipS { var apprenticeshipsQuery = _dbContext .Apprenticeships - .WithId(searchParameters) + .WithProviderOrEmployerId(searchParameters) .DownloadsFilter(searchParameters.PageNumber == 0); var totalAvailableApprenticeships = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs index 20fd7d7820..c392f47965 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeshipsFilterValues/GetApprenticeshipsFilterValuesQueryHandler.cs @@ -101,7 +101,7 @@ public async Task Handle(GetApprentic private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Select(apprenticeship => apprenticeship.Cohort.AccountLegalEntity.Name) .Distinct() @@ -111,7 +111,7 @@ private Task> GetDistinctEmployerNames(GetApprenticeshipsFilterValu private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .OrderBy(apprenticeship => apprenticeship.Cohort.Provider.Name) .Select(apprenticeship => apprenticeship.Cohort.Provider.Name) .Distinct() @@ -121,7 +121,7 @@ private Task> GetDistinctProviderNames(GetApprenticeshipsFilterValu private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .OrderBy(apprenticeship => apprenticeship.CourseName) .Select(apprenticeship => apprenticeship.CourseName) .Distinct() @@ -131,7 +131,7 @@ private Task> GetDistinctCourseNames(GetApprenticeshipsFilterValues private Task> GetDistinctStartDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .Where(apprenticeship => apprenticeship.StartDate.HasValue) .OrderBy(apprenticeship => apprenticeship.StartDate) .Select(apprenticeship => apprenticeship.StartDate.Value) @@ -142,7 +142,7 @@ private Task> GetDistinctStartDates(GetApprenticeshipsFilterValue private Task> GetDistinctEndDates(GetApprenticeshipsFilterValuesQuery request, CancellationToken cancellationToken) { return _dbContext.Apprenticeships - .WithId(request) + .WithProviderOrEmployerId(request) .Where(apprenticeship => apprenticeship.EndDate.HasValue) .OrderBy(apprenticeship => apprenticeship.EndDate) .Select(apprenticeship => apprenticeship.EndDate.Value) From 8ee266aa20120de7804b8fd5879538abe3c5e100 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Thu, 23 Apr 2020 09:11:36 +0100 Subject: [PATCH 21/21] Add missing include for provider on search sorting (cherry picked from commit 76a8268c7e4d7ea5df4e086fdd6e705bfd243b60) --- .../Search/Services/OrderedApprenticeshipSearchService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index 99ff875fa7..59530b064d 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -35,7 +35,9 @@ public async Task Find(OrderedApprenticeshipSearchPa .Include(apprenticeship => apprenticeship.ApprenticeshipUpdate) .Include(apprenticeship => apprenticeship.DataLockStatus) .Include(apprenticeship => apprenticeship.Cohort) - .ThenInclude(cohort => cohort.AccountLegalEntity); + .ThenInclude(cohort => cohort.AccountLegalEntity) + .Include(apprenticeship => apprenticeship.Cohort) + .ThenInclude(cohort => cohort.Provider); var totalApprenticeshipsFound = await apprenticeshipsQuery.CountAsync(searchParameters.CancellationToken);