Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests related to CDMS-144 AC1 to AC3. #47

Merged
merged 12 commits into from
Jan 14, 2025
1 change: 0 additions & 1 deletion Btms.Analytics.Tests/MovementsByMaxVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using TestDataGenerator.Scenarios;
using TestGenerator.IntegrationTesting.Backend;
using TestGenerator.IntegrationTesting.Backend.Extensions;
using TestGenerator.IntegrationTesting.Backend.Fixtures;
using Xunit;
using Xunit.Abstractions;

Expand Down
68 changes: 68 additions & 0 deletions Btms.Backend.IntegrationTests/DecisionTests/NonContiguous.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Btms.Backend.IntegrationTests.Helpers;
using Btms.Model;
using Btms.Model.Cds;
using FluentAssertions;
using TestDataGenerator.Scenarios;
using TestGenerator.IntegrationTesting.Backend;
using TestGenerator.IntegrationTesting.Backend.Fixtures;
using Xunit;
using Xunit.Abstractions;

namespace Btms.Backend.IntegrationTests.DecisionTests;

[Trait("Category", "Integration")]
public class NonContiguous(ITestOutputHelper output)
: ScenarioGeneratorBaseTest<CrNoMatchNonContiguousDecisionsScenarioGenerator>(output)
{

[Fact]
public void ShouldHave2AlvsDecisions()
{
// Assert
var movement = Client.AsJsonApiClient()
.Get("api/movements")
.GetResourceObjects<Movement>()
.Single();

movement
.AlvsDecisionStatus
.Decisions
.Count
.Should()
.Be(2);
}

[Fact]
public void ShouldHaveCorrectDecisionNumbers()
{
// Assert
var movement = Client.AsJsonApiClient()
.Get("api/movements")
.GetResourceObjects<Movement>()
.Single();

movement
.AlvsDecisionStatus
.Decisions
.Select(d => d.Context.AlvsDecisionNumber)
.Should()
.Equal(1, 3);
}

[Fact]
public void ShouldHaveVersionNotCompleteDecisionStatus()
{

// Assert
var movement = Client.AsJsonApiClient()
.Get("api/movements")
.GetResourceObjects<Movement>()
.Single();

movement
.AlvsDecisionStatus
.Context.DecisionComparison!.DecisionStatus
.Should()
.Be(DecisionStatusEnum.NoImportNotificationsLinked);
}
}
57 changes: 57 additions & 0 deletions Btms.Backend.IntegrationTests/DecisionTests/SingleChedH01Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Btms.Backend.IntegrationTests.Helpers;
using Btms.Model;
using Btms.Types.Alvs;
using FluentAssertions;
using TestDataGenerator.Scenarios.ChedP;
using TestGenerator.IntegrationTesting.Backend;
using Xunit;
using Xunit.Abstractions;

namespace Btms.Backend.IntegrationTests.DecisionTests;

[Trait("Category", "Integration")]

public class SingleChedH01Tests(ITestOutputHelper output)
: ScenarioGeneratorBaseTest<SimpleMatchScenarioGenerator>(output)
{
[Fact]
public void SingleChed_ShouldHaveH01CheckValues()
{
// Arrange
var loadedData = LoadedData;

var chedPClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d is { Message: AlvsClearanceRequest })
.Message;

// Act
var chedPMovement = Client.AsJsonApiClient()
.GetById(chedPClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();

// Assert
chedPMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!.Last().Checks!.Last()
.DecisionCode.Should().Be("H01");
}

// [Fact]
// public void SingleChed_ShouldHaveH02CheckValues()
// {
// // Arrange
// var loadedData = factory.LoadedData;
//
// var chedPClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
// d is { message: AlvsClearanceRequest })
// .message;
//
// var chedPNotification = (Types.Ipaffs.ImportNotification)loadedData.Single(d =>
// d is { message: Types.Ipaffs.ImportNotification })
// .message;
//
// // Act
// var chedPMovement = Client.AsJsonApiClient()
// .GetById(chedPClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();
//
// // Assert
// chedPMovement.Decisions.Last().Items!.Single().Checks!.Single().DecisionCode.Should().Be("H01");
// }
}
177 changes: 177 additions & 0 deletions Btms.Backend.IntegrationTests/DecisionTests/SingleChedH02Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
using Btms.Backend.IntegrationTests.Helpers;
using Btms.Model;
using Btms.Types.Alvs;
using Btms.Types.Ipaffs;
using FluentAssertions;
using TestDataGenerator.Scenarios.SpecificFiles;
using TestGenerator.IntegrationTesting.Backend;
using Xunit;
using Xunit.Abstractions;

namespace Btms.Backend.IntegrationTests.DecisionTests;

[Trait("Category", "Integration")]
public class SingleChedH02Tests(ITestOutputHelper output)
: ScenarioGeneratorBaseTest<AllChedsH02DecisionGenerator>(output)
{
[Fact]
public void SingleChed_ShouldHaveH02CheckValues()
{
// Arrange
var loadedData = LoadedData;

var chedA = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Cveda }).Message;
var chedD = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Ced }).Message;
var chedP = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Cvedp }).Message;
var chedPP = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Chedpp }).Message;

var chedAClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedA.ReferenceNumber!.Split(".")
.Last()))
.Message;
var chedDClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedD.ReferenceNumber!.Split(".")
.Last()))
.Message;
var chedPClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedP.ReferenceNumber!.Split(".")
.Last()))
.Message;
var chedPPClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedPP.ReferenceNumber!.Split(".")
.Last()))
.Message;

// Act
var chedAMovement = Client.AsJsonApiClient()
.GetById(chedAClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();
var chedDMovement = Client.AsJsonApiClient()
.GetById(chedDClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();
var chedPMovement = Client.AsJsonApiClient()
.GetById(chedPClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();
var chedPPMovement = Client.AsJsonApiClient()
.GetById(chedPPClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();

// Assert
string decisionCode = "";
chedAMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("H02");
}).Should().BeTrue("Expected H02. Actually {0}", decisionCode);
chedDMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("H02");
}).Should().BeTrue("Expected H02. Actually {0}", decisionCode);
chedPMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("H02");
}).Should().BeTrue("Expected H02. Actually {0}", decisionCode);
chedPPMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("H02");
}).Should().BeTrue("Expected H02. Actually {0}", decisionCode);
}
}

[Trait("Category", "Integration")]
public class SingleChedDecisionTests(ITestOutputHelper output)
: ScenarioGeneratorBaseTest<AllChedsNonHoldDecisionGenerator>(output)
{
[Fact]
public void SingleChed_ShouldHaveH02CheckValues()
{
// Arrange
var loadedData = LoadedData;

var chedA = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Cveda }).Message;
var chedD = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Ced }).Message;
var chedP = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Cvedp }).Message;
var chedPP = (ImportNotification)loadedData.Single(d =>
d.Message is ImportNotification { ImportNotificationType: ImportNotificationTypeEnum.Chedpp }).Message;

var chedAClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedA.ReferenceNumber!.Split(".")
.Last()))
.Message;
var chedDClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedD.ReferenceNumber!.Split(".")
.Last()))
.Message;
var chedPClearanceRequest = (AlvsClearanceRequest)loadedData.Single(d =>
d.Message is AlvsClearanceRequest clearanceRequest && clearanceRequest.Header!.EntryReference!.Contains(
chedP.ReferenceNumber!.Split(".")
.Last()))
.Message;

// Act
var chedAMovement = Client.AsJsonApiClient()
.GetById(chedAClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();
var chedDMovement = Client.AsJsonApiClient()
.GetById(chedDClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();
var chedPMovement = Client.AsJsonApiClient()
.GetById(chedPClearanceRequest!.Header!.EntryReference!, "api/movements").GetResourceObject<Movement>();

// Assert
string decisionCode = "";
chedAMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("C03");
}).Should().BeTrue("Expected C03. Actually {0}", decisionCode);
chedDMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("C03");
}).Should().BeTrue("Expected C03. Actually {0}", decisionCode);
chedPMovement.Decisions.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;
return decisionCode.Equals("C03");
}).Should().BeTrue("Expected C03. Actually {0}", decisionCode);
}
}

[Trait("Category", "Integration")]
public class MultiChedDecisionTest(ITestOutputHelper output)
: ScenarioGeneratorBaseTest<MultiChedPMatchScenarioGenerator>(output)
{
[Fact]
public void MultiChed_ShouldHaveH01CheckValues()
{
string decisionCode = "";
var expectedDecision = "H02";
var movements = Client.AsJsonApiClient().Get("api/movements").GetResourceObjects<Movement>().Single().Decisions
.OrderBy(x => x.ServiceHeader?.ServiceCalled).Last().Items!
.All(i =>
{
decisionCode = i.Checks!.First().DecisionCode!;

return decisionCode.Equals(expectedDecision);
}).Should().BeTrue($"Expected {expectedDecision}. Actually {{0}}", decisionCode);
;
}
}
5 changes: 4 additions & 1 deletion TestDataGenerator/ClearanceRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ protected override ClearanceRequestBuilder<T> Validate()
cr.Header!.EntryReference.AssertHasValue("Clearance Request EntryReference missing");
cr.Header!.EntryVersionNumber.AssertHasValue("Clearance Request EntryVersionNumber missing");
cr.Header!.DeclarationUcr.AssertHasValue("Clearance Request DeclarationUcr missing");
cr.Header!.MasterUcr.AssertHasValue("Clearance Request MasterUcr missing");

// masterUcr can be null
// cr.Header!.MasterUcr.AssertHasValue("Clearance Request MasterUcr missing");

// cr.Header!.ArrivalDateTime.AssertHasValue("Clearance Request ArrivalDateTime missing");

Array.ForEach(cr.Items!, i => Array.ForEach(i.Documents!, d => d.DocumentReference.AssertHasValue()));
Expand Down
16 changes: 16 additions & 0 deletions TestDataGenerator/ImportNotificationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ public ImportNotificationBuilder<T> WithInspectionStatus(InspectionRequiredEnum
x.PartTwo!.InspectionRequired = inspectionRequired;
});
}

public ImportNotificationBuilder<T> WithImportNotificationStatus(ImportNotificationStatusEnum importNotificationStatus = ImportNotificationStatusEnum.Submitted)
{
return Do(x =>
{
x.Status = importNotificationStatus;
});
}

public ImportNotificationBuilder<T> WithPartTwoDecision(Decision decision)
{
return Do(x =>
{
x.PartTwo!.Decision = decision;
});
}

public ImportNotificationBuilder<T> WithVersionNumber(int version = 1)
{
Expand Down
Loading
Loading