Skip to content

Commit

Permalink
Fixed incorrect decision selector logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Shimmings committed Jan 16, 2025
1 parent b12a9be commit 8c0e451
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
30 changes: 23 additions & 7 deletions Btms.Business.Tests/Services/Decisions/DecisionServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,49 @@ public class DecisionServiceTests
[InlineData(ImportNotificationTypeEnum.Cveda, ChedADecisionCode)]
[InlineData(ImportNotificationTypeEnum.Cvedp, ChedPDecisionCode)]
[InlineData(ImportNotificationTypeEnum.Chedpp, ChedPPDecisionCode)]
public async Task When_processing_decisions_for_ched_type_notifications_Then_should_use_correct_decision_finder(ImportNotificationTypeEnum targetImportNotificationType, DecisionCode expectedDecisionCode)
public async Task When_processing_decisions_for_ched_type_notifications_not_requiring_iuu_notifications_Then_should_use_matching_ched_decision_finder(ImportNotificationTypeEnum targetImportNotificationType, DecisionCode expectedDecisionCode)
{
var decisionContext = CreateDecisionContext(targetImportNotificationType);
var decisionContext = CreateDecisionContext(targetImportNotificationType, iuuCheckRequired: false);
var serviceProvider = ConfigureDecisionFinders(decisionContext.Notifications[0]);
var decisionService = serviceProvider.GetRequiredService<IDecisionService>();

var decisionResult = await decisionService.Process(decisionContext, CancellationToken.None);

decisionResult.Decisions[0].DecisionCode.Should().Be(expectedDecisionCode);
}


[Theory]
[InlineData(ImportNotificationTypeEnum.Ced, ChedDDecisionCode)]
[InlineData(ImportNotificationTypeEnum.Cveda, ChedADecisionCode)]
[InlineData(ImportNotificationTypeEnum.Cvedp, ChedPDecisionCode)]
[InlineData(ImportNotificationTypeEnum.Chedpp, ChedPPDecisionCode)]
public async Task When_processing_decisions_when_iuu_notifications_not_indicated_Then_should_use_matching_ched_decision_finder(ImportNotificationTypeEnum targetImportNotificationType, DecisionCode expectedDecisionCode)
{
var decisionContext = CreateDecisionContext(targetImportNotificationType, iuuCheckRequired: null);
var serviceProvider = ConfigureDecisionFinders(decisionContext.Notifications[0]);
var decisionService = serviceProvider.GetRequiredService<IDecisionService>();

var decisionResult = await decisionService.Process(decisionContext, CancellationToken.None);

decisionResult.Decisions[0].DecisionCode.Should().Be(expectedDecisionCode);
}

[Theory]
[InlineData(ImportNotificationTypeEnum.Ced)]
[InlineData(ImportNotificationTypeEnum.Cveda)]
[InlineData(ImportNotificationTypeEnum.Cvedp)]
[InlineData(ImportNotificationTypeEnum.Chedpp)]
public async Task When_processing_decisions_for_iuu_notifications_whatever_the_ched_type_Then_should_use_correct_decision_finder(ImportNotificationTypeEnum targetImportNotificationType)
public async Task When_processing_decisions_when_requiring_iuu_notifications_Then_should_use_iuu_decision_finder(ImportNotificationTypeEnum targetImportNotificationType)
{
var decisionContext = CreateDecisionContext(targetImportNotificationType, true);
var decisionContext = CreateDecisionContext(targetImportNotificationType, iuuCheckRequired: true);
var serviceProvider = ConfigureDecisionFinders(decisionContext.Notifications[0]);
var decisionService = serviceProvider.GetRequiredService<IDecisionService>();

var decisionResult = await decisionService.Process(decisionContext, CancellationToken.None);

decisionResult.Decisions[0].DecisionCode.Should().Be(IuuDecisionCode);
}

private const DecisionCode ChedDDecisionCode = DecisionCode.C05;
private const DecisionCode ChedADecisionCode = DecisionCode.C06;
private const DecisionCode ChedPDecisionCode = DecisionCode.C07;
Expand Down Expand Up @@ -81,7 +97,7 @@ private void ConfigureDecisionFinders<T>(ImportNotification notification, Decisi
_serviceCollection.AddSingleton(decisionFinder);
}

private static DecisionContext CreateDecisionContext(ImportNotificationTypeEnum? importNotificationType, bool iuuCheckRequired = false)
private static DecisionContext CreateDecisionContext(ImportNotificationTypeEnum? importNotificationType, bool? iuuCheckRequired)
{
var matchingResult = new MatchingResult();
matchingResult.AddMatch("notification-1", "movement-1", 1, "document-ref-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Btms.Business.Services.Decisions.Finders;

public class ChedADecisionFinder : IDecisionFinder
{
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired == false && notification.ImportNotificationType == ImportNotificationTypeEnum.Cveda;
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired is null or false && notification.ImportNotificationType == ImportNotificationTypeEnum.Cveda;

public DecisionFinderResult FindDecision(ImportNotification notification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Btms.Business.Services.Decisions.Finders;

public class ChedDDecisionFinder : IDecisionFinder
{
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired == false && notification.ImportNotificationType == ImportNotificationTypeEnum.Ced;
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired is null or false && notification.ImportNotificationType == ImportNotificationTypeEnum.Ced;

public DecisionFinderResult FindDecision(ImportNotification notification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Btms.Business.Services.Decisions.Finders;

public class ChedPDecisionFinder : IDecisionFinder
{
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired == false && notification.ImportNotificationType == ImportNotificationTypeEnum.Cvedp;
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired is null or false && notification.ImportNotificationType == ImportNotificationTypeEnum.Cvedp;

public DecisionFinderResult FindDecision(ImportNotification notification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Btms.Business.Services.Decisions.Finders;
// ReSharper disable once InconsistentNaming
public class ChedPPDecisionFinder : IDecisionFinder
{
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired == false && notification.ImportNotificationType == ImportNotificationTypeEnum.Chedpp;
public bool CanFindDecision(ImportNotification notification) => notification.PartTwo?.ControlAuthority?.IuuCheckRequired is null or false && notification.ImportNotificationType == ImportNotificationTypeEnum.Chedpp;

public DecisionFinderResult FindDecision(ImportNotification notification)
{
Expand Down

0 comments on commit 8c0e451

Please sign in to comment.