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
1 change: 1 addition & 0 deletions EconDataLens.Tests/Fixtures/cu.period.empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
period period_abbr period_name
3 changes: 3 additions & 0 deletions EconDataLens.Tests/Fixtures/cu.period.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
period period_abbr period_name
M01 JAN January
S03 AN AV Annual Average
70 changes: 70 additions & 0 deletions EconDataLens.Tests/Services/CpiPeriodParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using EconDataLens.Core.Configuration;
using EconDataLens.Core.Interfaces;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Services;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.Services;

public class CpiPeriodParserTests
{
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 ParseCpiPeriodAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "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, "Fixtures", "cu.period.sample");
var rows = new List<CpiPeriod>();

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

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

Assert.Multiple(() =>
{
Assert.That(rows[0].Period, Is.EqualTo("M01"));
Assert.That(rows[0].PeriodAbbreviation, Is.EqualTo("JAN"));
Assert.That(rows[0].PeriodName, Is.EqualTo("January"));

Assert.That(rows[1].Period, Is.EqualTo("S03"));
Assert.That(rows[1].PeriodAbbreviation, Is.EqualTo("AN AV"));
Assert.That(rows[1].PeriodName, Is.EqualTo("Annual Average"));
});
}

}
Loading