From 317b1b81b210f0b81e4a5723cbf90f3962a65343 Mon Sep 17 00:00:00 2001 From: Jaxel Rojas Date: Fri, 23 Aug 2024 08:35:54 -0400 Subject: [PATCH] tests: added exception unit tests --- tests/Unit/ExceptionTests.cs | 44 ++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/Unit/ExceptionTests.cs b/tests/Unit/ExceptionTests.cs index 05b1ace..be36f33 100644 --- a/tests/Unit/ExceptionTests.cs +++ b/tests/Unit/ExceptionTests.cs @@ -1,4 +1,5 @@ -using Minimig; +using System; +using Minimig; using MinimigTests.Fakes; using Xunit; @@ -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"; @@ -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); + } }