Skip to content

Commit

Permalink
EES-4954 - implemented the use of DataSetVersionMapping within the im…
Browse files Browse the repository at this point in the history
…porting of Filter Option metadata, and added appropriate tests to ensure that PublicIds are carried over into the new FilterOptionMetaLinks where mappings have been established.
  • Loading branch information
duncan-at-hiveit committed Jul 11, 2024
1 parent d5b973b commit d4aa5f4
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ public void ContainsKeyProperties()
{
HashSet<string> excludedProperties =
[
nameof(LocationOptionMetaRow.Id),
$"{nameof(LocationOptionMetaRow.Id)} value",
];

var expectedProperties = typeof(LocationOptionMetaRow)
.GetProperties()
.Select(p => p.Name)
.Select(p => $"{p.Name} value")
.Except(excludedProperties)
.ToHashSet();

var optionRow = new LocationOptionMetaRow
{
Id = 1,
Type = nameof(LocationOptionMetaRow.Type),
Label = nameof(LocationOptionMetaRow.Label),
Code = nameof(LocationOptionMetaRow.Code),
OldCode = nameof(LocationOptionMetaRow.OldCode),
Urn = nameof(LocationOptionMetaRow.Urn),
LaEstab = nameof(LocationOptionMetaRow.LaEstab),
Ukprn = nameof(LocationOptionMetaRow.Ukprn),
Type = nameof(LocationOptionMetaRow.Type) + " value",
Label = nameof(LocationOptionMetaRow.Label) + " value",
Code = nameof(LocationOptionMetaRow.Code) + " value",
OldCode = nameof(LocationOptionMetaRow.OldCode) + " value",
Urn = nameof(LocationOptionMetaRow.Urn) + " value",
LaEstab = nameof(LocationOptionMetaRow.LaEstab) + " value",
Ukprn = nameof(LocationOptionMetaRow.Ukprn) + " value"
};

var rowKey = optionRow.GetRowKey();
Expand All @@ -38,6 +38,75 @@ public void ContainsKeyProperties()
Assert.Equal(expectedProperties, properties);
}
}

public class GetRowKeyPrettyTests
{
[Fact]
public void ContainsKeyProperties()
{
HashSet<string> excludedProperties =
[
$"{nameof(LocationOptionMetaRow.Id)}:{nameof(LocationOptionMetaRow.Id)} value",
];

var expectedProperties = typeof(LocationOptionMetaRow)
.GetProperties()
.Select(p => $"{p.Name}:{p.Name} value")
.Except(excludedProperties)
.ToHashSet();

var optionRow = new LocationOptionMetaRow
{
Id = 1,
Type = nameof(LocationOptionMetaRow.Type) + " value",
Label = nameof(LocationOptionMetaRow.Label) + " value",
Code = nameof(LocationOptionMetaRow.Code) + " value",
OldCode = nameof(LocationOptionMetaRow.OldCode) + " value",
Urn = nameof(LocationOptionMetaRow.Urn) + " value",
LaEstab = nameof(LocationOptionMetaRow.LaEstab) + " value",
Ukprn = nameof(LocationOptionMetaRow.Ukprn) + " value"
};

var rowKey = optionRow.GetRowKeyPretty();
var properties = rowKey.Split(',').ToHashSet();

Assert.Equal(expectedProperties, properties);
}
}

[Fact]
public void OmitsNullProperties()
{
HashSet<string> excludedProperties =
[
$"{nameof(LocationOptionMetaRow.Id)}:{nameof(LocationOptionMetaRow.Id)} value",
$"{nameof(LocationOptionMetaRow.OldCode)}:{nameof(LocationOptionMetaRow.OldCode)} value",
$"{nameof(LocationOptionMetaRow.Ukprn)}:{nameof(LocationOptionMetaRow.Ukprn)} value",
];

var expectedProperties = typeof(LocationOptionMetaRow)
.GetProperties()
.Select(p => $"{p.Name}:{p.Name} value")
.Except(excludedProperties)
.ToHashSet();

var optionRow = new LocationOptionMetaRow
{
Id = 1,
Type = nameof(LocationOptionMetaRow.Type) + " value",
Label = nameof(LocationOptionMetaRow.Label) + " value",
Code = nameof(LocationOptionMetaRow.Code) + " value",
OldCode = null,
Urn = nameof(LocationOptionMetaRow.Urn) + " value",
LaEstab = nameof(LocationOptionMetaRow.LaEstab) + " value",
Ukprn = null
};

var rowKey = optionRow.GetRowKeyPretty();
var properties = rowKey.Split(',').ToHashSet();

Assert.Equal(expectedProperties, properties);
}

public class PropertyTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ public record FilterMappingPlan

public static class MappingKeyFunctions
{
public static Func<LocationOptionMetaRow, string> LocationOptionKeyGenerator =>
option => $"{option.Label} :: {option.GetRowKey()}";
public static Func<LocationOptionMetaRow, string> LocationOptionMetaRowKeyGenerator =>
option => $"{option.Label} :: {option.GetRowKeyPretty()}";

public static Func<LocationOptionMeta, string> LocationOptionMetaKeyGenerator =>
option => LocationOptionMetaRowKeyGenerator(option.ToRow());

public static Func<FilterMeta, string> FilterKeyGenerator =>
filter => filter.PublicId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ public string GetRowKey() =>
(Urn ?? "null") + ',' +
(LaEstab ?? "null") + ',' +
(Ukprn ?? "null");

public string GetRowKeyPretty()
{
var rowKey =
$"{nameof(Type)}:{Type}," +
$"{nameof(Label)}:{Label}," +
(Code is not null ? $"{nameof(Code)}:{Code}," : "") +
(OldCode is not null ? $"{nameof(OldCode)}:{OldCode}," : "") +
(Urn is not null ? $"{nameof(Urn)}:{Urn}," : "") +
(LaEstab is not null ? $"{nameof(LaEstab)}:{LaEstab}," : "") +
(Ukprn is not null ? $"{nameof(Ukprn)}:{Ukprn}," : "");

return rowKey[..^1];
}
}
Loading

0 comments on commit d4aa5f4

Please sign in to comment.