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
18 changes: 8 additions & 10 deletions EconDataLens.Tests/EtlRepositoryTests/AreaEtlRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Configuration;
using EconDataLens.Services;
Expand All @@ -14,7 +13,6 @@ public class AreaEtlRepositoryTests
private EconDataLensDbContext _dbContext = null!;
private ICpiDataFileParser _parser = null!;
private ICpiIngestionRepository _repository = null!;
private ICpiIngestionService _service = null!;
private string _connectionString = string.Empty;

[SetUp]
Expand Down Expand Up @@ -61,13 +59,13 @@ public async Task UpsertCpiAreaAsync_NewAreas_InsertsSuccessfully()

var sample = await _dbContext.CpiArea.FirstOrDefaultAsync(a => a.AreaCode == "0000");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.AreaName, Is.EqualTo("U.S. city average"));
Assert.That(sample!, Is.Not.Null);
Assert.That(sample!.AreaName, Is.EqualTo("U.S. city average"));

sample = await _dbContext.CpiArea.FirstOrDefaultAsync(a => a.AreaCode == "S49G");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.AreaName, Is.EqualTo("Urban Alaska"));
Assert.That(sample!.AreaName, Is.EqualTo("Urban Alaska"));

}

Expand All @@ -85,13 +83,13 @@ public async Task UpsertCpiAreaAsync_ExistingAreas_UpdatesSuccessfully()

var sample = await _dbContext.CpiArea.FirstOrDefaultAsync(a => a.AreaCode == "0000");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.AreaName, Is.EqualTo("U.S. city average"));
Assert.That(sample!, Is.Not.Null);
Assert.That(sample!.AreaName, Is.EqualTo("U.S. city average"));

sample = await _dbContext.CpiArea.FirstOrDefaultAsync(a => a.AreaCode == "S49G");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.AreaName, Is.EqualTo("Urban Alaska"));
Assert.That(sample!.AreaName, Is.EqualTo("Urban Alaska"));

// Ingest modified data

Expand All @@ -105,8 +103,8 @@ public async Task UpsertCpiAreaAsync_ExistingAreas_UpdatesSuccessfully()

sample = await _dbContext.CpiArea.FirstOrDefaultAsync(a => a.AreaCode == "S49G");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.AreaName, Is.EqualTo("Urban Alaska UPDATED"));
Assert.That(sample!, Is.Not.Null);
Assert.That(sample!.AreaName, Is.EqualTo("Urban Alaska UPDATED"));
}

[TearDown]
Expand Down
12 changes: 5 additions & 7 deletions EconDataLens.Tests/EtlRepositoryTests/ItemEtlRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Configuration;
using EconDataLens.Services;
Expand All @@ -14,7 +13,6 @@ public class ItemEtlRepositoryTests
private EconDataLensDbContext _dbContext = null!;
private ICpiDataFileParser _parser = null!;
private ICpiIngestionRepository _repository = null!;
private ICpiIngestionService _service = null!;
private string _connectionString = string.Empty;

[SetUp]
Expand Down Expand Up @@ -62,12 +60,12 @@ public async Task UpsertCpiItemsAsync_NewItems_InsertsSuccessfully()
var sample = await _dbContext.CpiItem.FirstOrDefaultAsync(i => i.ItemCode == "AA0");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.ItemName, Is.EqualTo("All items - old base"));
Assert.That(sample!.ItemName, Is.EqualTo("All items - old base"));

sample = await _dbContext.CpiItem.FirstOrDefaultAsync(i => i.ItemCode == "SSHJ031");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.ItemName, Is.EqualTo("Infants' furniture"));
Assert.That(sample!.ItemName, Is.EqualTo("Infants' furniture"));

}

Expand All @@ -86,12 +84,12 @@ public async Task UpsertCpiItemsAsync_ExistingItems_UpdatesSuccessfully()
var sample = await _dbContext.CpiItem.FirstOrDefaultAsync(i => i.ItemCode == "AA0");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.ItemName, Is.EqualTo("All items - old base"));
Assert.That(sample!.ItemName, Is.EqualTo("All items - old base"));

sample = await _dbContext.CpiItem.FirstOrDefaultAsync(i => i.ItemCode == "SSHJ031");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.ItemName, Is.EqualTo("Infants' furniture"));
Assert.That(sample!.ItemName, Is.EqualTo("Infants' furniture"));

// Ingest modified data

Expand All @@ -106,7 +104,7 @@ public async Task UpsertCpiItemsAsync_ExistingItems_UpdatesSuccessfully()
sample = await _dbContext.CpiItem.FirstOrDefaultAsync(i => i.ItemCode == "SSHJ031");

Assert.That(sample, Is.Not.Null);
Assert.That(sample.ItemName, Is.EqualTo("Infants' furniture UPDATED"));
Assert.That(sample!.ItemName, Is.EqualTo("Infants' furniture UPDATED"));
}

[TearDown]
Expand Down
114 changes: 114 additions & 0 deletions EconDataLens.Tests/EtlRepositoryTests/PeriodEtlRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Configuration;
using EconDataLens.Services;
using EconDataLens.Data;
using EconDataLens.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.EtlRepositoryTests;

public class PeriodEtlRepositoryTests
{
private EconDataLensDbContext _dbContext = null!;
private ICpiDataFileParser _parser = null!;
private ICpiIngestionRepository _repository = null!;
private string _connectionString = string.Empty;

[SetUp]
public async Task SetUp()
{
_connectionString = PostgresFixture.ConnectionString;
var opts = new DbContextOptionsBuilder<EconDataLensDbContext>()
.UseNpgsql(_connectionString)
.UseSnakeCaseNamingConvention()
.Options;

await DbReset.RecreateDatabaseAsync(_connectionString);

_dbContext = new EconDataLensDbContext(opts);

var blsOptions = Options.Create(new BlsOptions
{
Cpi = new CpiOptions
{
PeriodFile = "cu.period.sample"
}
});

var downloadOptions = Options.Create(new DownloadOptions
{
DownloadDirectory = "TestData/EtlData",
DeleteDownloadedFiles = false
});

_parser = new CpiDataFileParser(blsOptions, downloadOptions);
_repository = new CpiIngestionRepository(_dbContext);
}

[Test]
public async Task UpsertCpiPeriodsAsync_NewPeriods_InsertsSuccessfully()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "EtlData", "cu.period.sample");

await _repository.UpsertCpiPeriodAsync(_parser.ParseCpiPeriodsAsync(path));

var count = await _dbContext.CpiPeriod.CountAsync();

Assert.That(count, Is.EqualTo(16));

var sample = await _dbContext.CpiPeriod.FirstOrDefaultAsync(p => p.Period == "M01");

Assert.Multiple(() =>
{
Assert.That(sample, Is.Not.Null);
Assert.That(sample!.PeriodName, Is.EqualTo("January"));
Assert.That(sample!.PeriodAbbreviation, Is.EqualTo("JAN"));
});
}

[Test]
public async Task UpsertCpiPeriodsAsync_ExistingPeriods_UpdatesSuccessfully()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "EtlData", "cu.period.sample");

await _repository.UpsertCpiPeriodAsync(_parser.ParseCpiPeriodsAsync(path));

var count = await _dbContext.CpiPeriod.CountAsync();

Assert.That(count, Is.EqualTo(16));

var sample = await _dbContext.CpiPeriod.FirstOrDefaultAsync(p => p.Period == "M01");

Assert.Multiple(() =>
{
Assert.That(sample, Is.Not.Null);
Assert.That(sample!.PeriodName, Is.EqualTo("January"));
Assert.That(sample!.PeriodAbbreviation, Is.EqualTo("JAN"));
});

path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "EtlData", "cu.period.modified.sample");
await _repository.UpsertCpiPeriodAsync(_parser.ParseCpiPeriodsAsync(path));

count = await _dbContext.CpiPeriod.CountAsync();

Assert.That(count, Is.EqualTo(16));

sample = await _dbContext.CpiPeriod.FirstOrDefaultAsync(p => p.Period == "M01");

Assert.Multiple(() =>
{
Assert.That(sample, Is.Not.Null);
Assert.That(sample!.PeriodName, Is.EqualTo("JanuaryM"));
Assert.That(sample!.PeriodAbbreviation, Is.EqualTo("MOD"));
});

}

[TearDown]
public async Task TearDown()
{
await _dbContext.DisposeAsync();
}

}
17 changes: 17 additions & 0 deletions EconDataLens.Tests/TestData/EtlData/cu.period.modified.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
period period_abbr period_name
M01 MOD JanuaryM
M02 FEB February
M03 MAR March
M04 APR April
M05 MAY May
M06 JUN June
M07 JUL July
M08 AUG August
M09 SEP September
M10 OCT October
M11 NOV November
M12 DEC December
M13 AN AV Annual Average
S01 HALF1 First Half
S02 HALF2 Second Half
S03 AN AV Annual Average
Loading