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() .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() .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(); } 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() .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(); } }