-
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 #567 from SkillsFundingAgency/CV-251-add-reservati…
…ons-to-bulk-upload Cv 251 add reservations to bulk upload
- Loading branch information
Showing
95 changed files
with
1,507 additions
and
678 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
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
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
83 changes: 83 additions & 0 deletions
83
...MessageHandlers.UnitTests/EventHandlers/BulkUploadIntoCohortCompletedEventHandlerTests.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,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)); | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
....CommitmentsV2.MessageHandlers/EventHandlers/BulkUploadIntoCohortCompletedEventHandler.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,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); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...CommitmentsV2/SFA.DAS.CommitmentsV2.Messages/Events/BulkUploadIntoCohortCompletedEvent.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,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; } | ||
} | ||
} |
Oops, something went wrong.