Skip to content

Commit

Permalink
Merge pull request #567 from SkillsFundingAgency/CV-251-add-reservati…
Browse files Browse the repository at this point in the history
…ons-to-bulk-upload

Cv 251 add reservations to bulk upload
  • Loading branch information
CThomp2018 authored Sep 19, 2019
2 parents 2c18b1a + d11188c commit f454420
Show file tree
Hide file tree
Showing 95 changed files with 1,507 additions and 678 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="SFA.DAS.Apprenticeships.Api.Client" Version="0.11.174" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19270-01" PrivateAssets="All" />
<PackageReference Include="SFA.DAS.Http" Version="3.2.3" />
<PackageReference Include="SFA.DAS.Http" Version="3.2.23" />
<PackageReference Include="StructureMap" Version="4.7.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ public Task CallPingEndpoint_ThenShouldReturnOkResponse()
{
return TestAsync(f => f.Client.GetAsync("/api/ping"), (f, r) => r.StatusCode.Should().Be(HttpStatusCode.OK));
}

[Test]
public Task CallHealthEndpoint_ThenShouldReturnOkResponse()
{
return TestAsync(f => f.Client.GetAsync("/health"), (f, r) => r.StatusCode.Should().Be(HttpStatusCode.OK));
}
}

public class HealthCheckFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="140.17224.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="SFA.DAS.Apprenticeships.Api.Client" Version="0.11.174" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public async Task Run()
{
long accountId = 1001;
long accountLegalEntityId = 2001;
long cohortId = 3001;

var key = "";
ConsoleKey key = ConsoleKey.Escape;

while (key != "x")
while (key != ConsoleKey.X)
{
Console.Clear();
Console.WriteLine("Test Options");
Expand All @@ -33,47 +34,55 @@ public async Task Run()
Console.WriteLine("C - AddedLegalEntityEvent");
Console.WriteLine("D - UpdatedLegalEntityEvent");
Console.WriteLine("E - RemovedLegalEntityEvent");
Console.WriteLine("F - DraftApprenticeshipCreatedEvent");
Console.WriteLine("g - BulkUploadIntoCohortCompletedEvent");
Console.WriteLine("X - Exit");
Console.WriteLine("Press [Key] for Test Option");
key = Console.ReadKey().Key.ToString().ToLower();
key = Console.ReadKey().Key;


try
{
switch (key)
{
case "a":
case ConsoleKey.A:
await _publisher.Publish(new CreatedAccountEvent { AccountId = accountId, Created = DateTime.Now, HashedId = "HPRIV", PublicHashedId = "PUBH", Name = "My Test", UserName = "Tester", UserRef = Guid.NewGuid() });
Console.WriteLine();
Console.WriteLine($"Published CreatedAccountEvent");
break;
case "b":
case ConsoleKey.B:
await _publisher.Publish(new ChangedAccountNameEvent { AccountId = accountId, Created = DateTime.Now, CurrentName = "My Test new", PreviousName = "My Test", HashedAccountId = "PUBH", UserName = "Tester", UserRef = Guid.NewGuid() });
Console.WriteLine();
Console.WriteLine($"Published ChangedAccountNameEvent");
break;
case "c":
case ConsoleKey.C:
await _publisher.Publish(new AddedLegalEntityEvent { AccountId = accountId, Created = DateTime.Now, AccountLegalEntityId = accountLegalEntityId,
OrganisationType = OrganisationType.Charities, OrganisationReferenceNumber = "MyLegalEntityId", OrganisationAddress = "My Address",
AccountLegalEntityPublicHashedId = "ABCD", AgreementId = 9898, LegalEntityId = 75263,
OrganisationName = "My Legal Entity", UserName = "Tester", UserRef = Guid.NewGuid() });
Console.WriteLine();
Console.WriteLine($"Published AddedLegalEntityEvent");
break;
case "d":
case ConsoleKey.D:
await _publisher.Publish(new UpdatedLegalEntityEvent { AccountLegalEntityId = accountLegalEntityId, Created = DateTime.Now, Name = "TEST", OrganisationName = "OName", UserName = "Tester", UserRef = Guid.NewGuid() });
Console.WriteLine();
Console.WriteLine($"Published UpdatedLegalEntityEvent");
break;
case "e":
case ConsoleKey.E:
await _publisher.Publish(new RemovedLegalEntityEvent { AccountLegalEntityId = accountLegalEntityId, Created = DateTime.Now, AccountId = accountId, OrganisationName = "OName", LegalEntityId = 75263, AgreementId = 9898, UserName = "Tester", UserRef = Guid.NewGuid() });
Console.WriteLine();
Console.WriteLine($"Published RemovedLegalEntityEvent");
break;
case "f":
case ConsoleKey.F:
await _publisher.Publish(new DraftApprenticeshipCreatedEvent(111111, 222222, "AAA111", Guid.NewGuid(), DateTime.UtcNow));
Console.WriteLine();
Console.WriteLine($"Published {nameof(DraftApprenticeshipCreatedEvent)}");
break;
case ConsoleKey.G:
await _publisher.Publish(new BulkUploadIntoCohortCompletedEvent { CohortId = cohortId, ProviderId = 10010, NumberOfApprentices = 0, UploadedOn = DateTime.Now});
Console.WriteLine();
Console.WriteLine($"Published {nameof(DraftApprenticeshipCreatedEvent)}");
break;
}
}
catch (Exception e)
Expand All @@ -82,7 +91,7 @@ await _publisher.Publish(new AddedLegalEntityEvent { AccountId = accountId, Crea
Console.WriteLine();
}

if (key == "x") break;
if (key == ConsoleKey.X) break;

Console.WriteLine();
Console.WriteLine("Press anykey to return to menu");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using MediatR;
using Moq;
using NServiceBus;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Application.Queries.GetDraftApprenticeshipCreatedEventsForCohort;
using SFA.DAS.CommitmentsV2.MessageHandlers.EventHandlers;
using SFA.DAS.CommitmentsV2.Messages.Events;
using SFA.DAS.Testing;

namespace SFA.DAS.CommitmentsV2.MessageHandlers.UnitTests.EventHandlers
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class
BulkUploadIntoCohortCompletedEventHandlerTests : FluentTest<
BulkUploadIntoCohortCompletedEventHandlerTestsFixture>
{
[Test]
public Task Handle_WhenBulkUploadIntoCohortCompletedEventIsRaised_ThenShouldSendGetDraftApprenticeshipCreatedEventsForCohortQuery()
{
return TestAsync(f => f.Handle(), f => f.VerifyQueryIsSent());
}
[Test]

public Task Handle_WhenBulkUploadIntoCohortCompletedEventIsRaised_ThenShouldSendTheDraftApprenticeshipCreatedEventsReturnedInResponse()
{
return TestAsync(f => f.Handle(), f => f.VerifyDraftApprenticeshipCreatedEventsArePublished());
}
}

public class BulkUploadIntoCohortCompletedEventHandlerTestsFixture
{
public Mock<IMediator> MockMediator { get; set; }
public Mock<IMessageHandlerContext> MockMessageHandlerContext;
public BulkUploadIntoCohortCompletedEventHandler BulkUploadIntoCohortCompletedEventHandler;
public BulkUploadIntoCohortCompletedEvent BulkUploadIntoCohortCompletedEvent;
public GetDraftApprenticeshipCreatedEventsForCohortQueryResult GetDraftApprenticeshipCreatedEventsForCohortQueryResult;

public BulkUploadIntoCohortCompletedEventHandlerTestsFixture()
{
var autoFixture = new Fixture();
MockMediator = new Mock<IMediator>();
MockMessageHandlerContext = new Mock<IMessageHandlerContext>();

BulkUploadIntoCohortCompletedEventHandler =
new BulkUploadIntoCohortCompletedEventHandler(MockMediator.Object);
BulkUploadIntoCohortCompletedEvent = autoFixture.Create<BulkUploadIntoCohortCompletedEvent>();
GetDraftApprenticeshipCreatedEventsForCohortQueryResult =
autoFixture.Build<GetDraftApprenticeshipCreatedEventsForCohortQueryResult>().Create();

MockMediator.Setup(x => x.Send(It.IsAny<GetDraftApprenticeshipCreatedEventsForCohortQuery>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(GetDraftApprenticeshipCreatedEventsForCohortQueryResult);
}

public Task Handle()
{
return BulkUploadIntoCohortCompletedEventHandler.Handle(BulkUploadIntoCohortCompletedEvent,
MockMessageHandlerContext.Object);
}

public void VerifyQueryIsSent()
{
var e = BulkUploadIntoCohortCompletedEvent;
MockMediator.Verify(m => m.Send(It.Is<GetDraftApprenticeshipCreatedEventsForCohortQuery>(q =>
q.ProviderId == e.ProviderId &&
q.CohortId == e.CohortId &&
q.NumberOfApprentices == e.NumberOfApprentices &&
q.UploadedOn == e.UploadedOn), CancellationToken.None));
}

public void VerifyDraftApprenticeshipCreatedEventsArePublished()
{
var numberOfEvents = GetDraftApprenticeshipCreatedEventsForCohortQueryResult.DraftApprenticeshipCreatedEvents.Count();
var mockPipelineContext = MockMessageHandlerContext.As<IPipelineContext>();
mockPipelineContext.Verify(x =>x.Publish(It.IsAny<DraftApprenticeshipCreatedEvent>(), It.IsAny<PublishOptions>()), Times.Exactly(numberOfEvents));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="AutoFixture.NUnit3" Version="4.8.0" />
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="NServiceBus.Testing" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Linq;
using System.Threading.Tasks;
using MediatR;
using NServiceBus;
using SFA.DAS.CommitmentsV2.Application.Queries.GetDraftApprenticeshipCreatedEventsForCohort;
using SFA.DAS.CommitmentsV2.Messages.Events;

namespace SFA.DAS.CommitmentsV2.MessageHandlers.EventHandlers
{
public class BulkUploadIntoCohortCompletedEventHandler : IHandleMessages<BulkUploadIntoCohortCompletedEvent>
{
private readonly IMediator _mediator;

public BulkUploadIntoCohortCompletedEventHandler(IMediator mediator)
{
_mediator = mediator;
}

public async Task Handle(BulkUploadIntoCohortCompletedEvent message, IMessageHandlerContext context)
{
var response = await _mediator.Send(new GetDraftApprenticeshipCreatedEventsForCohortQuery(message.ProviderId, message.CohortId,
message.NumberOfApprentices, message.UploadedOn));

await Task.WhenAll(response.DraftApprenticeshipCreatedEvents.Select(context.Publish)).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace SFA.DAS.CommitmentsV2.Messages.Events
{
public class BulkUploadIntoCohortCompletedEvent
{
public long ProviderId { get; set; }
public long CohortId { get; set; }
public uint NumberOfApprentices { get; set; }
public DateTime UploadedOn { get; set; }
}
}
Loading

0 comments on commit f454420

Please sign in to comment.