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
2 changes: 1 addition & 1 deletion EconDataLens.Tests/EconDataLens.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<ProjectReference Include="..\EconDataLens.Etl\EconDataLens.Etl.csproj" />
<ProjectReference Include="..\EconDataLens.Services\EconDataLens.Services.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="TestData/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
144 changes: 72 additions & 72 deletions EconDataLens.Tests/EtlParserTests/CpiAreaParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Core.Configuration;
using EconDataLens.Services;
Expand All @@ -8,74 +8,74 @@ namespace EconDataLens.Tests.EtlParserTests;

public class CpiAreaParserTests
{
private ICpiDataFileParser _parser;
[SetUp]
public void SetUp()
{
// This isn't actually used in the test, but the parser requires it.
var blsOptions = Options.Create(new BlsOptions
{
Cpi = new CpiOptions
{
FootnoteFile = "cu.footnote"
}
});

// This isn't actually used in the test, but the parser requires it.
var downloadOptions = Options.Create(new DownloadOptions
{
DownloadDirectory = "downloads",
DeleteDownloadedFiles = false
});

_parser = new CpiDataFileParser(blsOptions, downloadOptions);
}

[Test]
public async Task ParseCpiAreaAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.area.empty");

var rows = new List<CpiArea>();
await foreach (var row in _parser.ParseCpiAreasAsync(path))
rows.Add(row);
Assert.That(rows, Is.Empty);
}
[Test]
public async Task ParseCpiAreaAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.area.sample");

var rows = new List<CpiArea>();
await foreach (var row in _parser.ParseCpiAreasAsync(path))
rows.Add(row);
Assert.That(rows, Has.Count.EqualTo(4));
Assert.Multiple(() =>
{
Assert.That(rows[0].AreaCode, Is.EqualTo("0000"));
Assert.That(rows[0].AreaName, Is.EqualTo("U.S. city average"));
Assert.That(rows[1].AreaCode, Is.EqualTo("0100"));
Assert.That(rows[1].AreaName, Is.EqualTo("Northeast"));
Assert.That(rows[2].AreaCode, Is.EqualTo("0110"));
Assert.That(rows[2].AreaName, Is.EqualTo("New England"));

Assert.That(rows[3].AreaCode, Is.EqualTo("0120"));
Assert.That(rows[3].AreaName, Is.EqualTo("Middle Atlantic"));

// Assert row 4 throws index out of range if accessed
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
var _ = rows[4].AreaCode;
});
});
}
}
private ICpiDataFileParser _parser;

[SetUp]
public void SetUp()
{
// This isn't actually used in the test, but the parser requires it.
var blsOptions = Options.Create(new BlsOptions
{
Cpi = new CpiOptions
{
FootnoteFile = "cu.footnote"
}
});

// This isn't actually used in the test, but the parser requires it.
var downloadOptions = Options.Create(new DownloadOptions
{
DownloadDirectory = "downloads",
DeleteDownloadedFiles = false
});

_parser = new CpiDataFileParser(blsOptions, downloadOptions);
}

[Test]
public async Task ParseCpiAreaAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.area.empty");

var rows = new List<CpiArea>();

await foreach (var row in _parser.ParseCpiAreasAsync(path))
rows.Add(row);

Assert.That(rows, Is.Empty);
}

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

var rows = new List<CpiArea>();

await foreach (var row in _parser.ParseCpiAreasAsync(path))
rows.Add(row);

Assert.That(rows, Has.Count.EqualTo(4));

Assert.Multiple(() =>
{
Assert.That(rows[0].AreaCode, Is.EqualTo("0000"));
Assert.That(rows[0].AreaName, Is.EqualTo("U.S. city average"));

Assert.That(rows[1].AreaCode, Is.EqualTo("0100"));
Assert.That(rows[1].AreaName, Is.EqualTo("Northeast"));

Assert.That(rows[2].AreaCode, Is.EqualTo("0110"));
Assert.That(rows[2].AreaName, Is.EqualTo("New England"));

Assert.That(rows[3].AreaCode, Is.EqualTo("0120"));
Assert.That(rows[3].AreaName, Is.EqualTo("Middle Atlantic"));

// Assert row 4 throws index out of range if accessed
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
var _ = rows[4].AreaCode;
});
});
}
}
20 changes: 10 additions & 10 deletions EconDataLens.Tests/EtlParserTests/CpiDataParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Core.Interfaces;
using EconDataLens.Services;
Expand All @@ -10,7 +10,7 @@ namespace EconDataLens.Tests.EtlParserTests;
public class CpiDataParserTests
{
private ICpiDataFileParser _parser;

[SetUp]
public void SetUp()
{
Expand All @@ -36,40 +36,40 @@ public void SetUp()
[Test]
public async Task ParseCpiFootnoteAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.data.0.Current.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.data.0.Current.empty");
var rows = new List<CpiData>();

await foreach (var row in _parser.ParseCpiDataAsync(path))
rows.Add(row);

Assert.That(rows, Has.Count.EqualTo(0));
Assert.That(rows, Is.Empty);
}

[Test]
public async Task ParseCpiDataAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.data.0.Current.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.data.0.Current.sample");
var rows = new List<CpiData>();

await foreach (var row in _parser.ParseCpiDataAsync(path))
rows.Add(row);

Assert.That(rows, Has.Count.EqualTo(2));

Assert.Multiple(() =>
{
Assert.That(rows[0].SeriesId, Is.EqualTo("CUSR0000SA0"));
Assert.That(rows[0].Year, Is.EqualTo(1997));
Assert.That(rows[0].Period, Is.EqualTo("M01"));
Assert.That(rows[0].Value, Is.EqualTo(159.40m));
Assert.That(rows[0].FootnoteCodes, Is.Null);

Assert.That(rows[1].SeriesId, Is.EqualTo("CUSR0000SA0"));
Assert.That(rows[1].Year, Is.EqualTo(1997));
Assert.That(rows[1].Period, Is.EqualTo("M02"));
Assert.That(rows[1].Value, Is.EqualTo(159.70m));
Assert.That(rows[1].FootnoteCodes, Is.Null);
});
}
}
}
8 changes: 4 additions & 4 deletions EconDataLens.Tests/EtlParserTests/CpiFootnoteParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Core.Interfaces;
using EconDataLens.Services;
Expand Down Expand Up @@ -37,7 +37,7 @@ public void SetUp()
public async Task ParseCpiFootnoteAsync_HeaderOnly_YieldsNoResults()
{
// Arrange
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.footnote.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.footnote.empty");

// Act
var rows = new List<CpiFootnote>();
Expand All @@ -53,7 +53,7 @@ public async Task ParseCpiFootnoteAsync_HeaderOnly_YieldsNoResults()
public async Task ParseCpiFootnoteAsync_FileWithRecords_YieldsResults()
{
// Arrange
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.footnote.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.footnote.sample");

// Act
var rows = new List<CpiFootnote>();
Expand All @@ -72,4 +72,4 @@ public async Task ParseCpiFootnoteAsync_FileWithRecords_YieldsResults()
Assert.That(rows[1].FootnoteText, Is.EqualTo("This is another footnote"));
});
}
}
}
16 changes: 8 additions & 8 deletions EconDataLens.Tests/EtlParserTests/CpiItemParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Core.Configuration;
using EconDataLens.Services;
Expand All @@ -9,7 +9,7 @@ namespace EconDataLens.Tests.EtlParserTests;
public class CpiItemParserTests
{
private ICpiDataFileParser _parser;

[SetUp]
public void SetUp()
{
Expand All @@ -35,26 +35,26 @@ public void SetUp()
[Test]
public async Task ParseCpiItemAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.item.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.item.empty");
var rows = new List<CpiItem>();

await foreach (var row in _parser.ParseCpiItemsAsync(path))
rows.Add(row);

Assert.That(rows, Is.Empty);
}

[Test]
public async Task ParseCpiItemAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.item.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.item.sample");
var rows = new List<CpiItem>();

await foreach (var row in _parser.ParseCpiItemsAsync(path))
rows.Add(row);

Assert.That(rows, Has.Count.EqualTo(3));

Assert.Multiple(() =>
{
Assert.That(rows, Is.Not.Null);
Expand All @@ -67,4 +67,4 @@ public async Task ParseCpiItemAsync_FileWithRecords_YieldsResults()
});
}

}
}
14 changes: 7 additions & 7 deletions EconDataLens.Tests/EtlParserTests/CpiPeriodParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Services;
Expand All @@ -9,7 +9,7 @@ namespace EconDataLens.Tests.EtlParserTests;
public class CpiPeriodParserTests
{
private ICpiDataFileParser _parser;

[SetUp]
public void SetUp()
{
Expand All @@ -35,19 +35,19 @@ public void SetUp()
[Test]
public async Task ParseCpiPeriodAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.period.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.period.empty");
var rows = new List<CpiPeriod>();

await foreach (var row in _parser.ParseCpiPeriodsAsync(path))
rows.Add(row);

Assert.That(rows, Is.Empty);
}

[Test]
public async Task ParseCpiPeriodAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.period.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "ParserData", "cu.period.sample");
var rows = new List<CpiPeriod>();

await foreach (var row in _parser.ParseCpiPeriodsAsync(path))
Expand All @@ -67,4 +67,4 @@ public async Task ParseCpiPeriodAsync_FileWithRecords_YieldsResults()
});
}

}
}
Loading
Loading