Skip to content

Commit

Permalink
Merge pull request #157 from SkillsFundingAgency/FAT2-294_fat_decomis…
Browse files Browse the repository at this point in the history
…sioning

FAT2-294 - remove fatv1 dependencies
  • Loading branch information
SijiOdun authored Feb 3, 2021
2 parents 0647a1c + 468c91c commit 9fa2d47
Show file tree
Hide file tree
Showing 28 changed files with 243 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using SFA.DAS.Apprenticeships.Api.Client;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
Expand Down Expand Up @@ -76,7 +75,6 @@ public class CreateCohortWithDraftApprenticeshipControllerTestFixtures
public CreateCohortWithDraftApprenticeshipControllerTestFixtures()
{
LinkGeneratorMock = new Mock<ILinkGenerator>();
TrainingProgrammeApiClientMock = new Mock<ITrainingProgrammeApiClient>();
CommitmentsApiClientMock = new Mock<ICommitmentsApiClient>();
ModelMapperMock = new Mock<IModelMapper>();
ModelMapperMock.Setup(x => x.Map<ApprenticeViewModel>(It.IsAny<ApprenticeRequest>()))
Expand All @@ -93,8 +91,6 @@ public CreateCohortWithDraftApprenticeshipControllerTestFixtures()
public Mock<IAuthorizationService> AuthorizationServiceMock { get; set; }
public IAuthorizationService AuthorizationService => AuthorizationServiceMock.Object;

public Mock<ITrainingProgrammeApiClient> TrainingProgrammeApiClientMock { get; }

public ApprenticeRequest GetRequest { get; private set; }
public ApprenticeViewModel PostRequest { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.Apprenticeships.Api.Client;
using SFA.DAS.Apprenticeships.Api.Types;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Api.Types.Validation;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
Expand Down Expand Up @@ -72,12 +71,11 @@ public class AddDraftApprenticeshipTestsFixture
public AddDraftApprenticeshipRequest Request { get; set; }
public AddDraftApprenticeshipViewModel ViewModel { get; set; }
public CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest AddDraftApprenticeshipRequest { get; set; }
public IReadOnlyList<ITrainingProgramme> StandardCourses { get; set; }
public IReadOnlyList<ITrainingProgramme> Courses { get; set; }
public IEnumerable<TrainingProgramme> StandardCourses { get; set; }
public IEnumerable<TrainingProgramme> Courses { get; set; }
public string CohortDetailsUrl { get; set; }
public CommitmentsApiModelException CommitmentsApiModelException { get; set; }
public Mock<ICommitmentsApiClient> CommitmentsApiClient { get; set; }
public Mock<ITrainingProgrammeApiClient> TrainingProgrammeApiClient { get; set; }
public Mock<IModelMapper> ModelMapper { get; set; }
public Mock<IAuthorizationService> AuthorizationService { get; set; }
public DraftApprenticeshipController Controller { get; set; }
Expand Down Expand Up @@ -117,12 +115,11 @@ public AddDraftApprenticeshipTestsFixture()
};

AddDraftApprenticeshipRequest = new CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest();
StandardCourses = new List<ITrainingProgramme>();
Courses = new List<ITrainingProgramme>();
StandardCourses = new List<TrainingProgramme>();
Courses = new List<TrainingProgramme>();
CohortDetailsUrl = $"accounts/{Request.AccountHashedId}/apprentices/{Request.CohortReference}/details";
CommitmentsApiModelException = new CommitmentsApiModelException(new List<ErrorDetail> { new ErrorDetail("Foo", "Bar") });
CommitmentsApiClient = new Mock<ICommitmentsApiClient>();
TrainingProgrammeApiClient = new Mock<ITrainingProgrammeApiClient>();
ModelMapper = new Mock<IModelMapper>();
LinkGenerator = new Mock<ILinkGenerator>();
AuthorizationService = new Mock<IAuthorizationService>();
Expand All @@ -134,8 +131,8 @@ public AddDraftApprenticeshipTestsFixture()
AuthorizationService.Object
);

TrainingProgrammeApiClient.Setup(c => c.GetAllTrainingProgrammes()).ReturnsAsync(Courses);
TrainingProgrammeApiClient.Setup(c => c.GetStandardTrainingProgrammes()).ReturnsAsync(StandardCourses);
CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammes(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammesResponse{TrainingProgrammes = Courses});
CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammeStandards(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse{TrainingProgrammes = StandardCourses});
ModelMapper.Setup(m => m.Map<CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(ViewModel)).Returns(Task.FromResult(AddDraftApprenticeshipRequest));

ModelMapper.Setup(m => m.Map<AddDraftApprenticeshipViewModel>(It.IsAny<AddDraftApprenticeshipRequest>())).ReturnsAsync(ViewModel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using AutoFixture;
using Moq;
using NUnit.Framework;
using SFA.DAS.Apprenticeships.Api.Client;
using SFA.DAS.Apprenticeships.Api.Types;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
Expand All @@ -11,22 +9,22 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.CommitmentsV2.Types;
using static SFA.DAS.CommitmentsV2.Api.Types.Responses.GetPriceEpisodesResponse;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice
{
public class ConfirmDetailsAndSendViewModelMapperTests
{
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient;
private Mock<ITrainingProgrammeApiClient> _mockTrainingProgrammeApiClient;

private ChangeOfProviderRequest _request;

private GetApprenticeshipResponse _apprenticeshipResponse;
private GetPriceEpisodesResponse _priceEpisodeResponse;
private StandardSummary _standardSummary;


private ConfirmDetailsAndSendViewModelMapper _mapper;
private TrainingProgramme _standardSummary;

[SetUp]
public void Arrange()
Expand All @@ -50,30 +48,32 @@ public void Arrange()
new PriceEpisode { Cost = 2000, ToDate = null } })
.Create();

_standardSummary = autoFixture.Create<StandardSummary>();
_standardSummary = autoFixture.Create<TrainingProgramme>();
_standardSummary.EffectiveFrom = new DateTime(2018, 1, 1);
_standardSummary.EffectiveTo = new DateTime(2022, 1, 1);
_standardSummary.FundingPeriods = SetPriceBand(1000);

_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockTrainingProgrammeApiClient = new Mock<ITrainingProgrammeApiClient>();

_mockCommitmentsApiClient.Setup(c => c.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_apprenticeshipResponse);
_mockCommitmentsApiClient.Setup(c => c.GetPriceEpisodes(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_priceEpisodeResponse);
_mockTrainingProgrammeApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode))
.ReturnsAsync(_standardSummary);
_mockCommitmentsApiClient.Setup(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode, It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetTrainingProgrammeResponse
{
TrainingProgramme = _standardSummary
});

_mapper = new ConfirmDetailsAndSendViewModelMapper(_mockCommitmentsApiClient.Object, _mockTrainingProgrammeApiClient.Object);
_mapper = new ConfirmDetailsAndSendViewModelMapper(_mockCommitmentsApiClient.Object);
}

[Test]
public async Task GetFundingCapIsCalled()
{
var result = await _mapper.Map(_request);

_mockTrainingProgrammeApiClient.Verify(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode), Times.Once());
_mockCommitmentsApiClient.Verify(t => t.GetTrainingProgramme(_apprenticeshipResponse.CourseCode, It.IsAny<CancellationToken>()), Times.Once());
}

[Test]
Expand Down Expand Up @@ -119,11 +119,11 @@ public async Task ExceedsMaxFunding_IsMapped(int newPrice, bool expectsExceedsMa
Assert.AreEqual(expectsExceedsMaxFunding, result.ExceedsMaxFunding);
}

public List<FundingPeriod> SetPriceBand(int fundingCap)
public List<TrainingProgrammeFundingPeriod> SetPriceBand(int fundingCap)
{
return new List<FundingPeriod>
return new List<TrainingProgrammeFundingPeriod>
{
new FundingPeriod
new TrainingProgrammeFundingPeriod
{
EffectiveFrom = new DateTime(2019, 1, 1),
EffectiveTo = DateTime.Now.AddMonths(1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.Apprenticeships.Api.Types;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Shared;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Cohort
{
Expand All @@ -24,13 +24,18 @@ public class ApprenticeViewModelMapperTests
private AccountLegalEntityResponse _accountLegalEntityResponse;
private ApprenticeRequest _source;
private ApprenticeViewModel _result;
private TrainingProgrammeApiClientMock _trainingProgrammeApiClient;
private TrainingProgramme _courseStandard;
private TrainingProgramme _course;
private List<TrainingProgramme> _allTrainingProgrammes;
private List<TrainingProgramme> _standardTrainingProgrammes;

[SetUp]
public async Task Arrange()
{
var autoFixture = new Fixture();

_course = autoFixture.Create<TrainingProgramme>();
_courseStandard = autoFixture.Create<TrainingProgramme>();
_providerResponse = autoFixture.Create<GetProviderResponse>();
_accountLegalEntityResponse = autoFixture.Build<AccountLegalEntityResponse>().With(x=>x.LevyStatus, ApprenticeshipEmployerType.Levy).Create();
_source = autoFixture.Create<ApprenticeRequest>();
Expand All @@ -43,12 +48,24 @@ public async Task Arrange()
.ReturnsAsync(_providerResponse);
_commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny<CancellationToken>()))
.ReturnsAsync(_accountLegalEntityResponse);
_standardTrainingProgrammes = new List<TrainingProgramme>{_courseStandard};
_commitmentsApiClient
.Setup(x => x.GetAllTrainingProgrammeStandards(It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse
{
TrainingProgrammes = _standardTrainingProgrammes
});
_allTrainingProgrammes = new List<TrainingProgramme>{_courseStandard, _course};
_commitmentsApiClient
.Setup(x => x.GetAllTrainingProgrammes(It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetAllTrainingProgrammesResponse
{
TrainingProgrammes = _allTrainingProgrammes
});

_trainingProgrammeApiClient = new TrainingProgrammeApiClientMock();

_mapper = new ApprenticeViewModelMapper(
_commitmentsApiClient.Object,
_trainingProgrammeApiClient.Object);
_commitmentsApiClient.Object);

_result = await _mapper.Map(TestHelper.Clone(_source));
}
Expand Down Expand Up @@ -104,7 +121,7 @@ public void ProviderNameIsMappedCorrectly()
[Test]
public void CoursesAreMappedCorrectly()
{
Assert.AreEqual(_trainingProgrammeApiClient.All, _result.Courses);
Assert.AreEqual(_allTrainingProgrammes, _result.Courses);
}

[Test]
Expand All @@ -130,7 +147,7 @@ public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLev
{
_source.TransferSenderId = "test";
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
_result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes);
}

[TestCase("12345")]
Expand All @@ -140,7 +157,7 @@ public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStat
_source.TransferSenderId = transferSenderId;
_accountLegalEntityResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy;
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
_result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.Apprenticeships.Api.Types;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
using SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Shared;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Cohort
{
Expand All @@ -25,13 +25,16 @@ public class CreateCohortWithDraftApprenticeshipRequestToAddDraftApprenticeshipV
private AccountLegalEntityResponse _accountLegalEntityResponse;
private ApprenticeRequest _source;
private AddDraftApprenticeshipViewModel _result;
private TrainingProgrammeApiClientMock _trainingProgrammeApiClient;
private List<TrainingProgramme> _standardTrainingProgrammes;
private List<TrainingProgramme> _allTrainingProgrammes;

[SetUp]
public async Task Arrange()
{
var autoFixture = new Fixture();

_standardTrainingProgrammes = autoFixture.CreateMany<TrainingProgramme>().ToList();
_allTrainingProgrammes = autoFixture.CreateMany<TrainingProgramme>().ToList();
_providerResponse = autoFixture.Create<GetProviderResponse>();
_accountLegalEntityResponse = autoFixture.Build<AccountLegalEntityResponse>().With(x => x.LevyStatus, ApprenticeshipEmployerType.Levy).Create();

Expand All @@ -45,12 +48,20 @@ public async Task Arrange()
.ReturnsAsync(_providerResponse);
_commitmentsApiClient.Setup(x => x.GetAccountLegalEntity(_source.AccountLegalEntityId, It.IsAny<CancellationToken>()))
.ReturnsAsync(_accountLegalEntityResponse);

_trainingProgrammeApiClient = new TrainingProgrammeApiClientMock(); ;

_mapper = new AddDraftApprenticeshipViewModelMapper(
_commitmentsApiClient.Object,
_trainingProgrammeApiClient.Object);
_commitmentsApiClient
.Setup(x => x.GetAllTrainingProgrammeStandards(It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse()
{
TrainingProgrammes = _standardTrainingProgrammes
});
_commitmentsApiClient
.Setup(x => x.GetAllTrainingProgrammes(It.IsAny<CancellationToken>()))
.ReturnsAsync(new GetAllTrainingProgrammesResponse
{
TrainingProgrammes = _allTrainingProgrammes
});

_mapper = new AddDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object);

_result = await _mapper.Map(TestHelper.Clone(_source));
}
Expand Down Expand Up @@ -100,15 +111,15 @@ public void ProviderNameIsMappedCorrectly()
[Test]
public void CoursesAreMappedCorrectly()
{
Assert.AreEqual(_trainingProgrammeApiClient.All, _result.Courses);
Assert.AreEqual(_allTrainingProgrammes, _result.Courses);
}

[Test]
public async Task TransferFundedCohortsAllowStandardCoursesOnlyWhenEmployerIsLevy()
{
_source.TransferSenderId = "test";
_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
_result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes);
}

[TestCase("12345")]
Expand All @@ -117,8 +128,10 @@ public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStat
{
_source.TransferSenderId = transferSenderId;
_accountLegalEntityResponse.LevyStatus = ApprenticeshipEmployerType.NonLevy;


_result = await _mapper.Map(TestHelper.Clone(_source));
Assert.IsFalse(_result.Courses.Any(x => x is Framework));
_result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes);
}

}
Expand Down
Loading

0 comments on commit 9fa2d47

Please sign in to comment.