Added migration tool

This commit is contained in:
Marius
2026-03-12 09:47:49 +02:00
parent 27648ae57c
commit b262d10ea4
35 changed files with 2579 additions and 2 deletions
@@ -0,0 +1,200 @@
using FluentAssertions;
using HaDbMigration.Configuration;
namespace HaDbMigration.Tests;
public sealed class MigrationOptionsTests
{
[Fact]
public void Validate_WithValidOptions_ShouldNotThrow()
{
// Arrange
var tempFile = Path.GetTempFileName();
try
{
var options = new MigrationOptions
{
SqlitePath = tempFile,
PostgresConnectionString = "Host=localhost;Database=test",
BatchSize = 10_000,
};
// Act
var act = () => options.Validate();
// Assert
act.Should().NotThrow();
}
finally
{
File.Delete(tempFile);
}
}
[Fact]
public void Validate_WithMissingSqliteFile_ShouldThrowFileNotFoundException()
{
// Arrange
var options = new MigrationOptions
{
SqlitePath = @"C:\nonexistent\path\db.sqlite",
PostgresConnectionString = "Host=localhost;Database=test",
};
// Act
var act = () => options.Validate();
// Assert
act.Should().Throw<FileNotFoundException>()
.WithMessage("*nonexistent*");
}
[Fact]
public void Validate_WithEmptyPostgresConnectionString_ShouldThrowArgumentException()
{
// Arrange
var tempFile = Path.GetTempFileName();
try
{
var options = new MigrationOptions
{
SqlitePath = tempFile,
PostgresConnectionString = "",
};
// Act
var act = () => options.Validate();
// Assert
act.Should().Throw<ArgumentException>()
.WithMessage("*connection string*");
}
finally
{
File.Delete(tempFile);
}
}
[Fact]
public void Validate_WithWhitespacePostgresConnectionString_ShouldThrowArgumentException()
{
// Arrange
var tempFile = Path.GetTempFileName();
try
{
var options = new MigrationOptions
{
SqlitePath = tempFile,
PostgresConnectionString = " ",
};
// Act
var act = () => options.Validate();
// Assert
act.Should().Throw<ArgumentException>();
}
finally
{
File.Delete(tempFile);
}
}
[Theory]
[InlineData(0)] // below minimum
[InlineData(50)] // below minimum
[InlineData(99)] // just below threshold
public void Validate_WithBatchSizeBelowMinimum_ShouldThrowArgumentOutOfRangeException(int batchSize)
{
// Arrange
var tempFile = Path.GetTempFileName();
try
{
var options = new MigrationOptions
{
SqlitePath = tempFile,
PostgresConnectionString = "Host=localhost;Database=test",
BatchSize = batchSize,
};
// Act
var act = () => options.Validate();
// Assert
act.Should().Throw<ArgumentOutOfRangeException>()
.WithMessage("*at least 100*");
}
finally
{
File.Delete(tempFile);
}
}
[Fact]
public void Validate_WithBatchSizeAtMinimum_ShouldNotThrow()
{
// Arrange
var tempFile = Path.GetTempFileName();
try
{
var options = new MigrationOptions
{
SqlitePath = tempFile,
PostgresConnectionString = "Host=localhost;Database=test",
BatchSize = 100,
};
// Act
var act = () => options.Validate();
// Assert
act.Should().NotThrow();
}
finally
{
File.Delete(tempFile);
}
}
[Fact]
public void DefaultBatchSize_ShouldBe10000()
{
// Arrange & Act
var options = new MigrationOptions
{
SqlitePath = "test.db",
PostgresConnectionString = "Host=localhost",
};
// Assert
options.BatchSize.Should().Be(10_000);
}
[Fact]
public void DefaultDryRun_ShouldBeFalse()
{
// Arrange & Act
var options = new MigrationOptions
{
SqlitePath = "test.db",
PostgresConnectionString = "Host=localhost",
};
// Assert
options.DryRun.Should().BeFalse();
}
[Fact]
public void DefaultTruncate_ShouldBeFalse()
{
// Arrange & Act
var options = new MigrationOptions
{
SqlitePath = "test.db",
PostgresConnectionString = "Host=localhost",
};
// Assert
options.Truncate.Should().BeFalse();
}
}