Skip to content

Commit

Permalink
remove two columns for energy suppliers in MDMP
Browse files Browse the repository at this point in the history
  • Loading branch information
vbelinschi committed Sep 23, 2024
1 parent 036f1de commit 9965871
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,40 @@ public sealed class SettlementReportMeteringPointMasterDataRowMap : ClassMap<Set
{
public SettlementReportMeteringPointMasterDataRowMap(SettlementReportRequestedByActor actorInfo)
{
var columnIndex = 0;
Map(r => r.MeteringPointId)
.Name("METERINGPOINTID")
.Index(0);
.Index(columnIndex++);

Map(r => r.PeriodStart)
.Name("VALIDFROM")
.Index(1);
.Index(columnIndex++);

Map(r => r.PeriodEnd)
.Name("VALIDTO")
.Index(2);
.Index(columnIndex++);

Map(r => r.GridAreaId)
.Name("GRIDAREAID")
.Index(3)
.Index(columnIndex++)
.Convert(row => row.Value.GridAreaId.PadLeft(3, '0'));

Map(r => r.GridAreaToId)
.Name("TOGRIDAREAID")
.Index(4)
.Convert(row => row.Value.GridAreaToId?.PadLeft(3, '0'));

Map(r => r.GridAreaFromId)
.Name("FROMGRIDAREAID")
.Index(5)
.Convert(row => row.Value.GridAreaFromId?.PadLeft(3, '0'));
if (actorInfo.MarketRole is not MarketRole.EnergySupplier)
{
Map(r => r.GridAreaToId)
.Name("TOGRIDAREAID")
.Index(columnIndex++)
.Convert(row => row.Value.GridAreaToId?.PadLeft(3, '0'));

Map(r => r.GridAreaFromId)
.Name("FROMGRIDAREAID")
.Index(columnIndex++)
.Convert(row => row.Value.GridAreaFromId?.PadLeft(3, '0'));
}

Map(r => r.MeteringPointType)
.Name("TYPEOFMP")
.Index(6)
.Index(columnIndex++)
.Convert(row => row.Value.MeteringPointType switch
{
null => string.Empty,
Expand All @@ -104,7 +108,7 @@ public SettlementReportMeteringPointMasterDataRowMap(SettlementReportRequestedBy

Map(r => r.SettlementMethod)
.Name("SETTLEMENTMETHOD")
.Index(7)
.Index(columnIndex++)
.Convert(row => row.Value.SettlementMethod switch
{
null => string.Empty,
Expand All @@ -117,7 +121,7 @@ public SettlementReportMeteringPointMasterDataRowMap(SettlementReportRequestedBy
{
Map(r => r.EnergySupplierId)
.Name("ENERGYSUPPLIERID")
.Index(8);
.Index(columnIndex++);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public SettlementReportMeteringPointMasterDataRepository(ISettlementReportDatabr

public Task<int> CountAsync(SettlementReportRequestFilterDto filter, long maximumCalculationVersion)
{
return Task.FromResult<int>(1);
return Task.FromResult(1);
}

public async IAsyncEnumerable<SettlementReportMeteringPointMasterDataRow> GetAsync(SettlementReportRequestFilterDto filter, int skip, int take, long maximumCalculationVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ await _databricksSqlStatementApiFixture.DatabricksSchemaManager.InsertAsync<Sett
public async Task RequestFileAsync_ForMeteringPointMasterData_ReturnsExpectedCsv()
{
// Arrange
await _databricksSqlStatementApiFixture.DatabricksSchemaManager
.EmptyAsync(_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions.Value.METERING_POINT_MASTER_DATA_V1_VIEW_NAME);

var calculationId = Guid.Parse("f8af5e30-3c65-439e-8fd0-1da0c40a26de");
var filter = new SettlementReportRequestFilterDto(
_gridAreaCodes.ToDictionary(x => x, _ => (CalculationId?)new CalculationId(calculationId)),
Expand Down Expand Up @@ -327,6 +330,62 @@ await _databricksSqlStatementApiFixture.DatabricksSchemaManager.InsertAsync<Sett
fileLines[2]);
}

[Fact]
public async Task RequestFileAsync_ForMeteringPointMasterData_ForEnergySuppliers_ReturnsExpectedCsv()
{
// Arrange
await _databricksSqlStatementApiFixture.DatabricksSchemaManager
.EmptyAsync(_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions.Value.METERING_POINT_MASTER_DATA_V1_VIEW_NAME);

var calculationId = Guid.Parse("f8af5e30-3c65-439e-8fd0-1da0c40a26de");
var filter = new SettlementReportRequestFilterDto(
_gridAreaCodes.ToDictionary(x => x, _ => (CalculationId?)new CalculationId(calculationId)),
_january1St.ToDateTimeOffset(),
_january5Th.ToDateTimeOffset(),
CalculationType.WholesaleFixing,
null,
null);

var requestId = new SettlementReportRequestId(Guid.NewGuid().ToString());
var fileRequest = new SettlementReportFileRequestDto(
requestId,
SettlementReportFileContent.MeteringPointMasterData,
new SettlementReportPartialFileInfo(Guid.NewGuid().ToString(), true),
filter,
1);
var actorInfo = new SettlementReportRequestedByActor(MarketRole.EnergySupplier, null);

await _databricksSqlStatementApiFixture.DatabricksSchemaManager.InsertAsync<SettlementReportMeteringPointMasterDataViewColumns>(
_databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions.Value.METERING_POINT_MASTER_DATA_V1_VIEW_NAME,
[
["'f8af5e30-3c65-439e-8fd0-1da0c40a26de'", "'wholesale_fixing'", "'15cba911-b91e-4782-bed4-f0d2841829e1'", "'2022-01-02T02:00:00.000+00:00'", "'2022-01-03T02:00:00.000+00:00'", "'018'", "'406'", "'407'", "'consumption'", "'flex'", "8397670583196"],
["'f8af5e30-3c65-439e-8fd0-1da0c40a26de'", "'wholesale_fixing'", "'15cba911-b91e-4782-bed4-f0d2841829e2'", "'2022-01-02T02:00:00.000+00:00'", "'2022-01-03T02:00:00.000+00:00'", "'018'", "'406'", "'407'", "'consumption'", "'flex'", "8397670583196"],
]);

// Act
var actual = await Sut.RequestFileAsync(fileRequest, actorInfo);

// Assert
Assert.Equal(requestId, actual.RequestId);

var container = _settlementReportFileBlobStorageFixture.CreateBlobContainerClient();
var generatedFileBlob = container.GetBlobClient($"settlement-reports/{requestId.Id}/{actual.StorageFileName}");
var generatedFile = await generatedFileBlob.DownloadContentAsync();
var fileContents = generatedFile.Value.Content.ToString();
var fileLines = fileContents.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

Assert.Equal(3, fileLines.Length);
Assert.Equal(
"METERINGPOINTID,VALIDFROM,VALIDTO,GRIDAREAID,TYPEOFMP,SETTLEMENTMETHOD",
fileLines[0]);
Assert.Equal(
"\"15cba911-b91e-4782-bed4-f0d2841829e1\",2022-01-02T02:00:00Z,2022-01-03T02:00:00Z,\"018\",\"E17\",\"D01\"",
fileLines[1]);
Assert.Equal(
"\"15cba911-b91e-4782-bed4-f0d2841829e2\",2022-01-02T02:00:00Z,2022-01-03T02:00:00Z,\"018\",\"E17\",\"D01\"",
fileLines[2]);
}

[Fact]
public async Task RequestFileAsync_ForMonthlyAmount_ReturnsExpectedCsv()
{
Expand Down

0 comments on commit 9965871

Please sign in to comment.