1 // ****************************************************************
\r
2 // This is free software licensed under the NUnit license. You
\r
3 // may obtain a copy of the license as well as information regarding
\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.
\r
5 // ****************************************************************
\r
9 using System.ComponentModel;
\r
10 using NUnit.Framework.Constraints;
\r
12 namespace NUnit.Framework
\r
15 /// Summary description for FileAssert.
\r
17 public class FileAssert
\r
19 #region Equals and ReferenceEquals
\r
22 /// The Equals method throws an AssertionException. This is done
\r
23 /// to make sure there is no mistake by calling this function.
\r
25 /// <param name="a"></param>
\r
26 /// <param name="b"></param>
\r
27 [EditorBrowsable(EditorBrowsableState.Never)]
\r
28 public static new bool Equals(object a, object b)
\r
30 throw new AssertionException("Assert.Equals should not be used for Assertions");
\r
34 /// override the default ReferenceEquals to throw an AssertionException. This
\r
35 /// implementation makes sure there is no mistake in calling this function
\r
36 /// as part of Assert.
\r
38 /// <param name="a"></param>
\r
39 /// <param name="b"></param>
\r
40 public static new void ReferenceEquals(object a, object b)
\r
42 throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");
\r
50 /// We don't actually want any instances of this object, but some people
\r
51 /// like to inherit from it to add other static methods. Hence, the
\r
52 /// protected constructor disallows any instances of this object.
\r
54 protected FileAssert() {}
\r
63 /// Verifies that two Streams are equal. Two Streams are considered
\r
64 /// equal if both are null, or if both have the same value byte for byte.
\r
65 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
67 /// <param name="expected">The expected Stream</param>
\r
68 /// <param name="actual">The actual Stream</param>
\r
69 /// <param name="message">The message to display if Streams are not equal</param>
\r
70 /// <param name="args">Arguments to be used in formatting the message</param>
\r
71 static public void AreEqual(Stream expected, Stream actual, string message, params object[] args)
\r
73 Assert.That( actual, new EqualConstraint( expected ), message, args );
\r
77 /// Verifies that two Streams are equal. Two Streams are considered
\r
78 /// equal if both are null, or if both have the same value byte for byte.
\r
79 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
81 /// <param name="expected">The expected Stream</param>
\r
82 /// <param name="actual">The actual Stream</param>
\r
83 /// <param name="message">The message to display if objects are not equal</param>
\r
84 static public void AreEqual(Stream expected, Stream actual, string message)
\r
86 AreEqual(expected, actual, message, null);
\r
90 /// Verifies that two Streams are equal. Two Streams are considered
\r
91 /// equal if both are null, or if both have the same value byte for byte.
\r
92 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
94 /// <param name="expected">The expected Stream</param>
\r
95 /// <param name="actual">The actual Stream</param>
\r
96 static public void AreEqual(Stream expected, Stream actual)
\r
98 AreEqual(expected, actual, string.Empty, null);
\r
105 /// Verifies that two files are equal. Two files are considered
\r
106 /// equal if both are null, or if both have the same value byte for byte.
\r
107 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
109 /// <param name="expected">A file containing the value that is expected</param>
\r
110 /// <param name="actual">A file containing the actual value</param>
\r
111 /// <param name="message">The message to display if Streams are not equal</param>
\r
112 /// <param name="args">Arguments to be used in formatting the message</param>
\r
113 static public void AreEqual(FileInfo expected, FileInfo actual, string message, params object[] args)
\r
115 using (FileStream exStream = expected.OpenRead())
\r
117 using (FileStream acStream = actual.OpenRead())
\r
119 AreEqual(exStream,acStream,message,args);
\r
125 /// Verifies that two files are equal. Two files are considered
\r
126 /// equal if both are null, or if both have the same value byte for byte.
\r
127 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
129 /// <param name="expected">A file containing the value that is expected</param>
\r
130 /// <param name="actual">A file containing the actual value</param>
\r
131 /// <param name="message">The message to display if objects are not equal</param>
\r
132 static public void AreEqual(FileInfo expected, FileInfo actual, string message)
\r
134 AreEqual(expected, actual, message, null);
\r
138 /// Verifies that two files are equal. Two files are considered
\r
139 /// equal if both are null, or if both have the same value byte for byte.
\r
140 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
142 /// <param name="expected">A file containing the value that is expected</param>
\r
143 /// <param name="actual">A file containing the actual value</param>
\r
144 static public void AreEqual(FileInfo expected, FileInfo actual)
\r
146 AreEqual(expected, actual, string.Empty, null);
\r
153 /// Verifies that two files are equal. Two files are considered
\r
154 /// equal if both are null, or if both have the same value byte for byte.
\r
155 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
157 /// <param name="expected">The path to a file containing the value that is expected</param>
\r
158 /// <param name="actual">The path to a file containing the actual value</param>
\r
159 /// <param name="message">The message to display if Streams are not equal</param>
\r
160 /// <param name="args">Arguments to be used in formatting the message</param>
\r
161 static public void AreEqual(string expected, string actual, string message, params object[] args)
\r
163 using (FileStream exStream = File.OpenRead(expected))
\r
165 using (FileStream acStream = File.OpenRead(actual))
\r
167 AreEqual(exStream,acStream,message,args);
\r
173 /// Verifies that two files are equal. Two files are considered
\r
174 /// equal if both are null, or if both have the same value byte for byte.
\r
175 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
177 /// <param name="expected">The path to a file containing the value that is expected</param>
\r
178 /// <param name="actual">The path to a file containing the actual value</param>
\r
179 /// <param name="message">The message to display if objects are not equal</param>
\r
180 static public void AreEqual(string expected, string actual, string message)
\r
182 AreEqual(expected, actual, message, null);
\r
186 /// Verifies that two files are equal. Two files are considered
\r
187 /// equal if both are null, or if both have the same value byte for byte.
\r
188 /// If they are not equal an <see cref="AssertionException"/> is thrown.
\r
190 /// <param name="expected">The path to a file containing the value that is expected</param>
\r
191 /// <param name="actual">The path to a file containing the actual value</param>
\r
192 static public void AreEqual(string expected, string actual)
\r
194 AreEqual(expected, actual, string.Empty, null);
\r
201 #region AreNotEqual
\r
205 /// Asserts that two Streams are not equal. If they are equal
\r
206 /// an <see cref="AssertionException"/> is thrown.
\r
208 /// <param name="expected">The expected Stream</param>
\r
209 /// <param name="actual">The actual Stream</param>
\r
210 /// <param name="message">The message to be displayed when the two Stream are the same.</param>
\r
211 /// <param name="args">Arguments to be used in formatting the message</param>
\r
212 static public void AreNotEqual( Stream expected, Stream actual, string message, params object[] args)
\r
214 Assert.That( actual, new NotConstraint( new EqualConstraint( expected ) ), message, args );
\r
218 /// Asserts that two Streams are not equal. If they are equal
\r
219 /// an <see cref="AssertionException"/> is thrown.
\r
221 /// <param name="expected">The expected Stream</param>
\r
222 /// <param name="actual">The actual Stream</param>
\r
223 /// <param name="message">The message to be displayed when the Streams are the same.</param>
\r
224 static public void AreNotEqual(Stream expected, Stream actual, string message)
\r
226 AreNotEqual(expected, actual, message, null);
\r
230 /// Asserts that two Streams are not equal. If they are equal
\r
231 /// an <see cref="AssertionException"/> is thrown.
\r
233 /// <param name="expected">The expected Stream</param>
\r
234 /// <param name="actual">The actual Stream</param>
\r
235 static public void AreNotEqual(Stream expected, Stream actual)
\r
237 AreNotEqual(expected, actual, string.Empty, null);
\r
243 /// Asserts that two files are not equal. If they are equal
\r
244 /// an <see cref="AssertionException"/> is thrown.
\r
246 /// <param name="expected">A file containing the value that is expected</param>
\r
247 /// <param name="actual">A file containing the actual value</param>
\r
248 /// <param name="message">The message to display if Streams are not equal</param>
\r
249 /// <param name="args">Arguments to be used in formatting the message</param>
\r
250 static public void AreNotEqual(FileInfo expected, FileInfo actual, string message, params object[] args)
\r
252 using (FileStream exStream = expected.OpenRead())
\r
254 using (FileStream acStream = actual.OpenRead())
\r
256 AreNotEqual(exStream,acStream,message,args);
\r
262 /// Asserts that two files are not equal. If they are equal
\r
263 /// an <see cref="AssertionException"/> is thrown.
\r
265 /// <param name="expected">A file containing the value that is expected</param>
\r
266 /// <param name="actual">A file containing the actual value</param>
\r
267 /// <param name="message">The message to display if objects are not equal</param>
\r
268 static public void AreNotEqual(FileInfo expected, FileInfo actual, string message)
\r
270 AreNotEqual(expected, actual, message, null);
\r
274 /// Asserts that two files are not equal. If they are equal
\r
275 /// an <see cref="AssertionException"/> is thrown.
\r
277 /// <param name="expected">A file containing the value that is expected</param>
\r
278 /// <param name="actual">A file containing the actual value</param>
\r
279 static public void AreNotEqual(FileInfo expected, FileInfo actual)
\r
281 AreNotEqual(expected, actual, string.Empty, null);
\r
288 /// Asserts that two files are not equal. If they are equal
\r
289 /// an <see cref="AssertionException"/> is thrown.
\r
291 /// <param name="expected">The path to a file containing the value that is expected</param>
\r
292 /// <param name="actual">The path to a file containing the actual value</param>
\r
293 /// <param name="message">The message to display if Streams are not equal</param>
\r
294 /// <param name="args">Arguments to be used in formatting the message</param>
\r
295 static public void AreNotEqual(string expected, string actual, string message, params object[] args)
\r
297 using (FileStream exStream = File.OpenRead(expected))
\r
299 using (FileStream acStream = File.OpenRead(actual))
\r
301 AreNotEqual(exStream,acStream,message,args);
\r
307 /// Asserts that two files are not equal. If they are equal
\r
308 /// an <see cref="AssertionException"/> is thrown.
\r
310 /// <param name="expected">The path to a file containing the value that is expected</param>
\r
311 /// <param name="actual">The path to a file containing the actual value</param>
\r
312 /// <param name="message">The message to display if objects are not equal</param>
\r
313 static public void AreNotEqual(string expected, string actual, string message)
\r
315 AreNotEqual(expected, actual, message, null);
\r
319 /// Asserts that two files are not equal. If they are equal
\r
320 /// an <see cref="AssertionException"/> is thrown.
\r
322 /// <param name="expected">The path to a file containing the value that is expected</param>
\r
323 /// <param name="actual">The path to a file containing the actual value</param>
\r
324 static public void AreNotEqual(string expected, string actual)
\r
326 AreNotEqual(expected, actual, string.Empty, null);
\r