Skip to content

Commit

Permalink
Merge pull request #769 from SkillsFundingAgency/QUAL-587-RemoveRestr…
Browse files Browse the repository at this point in the history
…ictionApprenticeshipSearch

Qual 587 remove restriction apprenticeship search
  • Loading branch information
Satya Sanikommu authored Oct 15, 2020
2 parents 8c63f91 + ad122a7 commit 9b5f781
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@ namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Queries.GetApprenticeships
[TestFixture]
public class GetApprenticeshipsValidationTests
{
[TestCase(0, 1, true)]
[TestCase(1, 0, true)]
[TestCase(null, 1, true)]
[TestCase(1, null, true)]
[TestCase(1, 1, false)]
[TestCase(0, 0, false)]
[TestCase(null, null, false)]
[TestCase(null, 0, false)]
[TestCase(0, null, false)]
public void Validate_WithSpecifiedProviderAndEmployerId_ShouldSetIsValidCorrectly(long? providerId, long? employerId, bool expectedIsValid)
{
// arrange
var validator = new GetApprenticeshipsQueryValidator();
var validationResults = validator.Validate(new GetApprenticeshipsQuery
{
EmployerAccountId = employerId,
ProviderId = providerId,
PageNumber = 1,
PageItemCount = 1
});

// act
var actualIsValid = validationResults.IsValid;

// Assert
Assert.AreEqual(expectedIsValid, actualIsValid);
}

[TestCase("test",false)]
[TestCase(null,true)]
[TestCase("",true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,6 @@ public class GetApprenticeshipsQueryValidator : AbstractValidator<GetApprentices
{
public GetApprenticeshipsQueryValidator()
{
Unless(request => request.EmployerAccountId.HasValue && request.EmployerAccountId.Value > 0, () =>
{
RuleFor(request => request.ProviderId)
.Must(id => id.HasValue && id.Value > 0)
.WithMessage("The provider id must be set");
});

Unless(request => request.ProviderId.HasValue && request.ProviderId.Value > 0, () =>
{
RuleFor(request => request.EmployerAccountId)
.Must(id => id.HasValue && id.Value > 0)
.WithMessage("The employer account id must be set");
});

When(request => request.ProviderId.HasValue && request.EmployerAccountId.HasValue, () =>
{
Unless(request => request.EmployerAccountId.Value == 0, () =>
{
RuleFor(request => request.ProviderId)
.Must(id => id.Value == 0)
.WithMessage("The provider id must be zero if employer account id is set");
});

Unless(request => request.ProviderId.Value == 0, () =>
{
RuleFor(request => request.EmployerAccountId)
.Must(id => id.Value == 0)
.WithMessage("The employer account id must be zero if provider id is set");
});
});


RuleFor(request => request.SortField)
.Must(field => string.IsNullOrEmpty(field) ||
typeof(Apprenticeship).GetProperties().Select(c => c.Name).Contains(field) ||
Expand All @@ -51,3 +19,4 @@ public GetApprenticeshipsQueryValidator()
}
}
}

0 comments on commit 9b5f781

Please sign in to comment.