Rows' count (advanced)
It’s possible to go further with the assertion row-count and define a filter. Suppose that you know that you’ve made less than 100 sales with a TotalAmountWithVAT higher than 1000$. To assert this create a query returning all your sales, define a filter to hold the rows with a TotalAmountWithVAT greater than 1000 and assert that the count is not greater than 100. You could also have asserted that this set of rows represent less than 1% of your sales. All these scenarios are supported by row-count.
Filter
To define a filter, you must specify it in the element row-count by the means of the tags filter.
<assert>
<row-count>
<filter>
...
</filter>
...
</row-count>
</assert>
This filter is defined by the means of alias, expressions and predicates. For more info about these elements check the page about them.
<assert>
<row-count>
<filter>
<alias column-index="1">Quantity</alias>
<alias column-index="2">UnitPrice</alias>
<expression name="TotalPriceWithVAT">UnitPrice*Quantity*1.21</variable>
<predicate name="TotalPriceWithVAT">
<more-than or-equal="true">1000<more-than>
<predicate>
</filter>
...
</row-count>
</assert>
Fixed value and percentage
It’s possible to use the standard behaviour of row-count and compare the remaining rows (after filter’s application). To achieve this, just specify the expected values in the xml element corresponding to one of the following operators equal, more-than, less-than (the two last element accepts the overload of the attribute or-equal).
<assert>
<row-count>
<filter>
...
</filter>
<more-than or-equal="true">10<more-than>
</row-count>
</assert>
If you want to assert the ratio of filtered rows, you can specify percentage. The count of filtered rows will be divided by the count of rows in the unfiltered result-set. To specify this kind of behaviour, you need to add the symbol percentage (%) after the value in the operator tag.
<assert>
<row-count>
<filter>
...
</filter>
<less-than>25%<less-than>
</row-count>
</assert>