Add count methods to context and query

This includes tests for these methods.

Signed-off-by: Don Naegely <naegelyd@gmail.com>