Frequently you'll want to simply make an assertion that an expected fact about your system is true. Storyteller provides a variation on the basic Sentence grammar that lets you simply assert on a single boolean condition.
As a Fixture Method
The easiest implementation is to use a grammar method on your Fixture classes that returns a boolean value without adding the return value into the Sentence format like these methods below:
public void ThisLineAlwaysThrowsExceptions()
{
throw new DivideByZeroException("You can't do this!");
}
[FormatAs("This line is always true")]
public bool ThisLineIsAlwaysTrue()
{
return true;
}
[FormatAs("This line is always false")]
public bool ThisLineIsAlwaysFalse()
{
return false;
}
As a Lambda Declaration
You also have the option of declaring a Fact grammar programmatically on a Fixture
class as in this code below:
public FactFixture()
{
this["AnotherTruth"]
= Fact("The thing is activated").VerifiedBy(() => true);
}
Providing more Context on Failures
For a success, simply turning the line green and tabulating the rights is good enough. For detected failures, you may want to add more contextual information to the specification output to help you solve any failures. While you can always throw an exception to get the extra information into the results, a cleaner, more controlled way is to use the StoryTellerAssert
class to add contextual information without all the overhead of a stacktrace.
Below is a sample:
[FormatAs("The confirmation email was sent")]
public bool TheConfirmationEmailWasSent()
{
StoryTellerAssert
.Fail(true, "The email server is not reachable");
return true;
}
See Instrumenting and Performance Logging
Facts in Action
If you were to use all the fact grammars shown above, the output would look like this below: