|
1 | 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. |
2 | 2 | // Licensed under the Apache License, Version 2.0. |
3 | 3 |
|
4 | | -using System.Linq; |
5 | 4 | using ImageMagick; |
6 | 5 | using ImageMagick.Formats; |
7 | 6 | using Xunit; |
8 | 7 | using Xunit.Sdk; |
9 | 8 |
|
10 | 9 | namespace Magick.NET.Tests; |
11 | 10 |
|
| 11 | +[Collection(nameof(IsolatedUnitTest))] |
12 | 12 | public partial class PdfReadDefinesTests |
13 | 13 | { |
14 | 14 | public class ThePasswordProperty |
15 | 15 | { |
16 | 16 | [Fact] |
17 | 17 | public void ShouldSetTheDefineWhenValueIsSet() |
18 | 18 | { |
19 | | - using var image = new MagickImage(MagickColors.Magenta, 1, 1); |
20 | | - image.Settings.SetDefines(new PdfReadDefines |
| 19 | + IsolatedUnitTest.Execute(static () => |
21 | 20 | { |
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 | + }); |
24 | 26 |
|
25 | | - Assert.Equal("test", image.Settings.GetDefine("authenticate")); |
| 27 | + Assert.Equal("test", image.Settings.GetDefine("authenticate")); |
| 28 | + }); |
26 | 29 | } |
27 | 30 |
|
28 | 31 | [Fact] |
29 | 32 | public void ShouldNotSetTheDefineWhenValueIsNotSet() |
30 | 33 | { |
31 | | - using var image = new MagickImage(); |
32 | | - image.Settings.SetDefines(new PdfReadDefines |
| 34 | + IsolatedUnitTest.Execute(static () => |
33 | 35 | { |
34 | | - Password = null, |
35 | | - }); |
| 36 | + using var image = new MagickImage(); |
| 37 | + image.Settings.SetDefines(new PdfReadDefines |
| 38 | + { |
| 39 | + Password = null, |
| 40 | + }); |
36 | 41 |
|
37 | | - Assert.Null(image.Settings.GetDefine("authenticate")); |
| 42 | + Assert.Null(image.Settings.GetDefine("authenticate")); |
| 43 | + }); |
38 | 44 | } |
39 | 45 |
|
40 | 46 | [Fact] |
41 | 47 | public void ShouldUseThePasswordToReadTheImage() |
42 | 48 | { |
43 | 49 | Assert.SkipUnless(Ghostscript.IsAvailable, "Ghostscript is not available"); |
44 | 50 |
|
45 | | - var settings = new MagickReadSettings |
| 51 | + IsolatedUnitTest.Execute(static () => |
46 | 52 | { |
47 | | - Defines = new PdfReadDefines |
| 53 | + var settings = new MagickReadSettings |
48 | 54 | { |
49 | | - Password = "test", |
50 | | - }, |
51 | | - }; |
| 55 | + Defines = new PdfReadDefines |
| 56 | + { |
| 57 | + Password = "test", |
| 58 | + }, |
| 59 | + }; |
52 | 60 |
|
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); |
55 | 63 |
|
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 | + }); |
58 | 67 | } |
59 | 68 |
|
60 | 69 | [Fact] |
61 | 70 | public void ShouldNotBeAbleToOpenFileWithNullPassword() |
62 | 71 | { |
63 | 72 | Assert.SkipUnless(Ghostscript.IsAvailable, "Ghostscript is not available"); |
64 | 73 |
|
65 | | - var settings = new MagickReadSettings |
| 74 | + IsolatedUnitTest.Execute(static () => |
66 | 75 | { |
67 | | - Defines = new PdfReadDefines |
| 76 | + var settings = new MagickReadSettings |
68 | 77 | { |
69 | | - Password = null, |
70 | | - }, |
71 | | - }; |
| 78 | + Defines = new PdfReadDefines |
| 79 | + { |
| 80 | + Password = null, |
| 81 | + }, |
| 82 | + }; |
72 | 83 |
|
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 | + { |
80 | 91 | #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); |
82 | 93 | #else |
83 | 94 | ExceptionAssert.Contains("Error: Couldn't initialise file.", exception); |
84 | 95 | #endif |
85 | | - return; |
86 | | - } |
| 96 | + return; |
| 97 | + } |
87 | 98 |
|
88 | | - throw new XunitException("Exception should be thrown."); |
| 99 | + throw new XunitException("Exception should be thrown."); |
| 100 | + }); |
89 | 101 | } |
90 | 102 | } |
91 | 103 | } |
0 commit comments