Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ await ResolveAndAddActivitiesAsync(
cancellationToken);
}

// If no derived mapping resolved a site type, fall back to the explicit site type code on the representative
derivedSiteType ??= await ResolveSiteTypeAsync(representative.SiteTypeCode, getSiteTypeByCode, cancellationToken);

return (allDerivedActivities, derivedSiteType);
}

Expand Down Expand Up @@ -391,7 +394,7 @@ private static async Task<Site> CreateSiteAsync(
null,
representative.Deleted,
isPermanentLandHolding ? null : representative.SecondaryCph,
representative.CphTypeIdentifier,
string.IsNullOrEmpty(representative.CphTypeIdentifier) ? null : representative.CphTypeIdentifier,
siteType,
location,
isPermanentLandHolding ? representative.SecondaryCph : null);
Expand Down Expand Up @@ -427,7 +430,7 @@ private static async Task<Site> UpdateSiteAsync(
null,
representative.Deleted,
isPermanentLandHolding ? null : representative.SecondaryCph,
representative.CphTypeIdentifier,
string.IsNullOrEmpty(representative.CphTypeIdentifier) ? null : representative.CphTypeIdentifier,
isPermanentLandHolding ? representative.SecondaryCph : null);

var (updatedAddress, updatedCommunication) = await ResolveLocationPartsAsync(addressSource, getCountryById, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public async Task GivenHoldingDataAlreadyExists_WhenTheHolderIsChanged_ShouldCor
VerifyGoldSiteGroupMarks(updateResult.GoldSiteGroupMarks!, updateScenarioData.ExpectedGoldSiteGroupMarks!);
}

[Fact]
public async Task GivenACommonLandHolding_WhenExecutingTheBulkImportStrategy_ShouldUseCommonLandAddressDetails()
{
var scenarioData = SamTestScenarios.Scenario_CommonLandOnly;
var result = await RunDefaultScenarioAsync(scenarioData);

VerifyGoldSite(result.GoldSite!, scenarioData.ExpectedGoldSite!);
}

private async Task<SamHoldingImportContext> RunDefaultScenarioAsync(SamTestScenarioData scenarioData, SamHoldingImportContext? existingContext = null)
{
var partyIds = scenarioData.RawParties.Select(x => x.PARTY_ID).Union(scenarioData.RawHolders.Select(x => x.PARTY_ID)).Distinct().ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ private static SiteDocument GetBlankSiteDocument()
Id = GoldSiteId,
Name = "",
Source = "SAM",
HoldingType = string.Empty,
HoldingType = null,
Location = new LocationDocument()
{
IdentifierId = "any-guid",
Expand Down
3 changes: 2 additions & 1 deletion tests/KeeperData.Tests.Common/TestData/CountryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static class CountryData
public static (string? id, string? code, string? name) Find(string code, string? internalCode)
{
var searchCode = DetermineSearchKey(code, internalCode);
var type = GetByCode(searchCode!);
if (searchCode == null) return (null, null, null);
var type = GetByCode(searchCode);
if (type == null) return (null, null, null);
return (type.IdentifierId, type.Code, type.Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,90 @@ public static class ExpectedGoldSite
Activities = []
//Activities = [.. DefaultExpectedSite.Activities.Where(x => x.Type.Code == "RM")]
};

public static SiteDocument ExpectedSite_CommonLandOnly =>
new()
{
Id = Guid.NewGuid().ToString(),
CreatedDate = new DateTime(2025, 1, 1, 0, 0, 0),
LastUpdatedDate = new DateTime(2025, 11, 13, 0, 0, 0),
Type = new SiteTypeSummaryDocument
{
IdentifierId = "cl-site-type-id",
Code = "CL",
Name = "Common Land"
},
Name = "Premises 22",
State = HoldingStatusType.Active.GetDescription(),
StartDate = default,
EndDate = null,
Source = SourceSystemType.SAM.ToString(),
DestroyIdentityDocumentsFlag = null,
Deleted = false,

Location = new LocationDocument
{
IdentifierId = Guid.NewGuid().ToString(),
Easting = null,
Northing = null,
OsMapReference = null,

Address = new AddressDocument
{
IdentifierId = Guid.NewGuid().ToString(),
AddressLine1 = "Holding Street 22",
AddressLine2 = "Town22",
PostTown = "Locality22",
Postcode = "CPH22 222",
LastUpdatedDate = new DateTime(2025, 11, 13, 0, 0, 0)
},

Communication =
[
new()
{
IdentifierId = Guid.NewGuid().ToString(),
Email = null,
Mobile = null,
Landline = null,
PrimaryContactFlag = false,
LastUpdatedDate = new DateTime(2025, 11, 13, 0, 0, 0)
}
],

LastUpdatedDate = new DateTime(2025, 11, 13, 0, 0, 0)
},

Identifiers =
[
new()
{
IdentifierId = Guid.NewGuid().ToString(),
Identifier = "00/000/8267",
Type = new SiteIdentifierSummaryDocument
{
IdentifierId = Guid.NewGuid().ToString(),
Code = HoldingIdentifierType.CPHN.ToString(),
Name = HoldingIdentifierType.CPHN.GetDescription()!,
LastUpdatedDate = new DateTime(2025, 11, 13, 0, 0, 0)
},
LastUpdatedDate = new DateTime(2025, 11, 13, 0, 0, 0)
}
],

Parties = [],
Species = [],
Marks = [],
Activities = [],
AssociatedMainHoldings =
[
new()
{
HoldingIdentifier = "17/050/0003",
ContiguousFlag = false,
StartDate = null,
EndDate = null
}
]
};
}
38 changes: 38 additions & 0 deletions tests/KeeperData.Tests.Common/TestData/Sam/SamTestScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static (string? associatedSiteTypeCode, string? associatedSiteActivityCod
}

private static readonly string s_cphNumber = "12/345/6789";
private static readonly string s_commonLandCph = "00/000/8267";

public static SamTestScenarioData DefaultScenario => new()
{
Expand Down Expand Up @@ -83,6 +84,18 @@ public static SamTestScenarioData Scenario_UpdatedHolderAndParties()
};
}

public static SamTestScenarioData Scenario_CommonLandOnly => new()
{
Cph = s_commonLandCph,
RawHoldings = [],
RawHerds = [],
RawHolders = [],
RawParties = [],
RawCommonLandsByCommonCph = [SamCommonLand_22],
RawPorts = [],
ExpectedGoldSite = ExpectedGoldSite.ExpectedSite_CommonLandOnly
};

public class SamTestScenarioData
{
public required string Cph { get; init; }
Expand Down Expand Up @@ -565,4 +578,29 @@ public class SamTestScenarioData
PAON_END_NUMBER_SUFFIX = null,
PAON_DESCRIPTION = null
};

private static SamCommonLand SamCommonLand_22 => new()
{
BATCH_ID = 1,
CHANGE_TYPE = "I",
CreatedAtUtc = new DateTime(2025, 1, 1, 0, 0, 0),
UpdatedAtUtc = new DateTime(2025, 11, 13, 0, 0, 0),
IsDeleted = false,

COMMON_LAND_PREMISE_ID = "554454",
MAIN_CPH = "17/050/0003",
COMMON_CPH = s_commonLandCph,
PREMISES_NAME = "Premises 22",
ADDRESS_LINE_1 = "Holding Street 22",
ADDRESS_LINE_2 = "Town22",
ADDRESS_LINE_3 = "Locality22",
POSTCODE = "CPH22 222",
LOCAL_AUTH_NAME = null,
COUNTRY = null,
EASTING = null,
NORTHING = null,
CONTIGUOUS_COMMON = null,
START_DATE = null,
END_DATE = null
};
}
Loading