Skip to content

Commit d4dc4ba

Browse files
committed
Added ExceptionAssert to get a better error message when the exception message does not contain the expected message.
1 parent a025869 commit d4dc4ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+147
-119
lines changed

tests/Magick.NET.Tests/Coders/TheMapCoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void ShouldThrowExceptionWhenDimensionsNotSpecified(uint? width, uint? he
4242
using var image = new MagickImage();
4343

4444
var exception = Assert.Throws<MagickOptionErrorException>(() => image.Read(tempFile.File, settings));
45-
Assert.Contains("must specify image size", exception.Message);
45+
ExceptionAssert.Contains("must specify image size", exception);
4646
}
4747

4848
[Fact]
@@ -58,7 +58,7 @@ public void ShouldThrowExceptionWhenDepthNotSpecified()
5858
using var image = new MagickImage();
5959

6060
var exception = Assert.Throws<MagickOptionErrorException>(() => image.Read(tempFile.File, settings));
61-
Assert.Contains("must specify image depth", exception.Message);
61+
ExceptionAssert.Contains("must specify image depth", exception);
6262
}
6363

6464
[Fact]

tests/Magick.NET.Tests/Coders/TheTiffCoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void ShouldThrowExceptionWhenImageContainsInvalidTag()
1919

2020
var exception = Assert.Throws<MagickCoderErrorException>(() => image.Read(Files.Coders.IgnoreTagTIF));
2121

22-
Assert.Contains(@$"Null count for ""Tag {_tag}""", exception.Message);
22+
ExceptionAssert.Contains(@$"Null count for ""Tag {_tag}""", exception);
2323
}
2424

2525
[Fact]
@@ -31,7 +31,7 @@ public void ShouldIgnoreTheSpecifiedTags()
3131

3232
var settings = new MagickReadSettings(new TiffReadDefines
3333
{
34-
IgnoreTags = new string[] { _tag },
34+
IgnoreTags = [_tag],
3535
});
3636

3737
image.Settings.RemoveDefine(MagickFormat.Tiff, "ignore-tags");

tests/Magick.NET.Tests/Formats/Bmp/BmpReadDefinesTests/TheIgnoreFileSizeProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void ShouldNotAllowReadingBmpWithInvalidFileSizeByDefault()
6262
image.Settings.SetDefines(defines);
6363

6464
var exception = Assert.Throws<MagickCorruptImageErrorException>(() => image.Read(Files.Coders.InvalidCrcBMP));
65-
Assert.Contains("length and filesize do not match", exception.Message);
65+
ExceptionAssert.Contains("length and filesize do not match", exception);
6666
}
6767
}
6868
}

tests/Magick.NET.Tests/Formats/Pdf/PdfInfoTests/TheCreateMethod.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public void ShouldThrowExceptionWhenFileIsPng()
7474

7575
if (exception is MagickDelegateErrorException delegateErrorException)
7676
{
77-
Assert.Single(exception.RelatedExceptions);
78-
Assert.Contains("Error: /syntaxerror in pdfopen", exception.RelatedExceptions.First().Message);
77+
Assert.Single(delegateErrorException.RelatedExceptions);
78+
ExceptionAssert.Contains("Error: /syntaxerror in pdfopen", delegateErrorException);
7979
}
8080
else
8181
{
82-
Assert.Contains("Unable to determine the page count.", exception.Message);
82+
ExceptionAssert.Contains("Unable to determine the page count.", exception);
8383
}
8484
}
8585
}

tests/Magick.NET.Tests/Formats/Pdf/PdfReadDefinesTests/ThePasswordProperty.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ public void ShouldNotBeAbleToOpenFileWithNullPassword()
7676
}
7777
catch (MagickDelegateErrorException exception)
7878
{
79-
var message = exception.Message;
80-
81-
var relatedException = exception.RelatedExceptions.FirstOrDefault();
82-
if (relatedException is not null)
83-
message += relatedException.Message;
84-
85-
Assert.Contains("This file requires a password for access.", message);
79+
ExceptionAssert.Contains("This file requires a password for access.", exception);
8680
return;
8781
}
8882

tests/Magick.NET.Tests/Helpers/StreamWrapperTests/TheCreateForReadingMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void ShouldThrowExceptionWhenStreamIsNotReadable()
1717
using var stream = TestStream.ThatCannotRead();
1818

1919
var exception = Assert.Throws<ArgumentException>("stream", () => StreamWrapper.CreateForReading(stream));
20-
Assert.Contains("readable", exception.Message);
20+
ExceptionAssert.Contains("readable", exception);
2121
}
2222

2323
[Fact]

tests/Magick.NET.Tests/Helpers/StreamWrapperTests/TheCreateForWritingMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void ShouldThrowExceptionWhenStreamIsNotWritable()
1717
using var stream = TestStream.ThatCannotWrite();
1818

1919
var exception = Assert.Throws<ArgumentException>("stream", () => StreamWrapper.CreateForWriting(stream));
20-
Assert.Contains("writable", exception.Message);
20+
ExceptionAssert.Contains("writable", exception);
2121
}
2222

2323
[Fact]

tests/Magick.NET.Tests/MagickImageCollectionTests/TheAddRangeMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void ShouldThrowExceptionWhenInvalid()
159159
using var images = new MagickImageCollection();
160160
var exception = Assert.Throws<MagickBlobErrorException>(() => images.Add(Files.Missing));
161161

162-
Assert.Contains("error/blob.c/OpenBlob", exception.Message);
162+
ExceptionAssert.Contains("error/blob.c/OpenBlob", exception);
163163
}
164164

165165
[Fact]

tests/Magick.NET.Tests/MagickImageCollectionTests/TheConstructor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public void ShouldThrowExceptionWhenFileNameIsInvalid()
239239
{
240240
var exception = Assert.Throws<MagickBlobErrorException>(() => new MagickImageCollection(Files.Missing));
241241

242-
Assert.Contains("error/blob.c/OpenBlob", exception.Message);
242+
ExceptionAssert.Contains("error/blob.c/OpenBlob", exception);
243243
}
244244

245245
[Fact]

tests/Magick.NET.Tests/MagickImageCollectionTests/ThePingMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void ShouldThrowExceptionWhenFileNameIsInvalid()
210210
using var images = new MagickImageCollection();
211211

212212
var exception = Assert.Throws<MagickBlobErrorException>(() => images.Ping(Files.Missing));
213-
Assert.Contains("error/blob.c/OpenBlob", exception.Message);
213+
ExceptionAssert.Contains("error/blob.c/OpenBlob", exception);
214214
}
215215

216216
[Fact]

0 commit comments

Comments
 (0)