Created
July 4, 2011 21:34
-
-
Save gregoryyoung/1063974 to your computer and use it in GitHub Desktop.
Failing spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sometimes the point of a specification is to show that a given scenario fails. | |
* | |
* A failing specification is similar to a SUT specification. It will return the SUT | |
* from its given method. The SUT will then be passed to the when() method where some | |
* action will happen. It is expected that this action will throw an exception. | |
* | |
* The exception is then passed to the expectations. | |
* | |
* note: if you are doing more complex operations other templates can be used with | |
* the TestContext pattern. | |
*/ | |
public class FailingSpecification | |
{ | |
public ISpecification it_will_fail = new FailingSpecification<FailingExample, SomethingFailedException>() | |
{ | |
On = () => new FailingExample(), | |
When = (obj) => obj.CauseFailure(), | |
Expect = | |
{ | |
exception => exception.Message == "Something failed!", | |
exception => exception.ErrorCode == 17 | |
}, | |
}; | |
} | |
public class FailingExample | |
{ | |
public void CauseFailure() | |
{ | |
throw new SomethingFailedException("Something failed!", 17); | |
} | |
} | |
public class SomethingFailedException : Exception | |
{ | |
public readonly int ErrorCode; | |
public SomethingFailedException(string msg, int errorCode) : base(msg) | |
{ | |
ErrorCode = errorCode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment