Skip to content

Commit

Permalink
tests: added exception unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxelr committed Aug 23, 2024
1 parent 01eb27e commit 317b1b8
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions tests/Unit/ExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Minimig;
using System;
using Minimig;
using MinimigTests.Fakes;
using Xunit;

Expand All @@ -8,7 +9,7 @@ public class ExceptionTests
{
[Theory]
[InlineData("SampleMigrations\\SqlServer\\0001 - Add One and Two tables.sql")]
public void Check_migration_exception(string filePath)
public void FakeMigration_ShouldHaveMigrationChangedException(string filePath)
{
//Arrange
const string modified = "has been modified since it was run";
Expand All @@ -21,4 +22,43 @@ public void Check_migration_exception(string filePath)
Assert.Contains(modified, exception.Message);
Assert.Contains(mig.Filename, exception.Message);
}

[Fact]
public void DefaultConstructor_ShouldHaveMessage()
{
// Arrange
const string message = "Exception of type 'Minimig.MigrationChangedException' was thrown.";

// Act
var exception = new MigrationChangedException();

// Assert
Assert.Equal(message, exception.Message);
}

[Theory]
[InlineData("Custom error message")]
public void Constructor_WithMessage_ShouldSetMessage(string message)
{
// Act
var exception = new MigrationChangedException(message);

// Assert
Assert.Equal(message, exception.Message);
}

[Theory]
[InlineData("Custom error message", "Inner exception message")]
public void Constructor_WithMessageAndInnerException_ShouldSetMessageAndInnerException(string message, string innerMessage)
{
// Arrange
var innerException = new Exception(innerMessage);

// Act
var exception = new MigrationChangedException(message, innerException);

// Assert
Assert.Equal(message, exception.Message);
Assert.Equal(innerException, exception.InnerException);
}
}

0 comments on commit 317b1b8

Please sign in to comment.