Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public class AddDraftApprenticeshipRequest : SaveDataRequest
public DateTime? EmploymentEndDate { get; set; }
public bool IgnoreStartDateOverlap { get; set; }
public bool? IsOnFlexiPaymentPilot { get; set; }
public LearnerVerificationResponse LearnerVerificationResponse { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public class CreateCohortRequest : SaveDataRequest
public DateTime? EmploymentEndDate { get; set; }
public bool IgnoreStartDateOverlap { get; set; }
public bool? IsOnFlexiPaymentPilot { get; set; }
public LearnerVerificationResponse LearnerVerificationResponse { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public class UpdateDraftApprenticeshipRequest : SaveDataRequest
public Guid? ReservationId { get; set; }
public bool IgnoreStartDateOverlap { get; set; }
public bool? IsOnFlexiPaymentPilot { get; set; }
public LearnerVerificationResponse LearnerVerificationResponse { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public CreateTestsFixture()
c.Uln == Request.Uln &&
c.TransferSenderId == Request.TransferSenderId &&
c.PledgeApplicationId == Request.PledgeApplicationId &&
c.UserInfo == Request.UserInfo), CancellationToken.None))
c.UserInfo == Request.UserInfo &&
c.IsOnFlexiPaymentPilot == Request.IsOnFlexiPaymentPilot &&
c.LearnerVerificationResponse == Request.LearnerVerificationResponse), CancellationToken.None))
.ReturnsAsync(Result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public async Task<IActionResult> Create([FromBody]CreateCohortRequest request)
request.EmploymentEndDate,
request.UserInfo,
request.IgnoreStartDateOverlap,
request.IsOnFlexiPaymentPilot);
request.IsOnFlexiPaymentPilot,
request.LearnerVerificationResponse);

var result = await _mediator.Send(command);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;

namespace SFA.DAS.CommitmentsV2.Types
{
public enum LearnerVerificationResponseType
{
SuccessfulMatch,

SuccessfulLinkedMatch,

SimilarMatch,

SimilarLinkedMatch,

LearnerDoesNotMatch,

UlnNotFound
}

public enum LearnerDetailMatchingError
{
GivenDoesntMatchGiven,

GivenDoesntMatchFamily,

GivenDoesntMatchPreviousFamily,

FamilyDoesntMatchGiven,

FamilyDoesntMatchFamily,

FamilyDoesntMatchPreviousFamily,

DateOfBirthDoesntMatchDateOfBirth,

GenderDoesntMatchGender
}

public class LearnerVerificationResponse
{
public LearnerVerificationResponseType ResponseType { get; set; }

public IEnumerable<LearnerDetailMatchingError> MatchingErrors { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -44,6 +43,7 @@ public async Task ShouldCreateCohort()
It.IsAny<DraftApprenticeshipDetails>(),
fixtures.UserInfo,
fixtures.RequestingParty,
It.IsAny<LearnerVerificationResponse>(),
It.IsAny<CancellationToken>()));

Assert.AreEqual(expectedHash, response.Reference);
Expand All @@ -54,6 +54,10 @@ public class TestLogger : ILogger<AddCohortHandler>
{
private readonly List<(LogLevel logLevel, Exception exception, string message)> _logMessages = new List<(LogLevel logLevel, Exception exception, string message)>();

public bool HasErrors => _logMessages.Any(l => l.logLevel == LogLevel.Error);

public bool HasInfo => _logMessages.Any(l => l.logLevel == LogLevel.Information);

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
_logMessages.Add((logLevel, exception, formatter(state, exception)));
Expand All @@ -68,17 +72,10 @@ public IDisposable BeginScope<TState>(TState state)
{
throw new NotImplementedException();
}

public bool HasErrors => _logMessages.Any(l => l.logLevel == LogLevel.Error);
public bool HasInfo => _logMessages.Any(l => l.logLevel == LogLevel.Information);
}

public class AddCohortCommandHandlerTestFixture
{
public ProviderCommitmentsDbContext Db { get; set; }

public Mock<Provider> Provider { get; set; }

public AddCohortCommandHandlerTestFixture()
{
Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder<ProviderCommitmentsDbContext>()
Expand All @@ -96,14 +93,18 @@ public AddCohortCommandHandlerTestFixture()
commitment.Apprenticeships.Add(new DraftApprenticeship());

CohortDomainServiceMock = new Mock<ICohortDomainService>();
CohortDomainServiceMock.Setup(x => x.CreateCohort(It.IsAny<long>(), It.IsAny<long>(), It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<int?>(),
It.IsAny<DraftApprenticeshipDetails>(), It.IsAny<UserInfo>(), It.IsAny<Party>(), It.IsAny<CancellationToken>()))
CohortDomainServiceMock
.Setup(x => x.CreateCohort(It.IsAny<long>(), It.IsAny<long>(), It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<int?>(),
It.IsAny<DraftApprenticeshipDetails>(), It.IsAny<UserInfo>(), It.IsAny<Party>(), It.IsAny<LearnerVerificationResponse>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(commitment);

Logger = new TestLogger();
UserInfo = new UserInfo();
}

public ProviderCommitmentsDbContext Db { get; set; }

public Mock<Provider> Provider { get; set; }
public Mock<IEncodingService> EncodingServiceMock { get; }
public IEncodingService EncodingService => EncodingServiceMock.Object;

Expand All @@ -113,6 +114,7 @@ public AddCohortCommandHandlerTestFixture()

public TestLogger Logger { get; }
public UserInfo UserInfo { get; }
public LearnerVerificationResponse LearnerVerificationResponse { get; }
public Party RequestingParty => Party.Provider;

public AddCohortCommandHandlerTestFixture WithGeneratedHash(string hash)
Expand All @@ -127,13 +129,13 @@ public AddCohortCommandHandlerTestFixture WithGeneratedHash(string hash)
public async Task<AddCohortResult> Handle(long accountId, long accountLegalEntity, long providerId, long? transferSenderId, int? pledgeApplicationId, string courseCode)
{
Db.SaveChanges();

var command = new AddCohortCommand(
RequestingParty,
accountId,
accountLegalEntity,
providerId,
courseCode,
courseCode,
null,
null,
null,
Expand All @@ -152,7 +154,8 @@ public async Task<AddCohortResult> Handle(long accountId, long accountLegalEntit
null,
UserInfo,
false,
false);
false,
LearnerVerificationResponse);

var handler = new AddCohortHandler(new Lazy<ProviderCommitmentsDbContext>(() => Db),
EncodingService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using FluentAssertions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
Expand All @@ -31,7 +30,7 @@ public Task Handle_WhenCommandIsHandled_ThenShouldAddDraftApprenticeship()
return TestAsync(
f => f.AddDraftApprenticeship(),
f => f.CohortDomainService.Verify(c => c.AddDraftApprenticeship(f.Command.ProviderId,
f.Command.CohortId, f.DraftApprenticeshipDetails, f.UserInfo, f.Command.RequestingParty, f.CancellationToken)));
f.Command.CohortId, f.DraftApprenticeshipDetails, f.UserInfo, f.Command.RequestingParty, f.LearnerVerificationResponse, f.CancellationToken)));
}

[Test]
Expand All @@ -57,12 +56,13 @@ public class AddDraftApprenticeshipCommandHandlerTestsFixture
public Mock<ICohortDomainService> CohortDomainService { get; set; }
public IRequestHandler<AddDraftApprenticeshipCommand, AddDraftApprenticeshipResult> Handler { get; set; }
public UserInfo UserInfo { get; }
public LearnerVerificationResponse LearnerVerificationResponse { get; }

public AddDraftApprenticeshipCommandHandlerTestsFixture()
{
Fixture = new Fixture();
DraftApprenticeshipDetails = Fixture.Build<DraftApprenticeshipDetails>()
.With(o => o.IgnoreStartDateOverlap,false)
.With(o => o.IgnoreStartDateOverlap, false)
.Create();
DraftApprenticeship = new DraftApprenticeship().Set(a => a.Id, 123);
CancellationToken = new CancellationToken();
Expand All @@ -74,8 +74,9 @@ public AddDraftApprenticeshipCommandHandlerTestsFixture()
CohortDomainService = new Mock<ICohortDomainService>();
DraftApprenticeshipDetailsMapper = new Mock<IOldMapper<AddDraftApprenticeshipCommand, DraftApprenticeshipDetails>>();
UserInfo = Fixture.Create<UserInfo>();
LearnerVerificationResponse = Fixture.Create<LearnerVerificationResponse>();

Command = Fixture.Build<AddDraftApprenticeshipCommand>().With(o => o.UserInfo, UserInfo).Without(x => x.IgnoreStartDateOverlap).Create();
Command = Fixture.Build<AddDraftApprenticeshipCommand>().With(o => o.UserInfo, UserInfo).With(o => o.LearnerVerificationResponse, LearnerVerificationResponse).Without(x => x.IgnoreStartDateOverlap).Create();

Handler = new AddDraftApprenticeshipCommandHandler(
new Lazy<ProviderCommitmentsDbContext>(() => Db),
Expand All @@ -84,7 +85,7 @@ public AddDraftApprenticeshipCommandHandlerTestsFixture()
CohortDomainService.Object);

CohortDomainService.Setup(s => s.AddDraftApprenticeship(Command.ProviderId, Command.CohortId,
DraftApprenticeshipDetails, Command.UserInfo, Command.RequestingParty, CancellationToken)).ReturnsAsync(DraftApprenticeship);
DraftApprenticeshipDetails, Command.UserInfo, Command.RequestingParty, Command.LearnerVerificationResponse, CancellationToken)).ReturnsAsync(DraftApprenticeship);
DraftApprenticeshipDetailsMapper.Setup(m => m.Map(Command)).ReturnsAsync(DraftApprenticeshipDetails);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public AddCohortCommandToDraftApprenticeshipDetailsMapperTestsFixture()
Command = new AddCohortCommand(command.RequestingParty, command.AccountId, command.AccountLegalEntityId, command.ProviderId,
courseCode, command.DeliveryModel, command.Cost, command.StartDate, command.ActualStartDate, command.EndDate, command.OriginatorReference,
command.ReservationId, command.FirstName, command.LastName, command.Email, command.DateOfBirth,
command.Uln, command.TransferSenderId, command.PledgeApplicationId, command.EmploymentPrice, command.EmploymentEndDate, command.UserInfo, true, true);
command.Uln, command.TransferSenderId, command.PledgeApplicationId, command.EmploymentPrice, command.EmploymentEndDate, command.UserInfo, true, true, command.LearnerVerificationResponse);

AuthorizationService = new Mock<IAuthorizationService>();
TrainingProgrammeLookup = new Mock<ITrainingProgrammeLookup>();
Expand Down Expand Up @@ -194,7 +194,7 @@ private AddCohortCommand AddCohortCommandNoDate()
return new AddCohortCommand(Command.RequestingParty, Command.AccountId, Command.AccountLegalEntityId, Command.ProviderId,
Command.CourseCode, Command.DeliveryModel, Command.Cost, null, null, null, Command.OriginatorReference, Command.ReservationId,
Command.FirstName, Command.LastName, Command.Email, Command.DateOfBirth, Command.Uln,
Command.TransferSenderId, Command.PledgeApplicationId, Command.EmploymentPrice, Command.EmploymentEndDate, Command.UserInfo, false, false);
Command.TransferSenderId, Command.PledgeApplicationId, Command.EmploymentPrice, Command.EmploymentEndDate, Command.UserInfo, false, false, Command.LearnerVerificationResponse);
}

public Task<DraftApprenticeshipDetails> MapWithFramework()
Expand All @@ -217,7 +217,7 @@ private AddCohortCommand CommandWithFramework()
return new AddCohortCommand(Command.RequestingParty, Command.AccountId, Command.AccountLegalEntityId, Command.ProviderId,
frameworkId, Command.DeliveryModel, Command.Cost, Command.StartDate, Command.ActualStartDate, Command.EndDate, Command.OriginatorReference, Command.ReservationId,
Command.FirstName, Command.LastName, Command.Email, Command.DateOfBirth, Command.Uln,
Command.TransferSenderId, Command.PledgeApplicationId, Command.EmploymentPrice, Command.EmploymentEndDate, Command.UserInfo, false, false);
Command.TransferSenderId, Command.PledgeApplicationId, Command.EmploymentPrice, Command.EmploymentEndDate, Command.UserInfo, false, false, Command.LearnerVerificationResponse);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Application.Commands.UpdateDraftApprenticeship;
Expand All @@ -9,17 +10,17 @@
namespace SFA.DAS.CommitmentsV2.UnitTests.Mapping.RequestToCommandMappers
{
[TestFixture]
public class UpdateDraftApprenticeshipRequestToUpdateDraftApprenticeshipCommandMapperTests :
public class UpdateDraftApprenticeshipRequestToUpdateDraftApprenticeshipCommandMapperTests :
OldMapperTester<UpdateDraftApprenticeshipRequestToUpdateDraftApprenticeshipCommandMapper,
UpdateDraftApprenticeshipRequest,
UpdateDraftApprenticeshipRequest,
UpdateDraftApprenticeshipCommand>
{
[Test]
public Task Map_CourseCode_ShouldBeSet()
{
return AssertPropertySet(from => from.CourseCode, "001/AAA");
}

[Test]
public Task Map_CostWithoutValue_ShouldBeSet()
{
Expand Down Expand Up @@ -56,7 +57,6 @@ public Task Map_StartDateWithValue_ShouldBeSet()
return AssertPropertySet(from => from.StartDate, (DateTime?)DateTime.Now);
}


[Test]
public Task Map_ActualStartDateWithoutValue_ShouldBeSet()
{
Expand Down Expand Up @@ -153,6 +153,18 @@ public Task Map_IsOnFlexiPaymentPilotWithValue_ShouldBeSet()
return AssertPropertySet(from => from.IsOnFlexiPaymentPilot, (bool?)true);
}

[Test]
public Task Map_LearnerVerificationResponseWithoutValue_ShouldBeSet()
{
return AssertPropertySet(from => from.LearnerVerificationResponse, (LearnerVerificationResponse)null);
}

[Test]
public Task Map_LearnerVerificationResponseWithValue_ShouldBeSet()
{
return AssertPropertySet(from => from.LearnerVerificationResponse, It.IsAny<LearnerVerificationResponse>());
}

[TestCase(DeliveryModel.Regular)]
[TestCase(DeliveryModel.PortableFlexiJob)]
public Task Map_DeliveryModel_ShouldBeSet(DeliveryModel dm)
Expand All @@ -166,4 +178,4 @@ public Task Map_RequestingParty_ShouldBeSet()
return AssertPropertySet(from => from.RequestingParty, (Party?)Party.Employer);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Task Map_WhenMapping_ThenShouldSetProperties()
public Task Map_WhenMapping_WithNoDate_VersionPropertiesNotSet()
{
return TestAsync(
f => f.MapNoDateAndNoVersionFields(),
f => f.MapNoDateAndNoVersionFields(),
(f, r) =>
{
r.FirstName.Should().Be(f.Command.FirstName);
Expand All @@ -73,7 +73,7 @@ public Task Map_WhenMapping_WithNoDate_VersionPropertiesNotSet()
public Task Map_WhenMappingWithDateAndStandardId_Then_UsesCalculatedTrainingProgramme()
{
return TestAsync(
f => f.MapWithStandard(),
f => f.MapWithStandard(),
(f, r) =>
{
r.FirstName.Should().Be(f.Command.FirstName);
Expand Down Expand Up @@ -121,7 +121,7 @@ public Task Map_WhenMappingWithFramework_Then_UsesGetTrainingProgramme()
public Task Map_WhenMappingWithNoCourse_Then_TrainingCourseVersionConfirmedIsFalse()
{
return TestAsync(
f => f.MapNoCourse(),
f => f.MapNoCourse(),
(f, r) =>
{
r.FirstName.Should().Be(f.Command.FirstName);
Expand All @@ -141,7 +141,7 @@ public Task Map_WhenMappingWithNoCourse_Then_TrainingCourseVersionConfirmedIsFal
});
}
}

public class UpdateDraftApprenticeshipToDraftApprenticeshipDetailsMapperTestsFixture
{
public Fixture Fixture { get; set; }
Expand Down Expand Up @@ -177,7 +177,7 @@ public Task<DraftApprenticeshipDetails> MapNoDateAndNoVersionFields()
Command.CourseCode = Fixture.Create<int>().ToString();
return Mapper.Map(Command);
}

public Task<DraftApprenticeshipDetails> MapWithDate()
{
Command.StartDate = DateTime.Now;
Expand All @@ -197,4 +197,4 @@ public Task<DraftApprenticeshipDetails> MapWithStandard()
return Mapper.Map(Command);
}
}
}
}
Loading