Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestMethod]
- [ExpectedException(typeof(CriticalException))]
- public void GetOrganisation_MultipleOrganisations_ThrowsException()
- [TestMethod]
- [ExpectedException(typeof(CriticalException), "An error occured")]
- public void GetOrganisation_MultipleOrganisations_ThrowsException()
- [TestMethod]
- [ExpectedException(typeof(CriticalException), MyRes.MultipleOrganisationsNotAllowed)]
- public void GetOrganisation_MultipleOrganisations_ThrowsException()
- public static class ExceptionAssert
- {
- public static T Throws<T>(Action action) where T : Exception
- {
- try
- {
- action();
- }
- catch (T ex)
- {
- return ex;
- }
- Assert.Fail("Exception of type {0} should be thrown.", typeof(T));
- // The compiler doesn't know that Assert.Fail
- // will always throw an exception
- return null;
- }
- }
- [TestMethod]
- public void GetOrganisation_MultipleOrganisations_ThrowsException()
- {
- OrganizationList organizations = new Organizations();
- organizations.Add(new Organization());
- organizations.Add(new Organization());
- var ex = ExceptionAssert.Throws<CriticalException>(
- () => organizations.GetOrganization());
- Assert.AreEqual(MyRes.MultipleOrganisationsNotAllowed, ex.Message);
- }
- [Fact]
- public void TestException()
- {
- Exception ex = Record.Exception(() => myClass.DoSomethingExceptional());
- // Assert whatever you like about the exception here.
- }
- [ExpectedException( Handler="HandlerMethod" )]
- public void TestMethod()
- {
- ...
- }
- public void HandlerMethod( System.Exception ex )
- {
- ...
- }
Add Comment
Please, Sign In to add comment