Skip to content

Commit

Permalink
Merge pull request #402 from SkillsFundingAgency/DPP-1586_DisplayOrga…
Browse files Browse the repository at this point in the history
…nisationsAndAgreements

DPP-1586 Display Organisations And Agreements
  • Loading branch information
satya-sanikommu authored Aug 20, 2018
2 parents 373a023 + fded0c0 commit bcfe152
Show file tree
Hide file tree
Showing 40 changed files with 607 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<Reference Include="Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.1.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="KellermanSoftware.Compare-NET-Objects, Version=4.3.0.0, Culture=neutral, PublicKeyToken=d970ace04cc85217, processorArchitecture=MSIL">
<HintPath>..\packages\CompareNETObjects.4.03.0.0\lib\net46\KellermanSoftware.Compare-NET-Objects.dll</HintPath>
<Reference Include="KellermanSoftware.Compare-NET-Objects, Version=4.55.0.0, Culture=neutral, PublicKeyToken=d970ace04cc85217, processorArchitecture=MSIL">
<HintPath>..\packages\CompareNETObjects.4.55.0.0\lib\net46\KellermanSoftware.Compare-NET-Objects.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.7.99.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.99\lib\net45\Moq.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.1.1" targetFramework="net461" />
<package id="CompareNETObjects" version="4.03.0.0" targetFramework="net461" />
<package id="CompareNETObjects" version="4.55.0.0" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net462" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.6" targetFramework="net462" />
<package id="Moq" version="4.7.99" targetFramework="net461" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ public async Task GetProviderCommitments()
Assert.Pass();
}

[Test]
public async Task GetCommitmentAgreements()
{
var providerRequest = new TestRequest(new Uri(ExpectedApiBaseUrl + $"api/provider/{ProviderId}/commitmentagreements"), string.Empty);
_fakeHandler.AddFakeResponse(providerRequest, new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(string.Empty) });

await _apiclient.GetCommitmentAgreements(ProviderId);

Assert.Pass();
}

[Test]
public async Task GetProviderCommitment()
{
Expand Down
14 changes: 7 additions & 7 deletions src/SFA.DAS.Commitments.Api.Client/HttpCommitmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using SFA.DAS.Commitments.Api.Types;
using SFA.DAS.Commitments.Api.Types.Apprenticeship;
using SFA.DAS.Commitments.Api.Types.Commitment;
using SFA.DAS.Commitments.Api.Types.Commitment.Types;
using SFA.DAS.Commitments.Api.Types.ProviderPayment;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down Expand Up @@ -34,12 +33,6 @@ public async Task PatchCommitment(string url, CommitmentSubmission submision)
await PatchAsync(url, data);
}

public async Task PutCommitment(string url, CommitmentStatus commitmentStatus)
{
var data = JsonConvert.SerializeObject(commitmentStatus);
await PutAsync(url, data);
}

public async Task PatchApprenticeship(string url, ApprenticeshipSubmission apprenticeshipSubmission)
{
var data = JsonConvert.SerializeObject(apprenticeshipSubmission);
Expand All @@ -53,6 +46,13 @@ public async Task<List<CommitmentListItem>> GetCommitments(string url)
return JsonConvert.DeserializeObject<List<CommitmentListItem>>(content);
}

public async Task<List<CommitmentAgreement>> GetCommitmentAgreements(string url)
{
var content = await GetAsync(url);

return JsonConvert.DeserializeObject<List<CommitmentAgreement>>(content);
}

public async Task<CommitmentView> GetCommitment(string url)
{
var content = await GetAsync(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using SFA.DAS.Commitments.Api.Types;
using SFA.DAS.Commitments.Api.Types.Apprenticeship;
using SFA.DAS.Commitments.Api.Types.Commitment;
using SFA.DAS.Commitments.Api.Types.Commitment.Types;
using SFA.DAS.Commitments.Api.Types.ProviderPayment;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -14,12 +13,12 @@ public interface IHttpCommitmentHelper

Task PatchCommitment(string url, CommitmentSubmission submision);

Task PutCommitment(string url, CommitmentStatus commitmentStatus);

Task PatchApprenticeship(string url, ApprenticeshipSubmission apprenticeshipSubmission);

Task<List<CommitmentListItem>> GetCommitments(string url);

Task<List<CommitmentAgreement>> GetCommitmentAgreements(string url);

Task<CommitmentView> GetCommitment(string url);

Task<List<Apprenticeship>> GetApprenticeships(string url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace SFA.DAS.Commitments.Api.Client.Interfaces
public interface IProviderCommitmentsApi
{
Task<List<CommitmentListItem>> GetProviderCommitments(long providerId);
Task<List<CommitmentAgreement>> GetCommitmentAgreements(long providerId);
Task<CommitmentView> GetProviderCommitment(long providerId, long commitmentId);
Task<List<Apprenticeship>> GetProviderApprenticeships(long providerId);
Task<ApprenticeshipSearchResponse> GetProviderApprenticeships(long providerId, ApprenticeshipSearchQuery apprenticeshipSearchQuery);
Expand Down
7 changes: 7 additions & 0 deletions src/SFA.DAS.Commitments.Api.Client/ProviderCommitmentsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public async Task<List<CommitmentListItem>> GetProviderCommitments(long provider
return await _commitmentHelper.GetCommitments(url);
}

public async Task<List<CommitmentAgreement>> GetCommitmentAgreements(long providerId)
{
var url = $"{_configuration.BaseUrl}api/provider/{providerId}/commitmentagreements";

return await _commitmentHelper.GetCommitmentAgreements(url);
}

public async Task<CommitmentView> GetProviderCommitment(long providerId, long commitmentId)
{
var url = $"{_configuration.BaseUrl}api/provider/{providerId}/commitments/{commitmentId}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

namespace SFA.DAS.Commitments.Api.Types.Commitment
{
/// <summary>
/// A subset of Commitment related to agreements
/// </summary>
public sealed class CommitmentAgreement
{
public string Reference { get; set; }
public string LegalEntityName { get; set; }
public string AccountLegalEntityPublicHashedId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SFA.DAS.Commitments.Api.Types.Commitment.Types
/// </summary>
public enum EditStatus
{
[Description("Indicates approval by both employer (receiving employer if transfer) and provider")] // note: badly named, not editable by either!
[Description("Indicates approval by both employer (receiving employer if transfer) and provider")]
Both = 0,
[Description("Editable by employer")]
EmployerOnly = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using SFA.DAS.Commitments.Api.Orchestrators.Mappers;
using SFA.DAS.Commitments.Api.Types.Commitment.Types;
using SFA.DAS.Commitments.Application.Commands.CreateApprenticeship;
using SFA.DAS.Commitments.Application.Services;
using SFA.DAS.Commitments.Domain;
using SFA.DAS.Commitments.Domain.Interfaces;
using Apprenticeship = SFA.DAS.Commitments.Api.Types.Apprenticeship;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Http.Results;
using Moq;
using NUnit.Framework;
using SFA.DAS.Commitments.Api.Controllers;
using SFA.DAS.Commitments.Api.Orchestrators;
using SFA.DAS.Commitments.Api.Types.Commitment;

namespace SFA.DAS.Commitments.Api.UnitTests.Controllers.ProviderControllerTests
{
[TestFixture]
public class WhenGettingCommitmentAgreements
{
private ProviderController _controller;
private Mock<IProviderOrchestrator> _mockProviderOrchestrator;

[SetUp]
public void Setup()
{
_mockProviderOrchestrator = new Mock<IProviderOrchestrator>();

_controller = new ProviderController(_mockProviderOrchestrator.Object, new Mock<IApprenticeshipsOrchestrator>().Object);
}

[Test]
public async Task ThenCommitmentAgreementsReturnedFromOrchestratorAreReturned()
{
// arrange
const long providerId = 123L;

var commitmentAgreements = new[] {new CommitmentAgreement {Reference = "ref", LegalEntityName = "len", AccountLegalEntityPublicHashedId = "aleHash"}};

_mockProviderOrchestrator.Setup(o => o.GetCommitmentAgreements(providerId)).ReturnsAsync(TestHelper.Clone(commitmentAgreements));

// act
var result = await _controller.GetCommitmentAgreements(providerId);

// assert
Assert.IsNotNull(result);

var contentResult = result as OkNegotiatedContentResult<IEnumerable<CommitmentAgreement>>;
Assert.IsNotNull(contentResult);

Assert.IsTrue(TestHelper.EnumerablesAreEqual(commitmentAgreements, contentResult.Content));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.Commitments.Api.Orchestrators.Mappers;
using SFA.DAS.Commitments.Application.Rules;

namespace SFA.DAS.Commitments.Api.UnitTests.Orchestrators.Mappers
{
[TestFixture]
public class WhenMappingACommitmentAgreement
{
private ICommitmentRules _rules;
private CommitmentMapper _mapper;

[SetUp]
public void Setup()
{
_rules = Mock.Of<ICommitmentRules>();
_mapper = new CommitmentMapper(_rules);
}

[Test]
public void ThenMappingCompletesSuccessfully()
{
const string reference = "COMREF", legalEntityName = "len", aleHash = "alehash";

var sourceDomainCommitmentAgreement = new Domain.Entities.CommitmentAgreement
{
Reference = reference,
LegalEntityName = legalEntityName,
AccountLegalEntityPublicHashedId = aleHash
};

var mappedTypesCommitmentAgreement = _mapper.Map(sourceDomainCommitmentAgreement);

Assert.AreEqual(reference, mappedTypesCommitmentAgreement.Reference);
Assert.AreEqual(legalEntityName, mappedTypesCommitmentAgreement.LegalEntityName);
Assert.AreEqual(aleHash, mappedTypesCommitmentAgreement.AccountLegalEntityPublicHashedId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,4 @@ public void SetUp()
.Returns<IList<Types.Apprenticeship.Apprenticeship>, ApprenticeshipSearchQuery, Originator>((aps, q, o) => new FilterResult(100, aps.ToList(), 1, 25));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class WhenGettingApprenticeshipUpdate : ProviderOrchestratorTestBase
public async Task ThereIsNoUpdate()
{
var result = await Orchestrator.GetPendingApprenticeshipUpdate(666, 999);
MockMediator.Setup(m => m.SendAsync(It.IsAny<GetPendingApprenticeshipUpdateRequest>()))
.ReturnsAsync((GetPendingApprenticeshipUpdateResponse)null);
result.Should().BeNull();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using SFA.DAS.Commitments.Api.Orchestrators;
using SFA.DAS.Commitments.Api.Orchestrators.Mappers;
using SFA.DAS.Commitments.Application.Queries.GetCommitmentAgreements;
using SFA.DAS.Commitments.Domain.Entities;
using SFA.DAS.Commitments.Domain.Interfaces;

namespace SFA.DAS.Commitments.Api.UnitTests.Orchestrators.Provider
{
[TestFixture]
public class WhenGettingCommitmentAgreements : ProviderOrchestratorTestBase
{
[Test]
public async Task ThenResultIsMappedCommitmentAgreementsReturnedFromGetCommitmentAgreementsQueryHandler()
{
const long providerId = 321L;

MockMediator.Setup(m => m.SendAsync(It.IsAny<GetCommitmentAgreementsRequest>()))
.ReturnsAsync(new GetCommitmentAgreementsResponse
{
Data = new List<CommitmentAgreement>
{
new CommitmentAgreement
{
Reference = "ref",
LegalEntityName = "len",
AccountLegalEntityPublicHashedId = "aleHash"
}
}
});

var mappedCommitmentAgreement = new Types.Commitment.CommitmentAgreement
{
Reference = "mapped ref",
LegalEntityName = "mapped len",
AccountLegalEntityPublicHashedId = "mapped aleHash"
};

var mockCommitmentMapper = new Mock<ICommitmentMapper>();

mockCommitmentMapper.Setup(m => m.Map(It.IsAny<Domain.Entities.CommitmentAgreement>()))
.Returns(TestHelper.Clone(mappedCommitmentAgreement));

Orchestrator = new ProviderOrchestrator(
MockMediator.Object,
Mock.Of<ICommitmentsLogger>(),
MockFacetMapper.Object,
MockApprenticeshipFilter.Object,
new ApprenticeshipMapper(),
mockCommitmentMapper.Object);

var result = await Orchestrator.GetCommitmentAgreements(providerId);

Assert.IsTrue(TestHelper.EnumerablesAreEqual(new[] { mappedCommitmentAgreement }, result));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<Reference Include="Hashids.net, Version=1.2.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hashids.net.1.2.2\lib\net45\Hashids.net.dll</HintPath>
</Reference>
<Reference Include="KellermanSoftware.Compare-NET-Objects, Version=4.55.0.0, Culture=neutral, PublicKeyToken=d970ace04cc85217, processorArchitecture=MSIL">
<HintPath>..\packages\CompareNETObjects.4.55.0.0\lib\net46\KellermanSoftware.Compare-NET-Objects.dll</HintPath>
</Reference>
<Reference Include="MediatR, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediatR.2.1.0\lib\net45\MediatR.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -109,6 +112,7 @@
<Compile Include="Controllers\EmployerControllerTests\WhenUpdatingAnApprenticeship.cs" />
<Compile Include="Controllers\EmployerControllerTests\WhenGettingProviderPaymentPriorites.cs" />
<Compile Include="Controllers\EmployerControllerTests\WhenUpdatingApprenticeshipStatus.cs" />
<Compile Include="Controllers\ProviderControllerTests\WhenGettingCommitmentAgreements.cs" />
<Compile Include="Controllers\ProviderControllerTests\WhenUpdatingAnApprenticeship.cs" />
<Compile Include="Controllers\ProviderControllerTests\WhenCreatingAnApprenticeship.cs" />
<Compile Include="Controllers\ProviderControllerTests\WhenGettingASingleApprenticeship.cs" />
Expand Down Expand Up @@ -141,6 +145,8 @@
<Compile Include="Orchestrators\Mappers\WhenMappingACommitment.cs" />
<Compile Include="Orchestrators\Mappers\WhenMappingACommitmentListItem.cs" />
<Compile Include="Orchestrators\Mappers\WhenMappingACommitmentView.cs" />
<Compile Include="Orchestrators\Mappers\WhenMappingACommitmentAgreement.cs" />
<Compile Include="Orchestrators\Provider\WhenGettingCommitmentAgreements.cs" />
<Compile Include="Orchestrators\Statistics\StatisticsOrchestratorTestBase.cs" />
<Compile Include="Orchestrators\Statistics\WhenGettingStatistics.cs" />
<Compile Include="StubCurrentDateTime.cs" />
Expand All @@ -160,6 +166,7 @@
<Compile Include="Orchestrators\Provider\WhenGettingApprenticeshipUpdate.cs" />
<Compile Include="Orchestrators\Provider\WhenPatchingApprenticeshipChange.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
Expand Down Expand Up @@ -187,7 +194,6 @@
<Name>SFA.DAS.Commitments.Domain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/SFA.DAS.Commitments.Api.UnitTests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using KellermanSoftware.CompareNetObjects;
using Newtonsoft.Json;

namespace SFA.DAS.Commitments.Api.UnitTests
{
public static class TestHelper
{
public static T Clone<T>(T source)
{
var serialized = JsonConvert.SerializeObject(source);
return JsonConvert.DeserializeObject<T>(serialized);
}

public static bool EnumerablesAreEqual<T>(IEnumerable<T> expected, IEnumerable<T> actual)
{
return new CompareLogic(new ComparisonConfig { IgnoreObjectTypes = true })
.Compare(expected, actual).AreEqual;
}
}
}
1 change: 1 addition & 0 deletions src/SFA.DAS.Commitments.Api.UnitTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="AutoFixture" version="4.3.0" targetFramework="net462" />
<package id="AutoFixture.NUnit3" version="4.3.0" targetFramework="net462" />
<package id="Castle.Core" version="4.1.1" targetFramework="net462" />
<package id="CompareNETObjects" version="4.55.0.0" targetFramework="net462" />
<package id="Fare" version="2.1.1" targetFramework="net462" />
<package id="FluentAssertions" version="4.19.2" targetFramework="net462" />
<package id="FluentValidation" version="6.2.1.0" targetFramework="net45" />
Expand Down
Loading

0 comments on commit bcfe152

Please sign in to comment.