Now we need to write our code for testing this. To refresh
your memory, we can use different Fitnesse fixtures to run our tests. In this
case as in part 1, we utilize a columnfixture. In this test, we cannot analyze
using the reportdocument object. We need to analyze the reports contents once
it's rendered. The reportdocument object can export the contents, but we
cannot use the reportdocument object directly to test for values.

To get our values for the test we will export the report to
a stream, and then read the stream as a string. Below is the code for doing
this:

In this code, we first set the fields for the fieldname, and value. And as in
part 1, we create a method called OK that returns a Boolean. Fitnesse will
pass the fieldname and value to the OK method. Within the OK method, we get
our report (CrystalReport1) named report. We then need to get the report
results back in a stream. To do that we use the ExportToStream method found in
the ReportDocument object. Here we cast it to a MemoryStream, but it can be
cast to any valid Stream type.

We then get the string value of the report, by reading the
Stream. Then we cast the resulting byte array into an ASCII value, pushing
into a string variable. In the if statements, this
particular test is checking for the presence of the value "today".
That way we know to test against the DateTime.Now value.

Once we have the report in a string, it's trivial to run the
tests. This simple test shows you how to accomplish this, by using the indexof property. We are assuming that if the value is
present in the report, this is true. You can create more complex testing if
you want, and test that this is after a heading or something. But that is
beyond the scope of this article.

Once you run this test, your Fitnesse test should run green.
Just like the one in Figure 1. And you now have a test to run in your QA build
script!