Based on the Visual Studio Unit Test framework, this library provides helper methods to speed up the development of new Unit Tests
To access to the methods provided by the library, the test classes must inherit from BaseTestClass
[TestClass]
public class UserRepositoryTest : BaseTestClass
{
...
}
The method allows to verify that an exception, inheriting from ArgumentException, is thrown during the execution of the Test logic. In the following example the code will verify that is not accepted a null value for the user parameter in the Insert method.
[TestMethod]
public void WhenUserIsNullItWillFail()
{
TestExpectedArgumentException<ArgumentNullException>( () => new UserRepository().Insert(null), "user");
}
You can also pass directly an ArgumentNullException instance
[TestMethod]
public void WhenUserIsNullItWillFail()
{
TestExpectedArgumentException( () => new UserRepository().Insert(null), new ArgumentNullException("user"));
}
The method works in the same way of the above method, except that is designed to work with any other type of exception.
[TestMethod]
public void WhenUserIsNullItWillFail()
{
TestExpectedException<UserNotFoundException>( () => new UserRepository().Select(100),
"No user with ID 100 has been found.");
}