Skip to content

Commit 924c41f

Browse files
committed
Also run the PdfReadDefinesTests as an isolated unit test.
1 parent 90c8496 commit 924c41f

File tree

1 file changed

+48
-36
lines changed

1 file changed

+48
-36
lines changed
Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,103 @@
11
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System.Linq;
54
using ImageMagick;
65
using ImageMagick.Formats;
76
using Xunit;
87
using Xunit.Sdk;
98

109
namespace Magick.NET.Tests;
1110

11+
[Collection(nameof(IsolatedUnitTest))]
1212
public partial class PdfReadDefinesTests
1313
{
1414
public class ThePasswordProperty
1515
{
1616
[Fact]
1717
public void ShouldSetTheDefineWhenValueIsSet()
1818
{
19-
using var image = new MagickImage(MagickColors.Magenta, 1, 1);
20-
image.Settings.SetDefines(new PdfReadDefines
19+
IsolatedUnitTest.Execute(static () =>
2120
{
22-
Password = "test",
23-
});
21+
using var image = new MagickImage(MagickColors.Magenta, 1, 1);
22+
image.Settings.SetDefines(new PdfReadDefines
23+
{
24+
Password = "test",
25+
});
2426

25-
Assert.Equal("test", image.Settings.GetDefine("authenticate"));
27+
Assert.Equal("test", image.Settings.GetDefine("authenticate"));
28+
});
2629
}
2730

2831
[Fact]
2932
public void ShouldNotSetTheDefineWhenValueIsNotSet()
3033
{
31-
using var image = new MagickImage();
32-
image.Settings.SetDefines(new PdfReadDefines
34+
IsolatedUnitTest.Execute(static () =>
3335
{
34-
Password = null,
35-
});
36+
using var image = new MagickImage();
37+
image.Settings.SetDefines(new PdfReadDefines
38+
{
39+
Password = null,
40+
});
3641

37-
Assert.Null(image.Settings.GetDefine("authenticate"));
42+
Assert.Null(image.Settings.GetDefine("authenticate"));
43+
});
3844
}
3945

4046
[Fact]
4147
public void ShouldUseThePasswordToReadTheImage()
4248
{
4349
Assert.SkipUnless(Ghostscript.IsAvailable, "Ghostscript is not available");
4450

45-
var settings = new MagickReadSettings
51+
IsolatedUnitTest.Execute(static () =>
4652
{
47-
Defines = new PdfReadDefines
53+
var settings = new MagickReadSettings
4854
{
49-
Password = "test",
50-
},
51-
};
55+
Defines = new PdfReadDefines
56+
{
57+
Password = "test",
58+
},
59+
};
5260

53-
using var image = new MagickImage();
54-
image.Read(Files.Coders.PdfExamplePasswordOriginalPDF, settings);
61+
using var image = new MagickImage();
62+
image.Read(Files.Coders.PdfExamplePasswordOriginalPDF, settings);
5563

56-
Assert.Equal(612U, image.Width);
57-
Assert.Equal(792U, image.Height);
64+
Assert.Equal(612U, image.Width);
65+
Assert.Equal(792U, image.Height);
66+
});
5867
}
5968

6069
[Fact]
6170
public void ShouldNotBeAbleToOpenFileWithNullPassword()
6271
{
6372
Assert.SkipUnless(Ghostscript.IsAvailable, "Ghostscript is not available");
6473

65-
var settings = new MagickReadSettings
74+
IsolatedUnitTest.Execute(static () =>
6675
{
67-
Defines = new PdfReadDefines
76+
var settings = new MagickReadSettings
6877
{
69-
Password = null,
70-
},
71-
};
78+
Defines = new PdfReadDefines
79+
{
80+
Password = null,
81+
},
82+
};
7283

73-
using var image = new MagickImage();
74-
try
75-
{
76-
image.Read(Files.Coders.PdfExamplePasswordOriginalPDF, settings);
77-
}
78-
catch (MagickDelegateErrorException exception)
79-
{
84+
using var image = new MagickImage();
85+
try
86+
{
87+
image.Read(Files.Coders.PdfExamplePasswordOriginalPDF, settings);
88+
}
89+
catch (MagickDelegateErrorException exception)
90+
{
8091
#if WINDOWS_BUILD
81-
ExceptionAssert.Contains("This file requires a password for access.", exception);
92+
ExceptionAssert.Contains("This file requires a password for access.", exception);
8293
#else
8394
ExceptionAssert.Contains("Error: Couldn't initialise file.", exception);
8495
#endif
85-
return;
86-
}
96+
return;
97+
}
8798

88-
throw new XunitException("Exception should be thrown.");
99+
throw new XunitException("Exception should be thrown.");
100+
});
89101
}
90102
}
91103
}

0 commit comments

Comments
 (0)