~a-schlapsi/nunit-3.0/linux-makefile

« back to all changes in this revision

Viewing changes to src/tests/Attributes/ExpectedExceptionTests.cs

  • Committer: Andreas Schlapsi
  • Date: 2010-01-23 23:14:05 UTC
  • mfrom: (18.1.137 work)
  • Revision ID: a.schlapsi@gmx.at-20100123231405-17deqoh18nfnbq1j
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
using System;
25
25
using System.Reflection;
26
26
using System.Runtime.Serialization;
27
 
using NUnit.Framework;
 
27
using NUnit.Framework.Api;
 
28
using NUnit.Framework.Internal;
28
29
using NUnit.TestUtilities;
29
30
using NUnit.TestData.ExpectedExceptionData;
30
31
 
31
 
namespace NUnit.Core.Tests
 
32
namespace NUnit.Framework.Attributes
32
33
{
33
34
        /// <summary>
34
35
        /// 
145
146
                {
146
147
                        Type fixtureType = typeof(BaseException);
147
148
                        Test test = TestBuilder.MakeTestCase( fixtureType, "BaseExceptionTest" );
148
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
149
 
                        Assert.IsTrue(result.IsFailure, "BaseExceptionTest should have failed");
 
149
            TestResult result = test.Run(TestListener.NULL);
 
150
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "BaseExceptionTest should have failed");
150
151
                        StringAssert.StartsWith(
151
152
                                "An unexpected exception type was thrown" + Environment.NewLine +
152
153
                                "Expected: System.ArgumentException" + Environment.NewLine +
159
160
                {
160
161
                        Type fixtureType = typeof(DerivedException);
161
162
                        Test test = TestBuilder.MakeTestCase( fixtureType, "DerivedExceptionTest" );
162
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
163
 
                        Assert.IsTrue(result.IsFailure, "DerivedExceptionTest should have failed");
 
163
            TestResult result = test.Run(TestListener.NULL);
 
164
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "DerivedExceptionTest should have failed");
164
165
                        StringAssert.StartsWith( 
165
166
                                "An unexpected exception type was thrown" + Environment.NewLine +
166
167
                                "Expected: System.Exception" + Environment.NewLine +
173
174
        {
174
175
            Type fixtureType = typeof(MismatchedException);
175
176
            Test test = TestBuilder.MakeTestCase(fixtureType, "MismatchedExceptionType");
176
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
177
 
            Assert.IsTrue(result.IsFailure, "MismatchedExceptionType should have failed");
 
177
            TestResult result = test.Run(TestListener.NULL);
 
178
            Assert.IsTrue(result.ResultState == ResultState.Failure, "MismatchedExceptionType should have failed");
178
179
            StringAssert.StartsWith(
179
180
                "An unexpected exception type was thrown" + Environment.NewLine +
180
181
                "Expected: System.ArgumentException" + Environment.NewLine +
187
188
        {
188
189
            Type fixtureType = typeof(MismatchedException);
189
190
            Test test = TestBuilder.MakeTestCase(fixtureType, "MismatchedExceptionTypeAsNamedParameter");
190
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
191
 
            Assert.IsTrue(result.IsFailure, "MismatchedExceptionType should have failed");
 
191
            TestResult result = test.Run(TestListener.NULL);
 
192
            Assert.IsTrue(result.ResultState == ResultState.Failure, "MismatchedExceptionType should have failed");
192
193
            StringAssert.StartsWith(
193
194
                "An unexpected exception type was thrown" + Environment.NewLine +
194
195
                "Expected: System.ArgumentException" + Environment.NewLine +
201
202
                {
202
203
                        Type fixtureType = typeof(MismatchedException);
203
204
                        Test test = TestBuilder.MakeTestCase( fixtureType, "MismatchedExceptionTypeWithUserMessage" );
204
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
205
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
205
            TestResult result = test.Run(TestListener.NULL);
 
206
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
206
207
                        StringAssert.StartsWith(
207
208
                                "custom message" + Environment.NewLine +
208
209
                                "An unexpected exception type was thrown" + Environment.NewLine +
216
217
                {
217
218
                        Type fixtureType = typeof(MismatchedException);
218
219
                        Test test = TestBuilder.MakeTestCase( fixtureType, "MismatchedExceptionName" );
219
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
220
 
                        Assert.IsTrue(result.IsFailure, "MismatchedExceptionName should have failed");
 
220
            TestResult result = test.Run(TestListener.NULL);
 
221
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "MismatchedExceptionName should have failed");
221
222
                        StringAssert.StartsWith(
222
223
                                "An unexpected exception type was thrown" + Environment.NewLine +
223
224
                                "Expected: System.ArgumentException" + Environment.NewLine +
230
231
                {
231
232
                        Type fixtureType = typeof(MismatchedException);
232
233
                        Test test = TestBuilder.MakeTestCase( fixtureType, "MismatchedExceptionNameWithUserMessage" );
233
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
234
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
234
            TestResult result = test.Run(TestListener.NULL);
 
235
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
235
236
                        StringAssert.StartsWith(
236
237
                                "custom message" + Environment.NewLine +
237
238
                                "An unexpected exception type was thrown" + Environment.NewLine +
245
246
                {
246
247
                        Type fixtureType = typeof(TestThrowsExceptionWithWrongMessage);
247
248
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestThrow" );
248
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
249
 
                        Assert.IsTrue(result.IsFailure, "TestThrow should have failed");
 
249
            TestResult result = test.Run(TestListener.NULL);
 
250
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "TestThrow should have failed");
250
251
                        Assert.AreEqual(
251
252
                                "The exception message text was incorrect" + Environment.NewLine +
252
253
                                "Expected: not the message" + Environment.NewLine +
259
260
                {
260
261
                        Type fixtureType = typeof(TestThrowsExceptionWithWrongMessage);
261
262
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestThrowWithUserMessage" );
262
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
263
 
                        Assert.IsTrue(result.IsFailure, "TestThrow should have failed");
 
263
            TestResult result = test.Run(TestListener.NULL);
 
264
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "TestThrow should have failed");
264
265
                        Assert.AreEqual(
265
266
                                "custom message" + Environment.NewLine +
266
267
                                "The exception message text was incorrect" + Environment.NewLine +
274
275
                {
275
276
                        Type fixtureType = typeof(TestDoesNotThrowExceptionFixture);
276
277
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestDoesNotThrowUnspecifiedException" );
277
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
278
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
278
            TestResult result = test.Run(TestListener.NULL);
 
279
                        Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
279
280
                        Assert.AreEqual("An Exception was expected", result.Message);
280
281
                }
281
282
 
284
285
                {
285
286
                        Type fixtureType = typeof(TestDoesNotThrowExceptionFixture);
286
287
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestDoesNotThrowUnspecifiedExceptionWithUserMessage" );
287
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
288
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
288
            TestResult result = test.Run(TestListener.NULL);
 
289
            Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
289
290
                        Assert.AreEqual("custom message" + Environment.NewLine + "An Exception was expected", result.Message);
290
291
                }
291
292
 
294
295
                {
295
296
                        Type fixtureType = typeof(TestDoesNotThrowExceptionFixture);
296
297
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestDoesNotThrowExceptionType" );
297
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
298
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
298
            TestResult result = test.Run(TestListener.NULL);
 
299
            Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
299
300
                        Assert.AreEqual("System.ArgumentException was expected", result.Message);
300
301
                }
301
302
 
304
305
                {
305
306
                        Type fixtureType = typeof(TestDoesNotThrowExceptionFixture);
306
307
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestDoesNotThrowExceptionTypeWithUserMessage" );
307
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
308
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
308
            TestResult result = test.Run(TestListener.NULL);
 
309
            Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
309
310
                        Assert.AreEqual("custom message" + Environment.NewLine + "System.ArgumentException was expected", result.Message);
310
311
                }
311
312
 
314
315
                {
315
316
                        Type fixtureType = typeof(TestDoesNotThrowExceptionFixture);
316
317
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestDoesNotThrowExceptionName" );
317
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
318
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
318
            TestResult result = test.Run(TestListener.NULL);
 
319
            Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
319
320
                        Assert.AreEqual("System.ArgumentException was expected", result.Message);
320
321
                }
321
322
 
324
325
                {
325
326
                        Type fixtureType = typeof(TestDoesNotThrowExceptionFixture);
326
327
                        Test test = TestBuilder.MakeTestCase( fixtureType, "TestDoesNotThrowExceptionNameWithUserMessage" );
327
 
            TestResult result = test.Run(TestListener.NULL, TestFilter.Empty);
328
 
                        Assert.IsTrue(result.IsFailure, "Test method should have failed");
 
328
            TestResult result = test.Run(TestListener.NULL);
 
329
            Assert.IsTrue(result.ResultState == ResultState.Failure, "Test method should have failed");
329
330
                        Assert.AreEqual("custom message" + Environment.NewLine + "System.ArgumentException was expected", result.Message);
330
331
                }
331
332
 
333
334
                public void MethodThrowsException()
334
335
                {
335
336
                        TestResult result = TestBuilder.RunTestFixture( typeof( TestThrowsExceptionFixture ) );
336
 
                        Assert.AreEqual(true, result.IsFailure);
 
337
            Assert.AreEqual(true, result.ResultState == ResultState.Failure);
337
338
                }
338
339
 
339
340
                [Test] 
340
341
                public void MethodThrowsRightExceptionMessage()
341
342
                {
342
343
                        TestResult result = TestBuilder.RunTestFixture( typeof( TestThrowsExceptionWithRightMessage ) );
343
 
                        Assert.AreEqual(true, result.IsSuccess);
 
344
            Assert.AreEqual(true, result.ResultState == ResultState.Success);
344
345
                }
345
346
 
346
347
                [Test]
347
348
                public void MethodThrowsArgumentOutOfRange()
348
349
                {
349
350
                        TestResult result = TestBuilder.RunTestFixture( typeof( TestThrowsArgumentOutOfRangeException ) );
350
 
                        Assert.AreEqual(true, result.IsSuccess );
 
351
            Assert.AreEqual(true, result.ResultState == ResultState.Success);
351
352
                }
352
353
 
353
354
                [Test] 
354
355
                public void MethodThrowsWrongExceptionMessage()
355
356
                {
356
357
                        TestResult result = TestBuilder.RunTestFixture( typeof( TestThrowsExceptionWithWrongMessage ) );
357
 
                        Assert.AreEqual(true, result.IsFailure);
 
358
            Assert.AreEqual(true, result.ResultState == ResultState.Failure);
358
359
                }
359
360
 
360
361
                [Test]
361
362
                public void SetUpThrowsSameException()
362
363
                {
363
364
                        TestResult result = TestBuilder.RunTestFixture( typeof( SetUpExceptionTests ) );
364
 
                        Assert.AreEqual(true, result.IsFailure);
 
365
            Assert.AreEqual(true, result.ResultState == ResultState.Failure);
365
366
                }
366
367
 
367
368
                [Test]
368
369
                public void TearDownThrowsSameException()
369
370
                {
370
371
                        TestResult result = TestBuilder.RunTestFixture( typeof( TearDownExceptionTests ) );
371
 
                        Assert.AreEqual(true, result.IsFailure);
 
372
            Assert.AreEqual(true, result.ResultState == ResultState.Failure);
372
373
                }
373
374
 
374
375
                [Test]
420
421
                {
421
422
                        ExceptionHandlerCalledClass fixture = new ExceptionHandlerCalledClass();
422
423
                        Test test = TestBuilder.MakeTestCase( fixture, "ThrowsArgumentException_AlternateHandler" );
423
 
            test.Run(TestListener.NULL, TestFilter.Empty);
 
424
            test.Run(TestListener.NULL);
424
425
                        Assert.IsFalse(fixture.HandlerCalled, "Base Handler should not be called" );
425
426
                        Assert.IsTrue(fixture.AlternateHandlerCalled, "Alternate Handler should be called" );
426
427
                }
430
431
                {
431
432
                        ExceptionHandlerCalledClass fixture = new ExceptionHandlerCalledClass();
432
433
                        Test test = TestBuilder.MakeTestCase( fixture, "ThrowsArgumentException" );
433
 
            test.Run(TestListener.NULL, TestFilter.Empty);
 
434
            test.Run(TestListener.NULL);
434
435
                        Assert.IsTrue(fixture.HandlerCalled, "Base Handler should be called");
435
436
                        Assert.IsFalse(fixture.AlternateHandlerCalled, "Alternate Handler should not be called");
436
437
                }
440
441
                {
441
442
                        ExceptionHandlerCalledClass fixture = new ExceptionHandlerCalledClass();
442
443
                        Test test = TestBuilder.MakeTestCase( fixture, "ThrowsApplicationException" );
443
 
            test.Run(TestListener.NULL, TestFilter.Empty);
 
444
            test.Run(TestListener.NULL);
444
445
                        Assert.IsFalse( fixture.HandlerCalled, "Base Handler should not be called" );
445
446
                        Assert.IsFalse( fixture.AlternateHandlerCalled, "Alternate Handler should not be called" );
446
447
                }
450
451
                {
451
452
                        ExceptionHandlerCalledClass fixture = new ExceptionHandlerCalledClass();
452
453
                        Test test = TestBuilder.MakeTestCase( fixture, "ThrowsApplicationException_AlternateHandler" );
453
 
            test.Run(TestListener.NULL, TestFilter.Empty);
 
454
            test.Run(TestListener.NULL);
454
455
                        Assert.IsFalse(fixture.HandlerCalled, "Base Handler should not be called");
455
456
                        Assert.IsFalse(fixture.AlternateHandlerCalled, "Alternate Handler should not be called");
456
457
                }