-
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 #709 from SkillsFundingAgency/CV-684-LevyNoneLevy-…
…flag Cv 684 levy none levy flag
- Loading branch information
Showing
31 changed files
with
321 additions
and
532 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/AccountLegalEntityResponse.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
using SFA.DAS.CommitmentsV2.Types; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
{ | ||
public class AccountLegalEntityResponse | ||
{ | ||
public long AccountId { get; set; } | ||
public long MaLegalEntityId { get; set; } | ||
public string AccountName { get; set; } | ||
public string LegalEntityName { get; set; } | ||
public ApprenticeshipEmployerType LevyStatus { get; set; } | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api.Types/Responses/AccountResponse.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
using SFA.DAS.CommitmentsV2.Types; | ||
|
||
namespace SFA.DAS.CommitmentsV2.Api.Types.Responses | ||
{ | ||
public class AccountResponse | ||
{ | ||
public long AccountId { get; set; } | ||
public bool HasCohorts { get; set; } | ||
public bool HasApprenticeships { get; set; } | ||
public ApprenticeshipEmployerType LevyStatus { get; set; } | ||
} | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
...mitmentsV2.MessageHandlers.UnitTests/EventHandlers/LevyAddedToAccountEventHandlerTests.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,55 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NServiceBus; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Application.Commands.UpdateLevyStatusToLevy; | ||
using SFA.DAS.CommitmentsV2.MessageHandlers.EventHandlers; | ||
using SFA.DAS.EmployerFinance.Messages.Events; | ||
|
||
namespace SFA.DAS.CommitmentsV2.MessageHandlers.UnitTests.EventHandlers | ||
{ | ||
[TestFixture] | ||
[Parallelizable(ParallelScope.All)] | ||
public class LevyAddedToAccountEventHandlerTests | ||
{ | ||
[Test] | ||
public async Task Handle_WhenLevyAddedToAccountIsRaised_LevyStatusIsSetToLevy() | ||
{ | ||
var f = new LevyAddedToAccountEventHandlerTestsFixture(); | ||
await f.Handle(); | ||
f.VerifyUpdateLevyStatusToLevyCommandSent(); | ||
} | ||
} | ||
|
||
public class LevyAddedToAccountEventHandlerTestsFixture | ||
{ | ||
public Mock<IMediator> Mediator { get; set; } | ||
public LevyAddedToAccountEventHandler Sut; | ||
public LevyAddedToAccount LevyAddedToAccount; | ||
|
||
public LevyAddedToAccountEventHandlerTestsFixture() | ||
{ | ||
var autoFixture = new Fixture(); | ||
Mediator = new Mock<IMediator>(); | ||
LevyAddedToAccount = autoFixture.Create<LevyAddedToAccount>(); | ||
|
||
Sut = new LevyAddedToAccountEventHandler(Mediator.Object, Mock.Of<ILogger<LevyAddedToAccountEventHandler>>()); | ||
} | ||
|
||
public Task Handle() | ||
{ | ||
return Sut.Handle(LevyAddedToAccount, Mock.Of<IMessageHandlerContext>()); | ||
} | ||
|
||
public void VerifyUpdateLevyStatusToLevyCommandSent() | ||
{ | ||
Mediator.Verify(x => | ||
x.Send(It.Is<UpdateLevyStatusToLevyCommand>(p => p.AccountId == LevyAddedToAccount.AccountId), | ||
It.IsAny<CancellationToken>())); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...sV2/SFA.DAS.CommitmentsV2.MessageHandlers/EventHandlers/LevyAddedToAccountEventHandler.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 MediatR; | ||
using Microsoft.Extensions.Logging; | ||
using NServiceBus; | ||
using SFA.DAS.CommitmentsV2.Application.Commands.UpdateLevyStatusToLevy; | ||
using SFA.DAS.EmployerFinance.Messages.Events; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.CommitmentsV2.MessageHandlers.EventHandlers | ||
{ | ||
public class LevyAddedToAccountEventHandler : IHandleMessages<LevyAddedToAccount> | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ILogger<LevyAddedToAccountEventHandler> _logger; | ||
|
||
public LevyAddedToAccountEventHandler(IMediator mediator, ILogger<LevyAddedToAccountEventHandler> logger) | ||
{ | ||
_mediator = mediator; | ||
_logger = logger; | ||
} | ||
|
||
public async Task Handle(LevyAddedToAccount message, IMessageHandlerContext context) | ||
{ | ||
_logger.LogInformation($"LevyAddedToAccount event received for Account {message.AccountId}"); | ||
await _mediator.Send(new UpdateLevyStatusToLevyCommand { AccountId = message.AccountId }); | ||
} | ||
} | ||
} |
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
...CommitmentsV2.UnitTests/Application/Commands/UpdateLevyStatusToLevyCommandHandlerTests.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; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.CommitmentsV2.Application.Commands.UpdateLevyStatusToLevy; | ||
using SFA.DAS.CommitmentsV2.Data; | ||
using SFA.DAS.CommitmentsV2.Models; | ||
using SFA.DAS.CommitmentsV2.Types; | ||
|
||
namespace SFA.DAS.CommitmentsV2.UnitTests.Application.Commands | ||
{ | ||
[TestFixture] | ||
[Parallelizable(ParallelScope.None)] | ||
public class UpdateLevyStatusToLevyCommandHandlerTests | ||
{ | ||
[Test] | ||
public void Handle_WhenHandlingCommand_ThenShouldUpdateTheLevyStatus() | ||
{ | ||
var f = new UpdateLevyStatusToLevyCommandHandlerTestsFixture(); | ||
f.SetAccount() | ||
.Handle(); | ||
|
||
Assert.IsTrue(f.IsValid(ApprenticeshipEmployerType.Levy)); | ||
} | ||
|
||
[Test] | ||
public void Handle_WhenHandlingCommand_AndAccountNotFound_ThenShouldnotUpdateTheLevyStatus() | ||
{ | ||
var f = new UpdateLevyStatusToLevyCommandHandlerTestsFixture(); | ||
f.SetAccount(); | ||
f.Command.AccountId = 2; | ||
f.Handle(); | ||
|
||
Assert.IsTrue(f.IsValid(ApprenticeshipEmployerType.NonLevy)); | ||
} | ||
} | ||
|
||
public class UpdateLevyStatusToLevyCommandHandlerTestsFixture | ||
{ | ||
public IFixture AutoFixture { get; set; } | ||
public UpdateLevyStatusToLevyCommand Command { get; set; } | ||
public Mock<ProviderCommitmentsDbContext> Db { get; set; } | ||
public IRequestHandler<UpdateLevyStatusToLevyCommand> Handler { get; set; } | ||
public long AccountId { get; set; } | ||
|
||
public UpdateLevyStatusToLevyCommandHandlerTestsFixture() | ||
{ | ||
AutoFixture = new Fixture(); | ||
AccountId = 1; | ||
Command = new UpdateLevyStatusToLevyCommand { AccountId = AccountId }; | ||
Db = new Mock<ProviderCommitmentsDbContext>(new DbContextOptionsBuilder<ProviderCommitmentsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options) { CallBase = true }; | ||
Handler = new UpdateLevyStatusToLevyCommandHandler(new Lazy<ProviderCommitmentsDbContext>(() => Db.Object), Mock.Of<ILogger<UpdateLevyStatusToLevyCommandHandler>>()); | ||
|
||
AutoFixture.Behaviors.Add(new OmitOnRecursionBehavior()); | ||
} | ||
|
||
public Task Handle() | ||
{ | ||
return Handler.Handle(Command, CancellationToken.None); | ||
} | ||
|
||
public UpdateLevyStatusToLevyCommandHandlerTestsFixture SetAccount() | ||
{ | ||
var account = new Account(AccountId, "", "", "", DateTime.UtcNow); | ||
|
||
Db.Object.Accounts.Add(account); | ||
Db.Object.SaveChanges(); | ||
|
||
return this; | ||
} | ||
|
||
public bool IsValid(ApprenticeshipEmployerType levyStatus) | ||
{ | ||
return levyStatus == Db.Object.Accounts.First().LevyStatus; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.