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
6 changes: 4 additions & 2 deletions EconDataLens.Tests/EconDataLens.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="Npgsql" Version="9.0.3" />
<PackageReference Include="NUnit" Version="4.2.2"/>
<PackageReference Include="NUnit.Analyzers" Version="4.4.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>
<PackageReference Include="Testcontainers.PostgreSql" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -31,9 +33,9 @@
</ItemGroup>

<ItemGroup>
<Content Include="Fixtures/**">
<Content Include="TestData/**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using EconDataLens.Services;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.Services;
namespace EconDataLens.Tests.EtlParserTests;

public class CpiAreaParserTests
{
Expand Down Expand Up @@ -35,7 +35,7 @@ public void SetUp()
[Test]
public async Task ParseCpiAreaAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.area.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.area.empty");

var rows = new List<CpiArea>();

Expand All @@ -48,7 +48,7 @@ public async Task ParseCpiAreaAsync_HeaderOnly_YieldsNoResults()
[Test]
public async Task ParseCpiAreaAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.area.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.area.sample");

var rows = new List<CpiArea>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Extensions.Options;


namespace EconDataLens.Tests.Services;
namespace EconDataLens.Tests.EtlParserTests;

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

await foreach (var row in _parser.ParseCpiDataAsync(path))
Expand All @@ -49,7 +49,7 @@ public async Task ParseCpiFootnoteAsync_HeaderOnly_YieldsNoResults()
[Test]
public async Task ParseCpiDataAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.data.0.Current.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.data.0.Current.sample");
var rows = new List<CpiData>();

await foreach (var row in _parser.ParseCpiDataAsync(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using EconDataLens.Services;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.Services;
namespace EconDataLens.Tests.EtlParserTests;

[TestFixture]
public class CpiFootnoteParserTests
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, "Fixtures", "cu.footnote.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "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, "Fixtures", "cu.footnote.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.footnote.sample");

// Act
var rows = new List<CpiFootnote>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using EconDataLens.Services;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.Services;
namespace EconDataLens.Tests.EtlParserTests;

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

await foreach (var row in _parser.ParseCpiItemsAsync(path))
Expand All @@ -47,7 +47,7 @@ public async Task ParseCpiItemAsync_HeaderOnly_YieldsNoResults()
[Test]
public async Task ParseCpiItemAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.item.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.item.sample");
var rows = new List<CpiItem>();

await foreach (var row in _parser.ParseCpiItemsAsync(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using EconDataLens.Services;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.Services;
namespace EconDataLens.Tests.EtlParserTests;

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

await foreach (var row in _parser.ParseCpiPeriodsAsync(path))
Expand All @@ -47,7 +47,7 @@ public async Task ParseCpiPeriodAsync_HeaderOnly_YieldsNoResults()
[Test]
public async Task ParseCpiPeriodAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.period.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.period.sample");
var rows = new List<CpiPeriod>();

await foreach (var row in _parser.ParseCpiPeriodsAsync(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using EconDataLens.Services;
using Microsoft.Extensions.Options;

namespace EconDataLens.Tests.Services;
namespace EconDataLens.Tests.EtlParserTests;

public class CpiSeriesParserTests
{
Expand Down Expand Up @@ -35,7 +35,7 @@ public void SetUp()
[Test]
public async Task ParseCpiSeriesAsync_HeaderOnly_YieldsNoResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.series.empty");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.series.empty");
var rows = new List<CpiSeries>();

await foreach (var row in _parser.ParseCpiSeriesAsync(path))
Expand All @@ -47,7 +47,7 @@ public async Task ParseCpiSeriesAsync_HeaderOnly_YieldsNoResults()
[Test]
public async Task ParseCpiSeriesAsync_FileWithRecords_YieldsResults()
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Fixtures", "cu.series.sample");
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "cu.series.sample");
var rows = new List<CpiSeries>();

await foreach (var row in _parser.ParseCpiSeriesAsync(path))
Expand Down
40 changes: 40 additions & 0 deletions EconDataLens.Tests/PostgresFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using EconDataLens.Data;
using Microsoft.EntityFrameworkCore;
using Testcontainers.PostgreSql;

namespace EconDataLens.Tests;

[SetUpFixture]
public class PostgresFixture
{
private PostgreSqlContainer _container = default!;
public static string ConnectionString { get; private set; } = string.Empty;

[OneTimeSetUp]
public async Task OneTimeSetUp()
{
_container = new PostgreSqlBuilder()
.WithImage("postgres:17-alpine")
.WithDatabase("econ_test")
.WithUsername("postgres")
.WithPassword("postgres")
.WithCleanUp(true)
.Build();

await _container.StartAsync();
ConnectionString = _container.GetConnectionString();

var options = new DbContextOptionsBuilder<EconDataLensDbContext>()
.UseNpgsql(ConnectionString)
.Options;

await using var ctx = new EconDataLensDbContext(options);
await ctx.Database.MigrateAsync();
}

[OneTimeTearDown]
public async Task OneTimeTearDown()
{
await _container.DisposeAsync();
}
}
36 changes: 36 additions & 0 deletions EconDataLens.Tests/Smoke/DbSmokeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using EconDataLens.Core.Entities.Cpi;
using EconDataLens.Data;

namespace EconDataLens.Tests.Smoke;

public class DbSmokeTests
{
private static EconDataLensDbContext CreateDb()
{
var opts = new DbContextOptionsBuilder<EconDataLensDbContext>()
.UseNpgsql(PostgresFixture.ConnectionString)
.UseSnakeCaseNamingConvention()
.Options;

return new EconDataLensDbContext(opts);
}

[Test]
public async Task Can_Migrate_And_Do_Basic_CRUD()
{
await using var db = CreateDb();

// Insert
db.CpiArea.Add(new CpiArea { AreaCode = "ZZZ0", AreaName = "Test Area" });
await db.SaveChangesAsync();

// Query
var found = await db.CpiArea.AsNoTracking().CountAsync(a => a.AreaCode == "ZZZ0");
Assert.That(found, Is.EqualTo(1));

// Cleanup (optional)
db.CpiArea.RemoveRange(db.CpiArea.Where(a => a.AreaCode == "ZZZ0"));
await db.SaveChangesAsync();
}
}
Loading