Skip to content

Commit

Permalink
Merge pull request #416 from SkillsFundingAgency/DPP-1653-resolve-tas…
Browse files Browse the repository at this point in the history
…ks-after-r14

DPP-1653 resolve tasks after r14
  • Loading branch information
m-nagashree authored Oct 22, 2018
2 parents 9fc9b7a + db719fb commit 379ea53
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<Reference Include="Polly, Version=5.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Polly.5.7.0\lib\net45\Polly.dll</HintPath>
</Reference>
<Reference Include="SFA.DAS.Messaging, Version=3.0.0.53230, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SFA.DAS.Messaging.3.0.0.53230\lib\net45\SFA.DAS.Messaging.dll</HintPath>
</Reference>
<Reference Include="SFA.DAS.NLog.Logger, Version=1.0.0.43242, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SFA.DAS.NLog.Logger.1.0.0.43242\lib\net45\SFA.DAS.NLog.Logger.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -106,10 +109,9 @@
<Compile Include="DatalockStatusTestData.cs" />
<Compile Include="StubCurrentDateTime.cs" />
<Compile Include="WhenRunningApprenticeshipUpdateJob.cs" />
<Compile Include="WhenRunningUpdate.cs" />
<Compile Include="WhenCallingRunDataLock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WhenRunningJob.cs" />
<Compile Include="WhenTestingAcademicYearEndExpiryProcessor.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
Expand All @@ -128,6 +130,10 @@
<Project>{C4C803AF-747E-4747-A23B-DA43219009A4}</Project>
<Name>SFA.DAS.Commitments.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\SFA.DAS.Commitments.Events\SFA.DAS.Commitments.Events.csproj">
<Project>{7B636FB3-F4A9-479B-A371-0E82A67B4FD2}</Project>
<Name>SFA.DAS.Commitments.Events</Name>
</ProjectReference>
<ProjectReference Include="..\SFA.DAS.Commitments.Notification.WebJob\SFA.DAS.Commitments.Notification.WebJob.csproj">
<Project>{59b9f340-4489-4942-8ea2-0df38c4db3b9}</Project>
<Name>SFA.DAS.Commitments.Notification.WebJob</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using SFA.DAS.Commitments.AcademicYearEndProcessor.WebJob.Updater;
using SFA.DAS.Commitments.Domain.Data;
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Messaging.Interfaces;
using SFA.DAS.NLog.Logger;

namespace SFA.DAS.Commitments.AcademicYearEndProcessor.UnitTests
{
[TestFixture]
public class WhenRunningUpdate
public class WhenCallingRunDataLock
{
private Mock<ILog> _logger;
private Mock<IAcademicYearDateProvider> _academicYearProvider;
Expand Down Expand Up @@ -60,7 +61,9 @@ DateTime atTheTime
_academicYearProvider.Object,
_dataLockRepository.Object,
_apprenticeshipUpdateRepository.Object,
currentDatetime);
currentDatetime,
Mock.Of<IMessagePublisher>(),
Mock.Of<IApprenticeshipRepository>());

_dataLockRepository.Setup(r => r.GetExpirableDataLocks(_academicYearProvider.Object.CurrentAcademicYearStartDate)).ReturnsAsync(testDatalockStatusItems);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoFixture;
using AutoFixture.NUnit3;
using Moq;

using NUnit.Framework;
Expand All @@ -10,6 +12,8 @@
using SFA.DAS.Commitments.Domain.Data;
using SFA.DAS.Commitments.Domain.Entities;
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Commitments.Events;
using SFA.DAS.Messaging.Interfaces;
using SFA.DAS.NLog.Logger;

namespace SFA.DAS.Commitments.AcademicYearEndProcessor.UnitTests
Expand All @@ -22,6 +26,9 @@ public class WhenRunningApprenticeshipUpdateJob
private Mock<IDataLockRepository> _dataLockRepository;
private Mock<IApprenticeshipUpdateRepository> _apprenticeshipUpdateRepository;
private Mock<ICurrentDateTime> _currentDateTime;
private Mock<IMessagePublisher> _mockMessageBuilder;
private Mock<IApprenticeshipRepository> _mockApprenticeshipRepository;


private AcademicYearEndExpiryProcessor _sut;

Expand All @@ -34,13 +41,17 @@ public void Arrange()
_dataLockRepository = new Mock<IDataLockRepository>();
_apprenticeshipUpdateRepository = new Mock<IApprenticeshipUpdateRepository>();
_currentDateTime = new Mock<ICurrentDateTime>();
_mockMessageBuilder = new Mock<IMessagePublisher>();
_mockApprenticeshipRepository = new Mock<IApprenticeshipRepository>();

_sut = new AcademicYearEndExpiryProcessor(
_logger.Object,
_academicYearProvider.Object,
_dataLockRepository.Object,
_apprenticeshipUpdateRepository.Object,
_currentDateTime.Object);
_currentDateTime.Object,
_mockMessageBuilder.Object,
_mockApprenticeshipRepository.Object);

}

Expand All @@ -60,15 +71,23 @@ public async Task WhenNoUpdatesFound()
[Test]
public async Task WhenApprenticeshpUpdatesFound()
{
var records = 4;
var recordCount = 4;
var apprenticeshipUpdates = new List<ApprenticeshipUpdate>();
var apprenticeships = new List<Apprenticeship>();
var fixture = new Fixture();
fixture.AddManyTo(apprenticeshipUpdates, records);
fixture.AddManyTo(apprenticeshipUpdates, recordCount);
apprenticeshipUpdates.ForEach(update =>
apprenticeships.Add(
fixture.Build<Apprenticeship>()
.With(a => a.Id, update.ApprenticeshipId)
.Create()));

_apprenticeshipUpdateRepository.Setup(m => m.GetExpiredApprenticeshipUpdates(_currentDateTime.Object.Now))
_apprenticeshipUpdateRepository
.Setup(m => m.GetExpiredApprenticeshipUpdates(_currentDateTime.Object.Now))
.ReturnsAsync(apprenticeshipUpdates);

_apprenticeshipUpdateRepository.Setup(m => m.ExpireApprenticeshipUpdate(It.IsAny<long>()))
_apprenticeshipUpdateRepository
.Setup(m => m.ExpireApprenticeshipUpdate(It.IsAny<long>()))
.Callback(
() =>
{
Expand All @@ -79,18 +98,36 @@ public async Task WhenApprenticeshpUpdatesFound()
})
.Returns(Task.FromResult(0));

_mockApprenticeshipRepository
.Setup(repository =>
repository.GetApprenticeship(
It.IsIn(apprenticeshipUpdates.Select(update => update.ApprenticeshipId))))
.ReturnsAsync((long apprenticeshipId) =>
apprenticeships.Single(apprenticeship => apprenticeship.Id == apprenticeshipId));

await _sut.RunApprenticeshipUpdateJob("jobId");

_apprenticeshipUpdateRepository
.Verify(m => m.GetExpiredApprenticeshipUpdates(It.IsAny<DateTime>()), Times.Exactly(2),
"Should call one time to get all updates and one to verify that all have been updated");
_apprenticeshipUpdateRepository.Verify(m => m.ExpireApprenticeshipUpdate(It.IsAny<long>()),
Times.Exactly(records),
Times.Exactly(recordCount),
"Should be called once for each update record");
apprenticeshipUpdates.ForEach(update =>
{
var apprenticeship = apprenticeships.Single(a => a.Id == update.ApprenticeshipId);
_mockMessageBuilder.Verify(m =>
m.PublishAsync(It.Is<ApprenticeshipUpdateCancelled>(cancelled =>
cancelled.ApprenticeshipId == apprenticeship.Id &&
cancelled.AccountId == apprenticeship.EmployerAccountId &&
cancelled.ProviderId == apprenticeship.ProviderId)),
"Should be called once for each update record, with correct params");
});
}

[Test]
public async Task ShouldOnlyUpdateRecordsWithCostOrTrainingChanges()
[Test, AutoData]
public async Task ShouldOnlyUpdateRecordsWithCostOrTrainingChanges(
Apprenticeship apprenticeship)
{
var apprenticeshipUpdates = new List<ApprenticeshipUpdate>
{
Expand All @@ -117,6 +154,10 @@ public async Task ShouldOnlyUpdateRecordsWithCostOrTrainingChanges()
})
.Returns(Task.FromResult(0));

_mockApprenticeshipRepository
.Setup(repository => repository.GetApprenticeship(It.IsAny<long>()))
.ReturnsAsync(apprenticeship);

await _sut.RunApprenticeshipUpdateJob("jobId");

_apprenticeshipUpdateRepository
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<package id="NUnit3TestAdapter" version="3.10.0" targetFramework="net462" />
<package id="Polly" version="5.7.0" targetFramework="net462" />
<package id="SFA.DAS.Learners" version="1.0.0.39408" targetFramework="net452" />
<package id="SFA.DAS.Messaging" version="3.0.0.53230" targetFramework="net462" />
<package id="SFA.DAS.NLog.Logger" version="1.0.0.43242" targetFramework="net461" />
<package id="SFA.DAS.Provider.Events.Api.Client" version="2.0.0.57315" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net462" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand All @@ -93,4 +93,30 @@
<add key="ConfigurationStorageConnectionString" value="UseDevelopmentStorage=true;" />
<add key="EnvironmentName" value="LOCAL" />
</appSettings>
<system.serviceModel>
<extensions>
<!-- In this extension section we are introducing all known service bus extensions. User can remove the ones they don't need. -->
<behaviorExtensions>
<add name="connectionStatusBehavior" type="Microsoft.ServiceBus.Configuration.ConnectionStatusElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="serviceRegistrySettings" type="Microsoft.ServiceBus.Configuration.ServiceRegistrySettingsElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</behaviorExtensions>
<bindingElementExtensions>
<add name="netMessagingTransport" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="tcpRelayTransport" type="Microsoft.ServiceBus.Configuration.TcpRelayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="httpRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpRelayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="httpsRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpsRelayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="onewayRelayTransport" type="Microsoft.ServiceBus.Configuration.RelayedOnewayTransportElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingElementExtensions>
<bindingExtensions>
<add name="basicHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="webHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WebHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ws2007HttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WS2007HttpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netOnewayRelayBinding" type="Microsoft.ServiceBus.Configuration.NetOnewayRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netEventRelayBinding" type="Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>
</extensions>
</system.serviceModel>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using SFA.DAS.Commitments.Domain.Interfaces;
using SFA.DAS.Messaging.AzureServiceBus.StructureMap;

namespace SFA.DAS.Commitments.AcademicYearEndProcessor.WebJob.Configuration
{
public class CommitmentsAcademicYearEndProcessorConfiguration : IConfiguration
public class CommitmentsAcademicYearEndProcessorConfiguration : IConfiguration, ITopicMessagePublisherConfiguration
{
public string DatabaseConnectionString { get; set; }
public string ServiceBusConnectionString { get; set; }
public string CurrentStartTime { get; set; }
public string MessageServiceBusConnectionString { get; set; }
}
}
Loading

0 comments on commit 379ea53

Please sign in to comment.