-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from SkillsFundingAgency/CV-517-Get-Approved-…
…Cohorts Cv 517 get approved cohorts
- Loading branch information
Showing
13 changed files
with
379 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/GetApprovedProvidersResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
{ | ||
public class GetApprovedProvidersResponse | ||
{ | ||
public long[] ProviderIds { get; } | ||
|
||
public GetApprovedProvidersResponse(IEnumerable<long> providerIds) | ||
{ | ||
ProviderIds = providerIds.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
...itTests/Application/Queries/GetApprovedProviders/GetApprovedProvidersQueryHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprovedProviders; | ||
using SFA.DAS.CommitmentsV2.Data; | ||
using SFA.DAS.CommitmentsV2.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetApprovedProviders | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class GetApprovedProvidersQueryHandlerTests | ||
{ | ||
private GetApprovedProvidersQueryHandlerFixture _fixture; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fixture = new GetApprovedProvidersQueryHandlerFixture(); | ||
} | ||
|
||
[Test] | ||
public async Task Handle_WhenCohortApprovedByBoth_And_TransferSender_IdIsNull_ThenShouldReturnResult() | ||
{ | ||
var result = await _fixture.AddApprovedCohortAndProviderForAccount() | ||
.AddApprovedCohortAndProviderForAccount() | ||
.AddNotApprovedCohortAndProviderForAccount() | ||
.SeedDb().Handle(); | ||
|
||
Assert.AreEqual(2, result.ProviderIds.Count()); | ||
} | ||
|
||
[Test] | ||
public async Task Handle_WhenCohortApprovedByBoth_And_TransferSenderNotApproved_ThenShouldNotReturnResult() | ||
{ | ||
var result = await _fixture.AddCohortAndProvider_WithTransfserSenderNotApproved() | ||
.SeedDb().Handle(); | ||
|
||
Assert.AreEqual(0, result.ProviderIds.Count()); | ||
} | ||
|
||
[Test] | ||
public async Task Handle_WhenCohortApprovedByBoth_And_TransferSenderApproved_ThenShouldReturnResult() | ||
{ | ||
var result = await _fixture.AddCohortAndProvider_WithTransferSenderApproved() | ||
.SeedDb().Handle(); | ||
|
||
Assert.AreEqual(1, result.ProviderIds.Count()); | ||
} | ||
|
||
[Test] | ||
public async Task Handle_WhenCohortNotFullyApproved_ThenShouldNotReturnResult() | ||
{ | ||
var result = await _fixture.AddNotApprovedCohortAndProviderForAccount().SeedDb().Handle(); | ||
|
||
Assert.AreEqual(0, result.ProviderIds.Count()); | ||
} | ||
} | ||
|
||
public class GetApprovedProvidersQueryHandlerFixture | ||
{ | ||
public GetApprovedProvidersQuery Query { get; set; } | ||
public List<Cohort> Cohorts { get; set; } | ||
public List<Provider> Provider { get; set; } | ||
public ProviderCommitmentsDbContext Db { get; set; } | ||
public IRequestHandler<GetApprovedProvidersQuery, GetApprovedProvidersQueryResult> Handler { get; set; } | ||
|
||
public long AccountId => 1; | ||
|
||
public GetApprovedProvidersQueryHandlerFixture() | ||
{ | ||
Cohorts = new List<Cohort>(); | ||
Provider = new List<Provider>(); | ||
Query = new GetApprovedProvidersQuery(AccountId); | ||
Db = new ProviderCommitmentsDbContext(new DbContextOptionsBuilder<ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options); | ||
Handler = new GetApprovedProvidersQueryHandler(new Lazy<ProviderCommitmentsDbContext>(() => Db)); | ||
} | ||
|
||
public GetApprovedProvidersQueryHandlerFixture AddCohortAndProvider_WithTransfserSenderNotApproved() | ||
{ | ||
var provider = new Provider(GetNextProviderId(), "Foo", DateTime.UtcNow, DateTime.UtcNow); | ||
|
||
Provider.Add(provider); | ||
|
||
Cohorts.Add(new Cohort | ||
{ | ||
EmployerAccountId = AccountId, | ||
Id = GetNextCohortId(), | ||
EditStatus = 0, | ||
TransferSenderId = 1, | ||
ProviderId = provider.UkPrn, | ||
TransferApprovalStatus = Types.TransferApprovalStatus.Pending | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public GetApprovedProvidersQueryHandlerFixture AddCohortAndProvider_WithTransferSenderApproved() | ||
{ | ||
var provider = new Provider(GetNextProviderId(), "Foo", DateTime.UtcNow, DateTime.UtcNow); | ||
|
||
Provider.Add(provider); | ||
|
||
Cohorts.Add(new Cohort | ||
{ | ||
EmployerAccountId = AccountId, | ||
Id = GetNextCohortId(), | ||
EditStatus = 0, | ||
TransferSenderId = 1, | ||
ProviderId = provider.UkPrn, | ||
TransferApprovalStatus = Types.TransferApprovalStatus.Approved | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public GetApprovedProvidersQueryHandlerFixture AddApprovedCohortAndProviderForAccount() | ||
{ | ||
var provider = new Provider(GetNextProviderId(), "Foo", DateTime.UtcNow, DateTime.UtcNow); | ||
|
||
Provider.Add(provider); | ||
|
||
Cohorts.Add(new Cohort | ||
{ | ||
EmployerAccountId = AccountId, | ||
Id = GetNextCohortId(), | ||
EditStatus = 0, | ||
TransferSenderId = null, | ||
ProviderId = provider.UkPrn | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public GetApprovedProvidersQueryHandlerFixture AddNotApprovedCohortAndProviderForAccount() | ||
{ | ||
Provider.Add( | ||
new Provider(GetNextProviderId(), "Foo", DateTime.UtcNow, DateTime.UtcNow) | ||
); | ||
|
||
Cohorts.Add(new Cohort | ||
{ | ||
EmployerAccountId = AccountId, | ||
Id = GetNextCohortId(), | ||
EditStatus = Types.EditStatus.EmployerOnly, | ||
TransferSenderId = null, | ||
ProviderId = 1 | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
public Task<GetApprovedProvidersQueryResult> Handle() | ||
{ | ||
return Handler.Handle(Query, CancellationToken.None); | ||
} | ||
|
||
public GetApprovedProvidersQueryHandlerFixture SeedDb() | ||
{ | ||
Db.Cohorts.AddRange(Cohorts); | ||
Db.Providers.AddRange(Provider); | ||
Db.SaveChanges(); | ||
|
||
return this; | ||
} | ||
|
||
private long GetNextCohortId() => Cohorts.Count == 0 ? 1 : Cohorts.Max(x => x.Id) + 1; | ||
|
||
private long GetNextProviderId() => Provider.Count == 0 ? 1: Provider.Max(x => x.UkPrn) + 1; | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...Tests/Application/Queries/GetApprovedProviders/GetApprovedProvidersQueryValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using FluentValidation.Results; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprovedProviders; | ||
|
||
namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetProvider | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class GetApprovedProvidersQueryValidatorTests | ||
{ | ||
private GetApproveProvidersdQueryValidatorTestsFixture _fixture; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fixture = new GetApproveProvidersdQueryValidatorTestsFixture(); | ||
} | ||
|
||
[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 GetApproveProvidersdQueryValidatorTestsFixture | ||
{ | ||
public GetApprovedProvidersQueryValidator Validator { get; set; } | ||
|
||
public GetApproveProvidersdQueryValidatorTestsFixture() | ||
{ | ||
Validator = new GetApprovedProvidersQueryValidator(); | ||
} | ||
|
||
public ValidationResult Validate(long providerId) | ||
{ | ||
return Validator.Validate(new GetApprovedProvidersQuery(providerId)); | ||
} | ||
} | ||
} |
Oops, something went wrong.