How to pass NUnit test if no exception?

In .NET 3.5 using NUnit 2.4.8, I'm running this test:

[ExpectedException(typeof(EligibilityException))]
        [Test]
        public void OverMaxWeightSuccessTest()
        {
            new Eligibility.OverMaxWeight("501").CheckEligibility();
        }

The above throws an EligibilityException exception if the weight is over 500.  CheckEligibility() is a void.  How do I write a test for the failure condition?  Meaning, a weight of 400?

In general, I need to throw an exception if the weight is over 500.   It would be cleaner if CheckEligibility() returned a boolean.   If there a better way to do this?
brettrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

philipjonathanCommented:
You mean you want the test to fail if CheckEligibility throws EligibilityException when weight is 400?
The simplest way is to use try-catch:

try
{
  new Eligibility.OverMaxWeight("400").CheckEligibility();
  // assert test succeeds
}
catch (EligibilityException)
{
  // assert test fails
}
0
brettrAuthor Commented:
No - you have it backwards.  The attribute is already taking care of the exception.  I need a way to say test failure when there isn't an exception.
0
philipjonathanCommented:
I suppose you could assert a failure below the CheckEligibility line:

[ExpectedException(typeof(EligibilityException))]
[Test]
public void OverMaxWeightSuccessTest()
{
  new Eligibility.OverMaxWeight("501").CheckEligibility();
  Assert.Fail();
}

0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

brettrAuthor Commented:
Thanks.  In your first example where you have

// assert test succeeds

what type of assert could I put there so the test passes in that case?  There isn't an Assert.Pass().   CheckEligibility() returns void so I don't have anything to check.
0
philipjonathanCommented:
I don't there is Assert.Pass, but probably you can just leave it alone. If you don't assert fail anything, it will be considered a pass. Either that, or you assert a "true" equals to "true"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brettrAuthor Commented:
Leaving it blank works.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.