NUnit.Framework.Assertions.AssertThrowsTests.CheckForSpuriousAssertionResults()

Here are the examples of the csharp api class NUnit.Framework.Assertions.AssertThrowsTests.CheckForSpuriousAssertionResults() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

9 Examples 7

1. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void AssertThrowsWrappingAssertFail()
        {
            Assert.Throws<AssertionException>(() => Assert.Fail());

            CheckForSpuriousAssertionResults();
        }

2. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void ThrowsConstraintWrappingAssertFail()
        {
            Assert.That(() => { Assert.Fail(); }, 
                Throws.Exception.TypeOf<AssertionException>());

            CheckForSpuriousAssertionResults();
        }

3. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void BaseExceptionThrown()
        {
            var ex = CatchException(() => 
                Assert.Throws<ArgumentException>(TestDelegates.ThrowsSystemException));

            Assert.That(ex.Message, Does.StartWith(
                "  Expected: <System.ArgumentException>" + Environment.NewLine +
                "  But was:  <System.Exception: my message" + Environment.NewLine ));

            CheckForSpuriousAssertionResults();
        }

4. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void UnrelatedExceptionThrown()
        {
            var ex = CatchException(() => 
                Assert.Throws<ArgumentException>(TestDelegates.ThrowsNullReferenceException));

            Assert.That(ex.Message, Does.StartWith(
                "  Expected: <System.ArgumentException>" + Environment.NewLine +
                "  But was:  <System.NullReferenceException: my message" + Environment.NewLine ));

            CheckForSpuriousAssertionResults();
        }

5. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void DerivedExceptionThrown()
        {
            var ex = CatchException(() => 
                Assert.Throws<Exception>(TestDelegates.ThrowsArgumentException));

            Assert.That(ex.Message, Does.StartWith(
                "  Expected: <System.Exception>" + Environment.NewLine +
                "  But was:  <System.ArgumentException: myMessage" + Environment.NewLine + "Parameter name: myParam" + Environment.NewLine ));

            CheckForSpuriousAssertionResults();
        }

6. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void NoExceptionThrown()
        {
            var ex = CatchException(() => 
                Assert.Throws<ArgumentException>(TestDelegates.ThrowsNothing));

            Assert.That(ex.Message, Is.EqualTo(
                "  Expected: <System.ArgumentException>" + Environment.NewLine +
                "  But was:  null" + Environment.NewLine));

            CheckForSpuriousAssertionResults();
        }

7. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void AssertDoesNotThrowFails()
        {
            var ex = CatchException(() => 
                Assert.DoesNotThrow(TestDelegates.ThrowsArgumentException));

            Assert.That(ex, Is.Not.Null.With.TypeOf<AssertionException>());

            CheckForSpuriousAssertionResults();
        }

8. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void GenericThrowsReturnsCorrectException()
        {
            var ex = Assert.Throws<ArgumentException>(
                delegate { throw new ArgumentException("myMessage", "myParam"); }) as ArgumentException;

            Assert.IsNotNull(ex, "No ArgumentException thrown");
            Assert.That(ex.Message, Does.StartWith("myMessage"));
            Assert.That(ex.ParamName, Is.EqualTo("myParam"));

            CheckForSpuriousAssertionResults();
        }

9. Example

Project: nunit
Source File: AssertThrowsTests.cs
View license
[Test]
        public void ThrowsReturnsCorrectException()
        { 
            var ex = Assert.Throws(typeof(ArgumentException), 
                delegate { throw new ArgumentException("myMessage", "myParam"); } ) as ArgumentException;

            Assert.IsNotNull(ex, "No ArgumentException thrown");
            Assert.That(ex.Message, Does.StartWith("myMessage"));
            Assert.That(ex.ParamName, Is.EqualTo("myParam"));

            CheckForSpuriousAssertionResults();
        }