Add QueryLens to an Existing Test Project
The safest rollout is incremental: start with a few high-value statements in Level 1, then introduce a dialect profile, then add a schema snapshot when the suite is stable.
Recommended Rollout
- Install the package with
dotnet add package QueryLens. - Pick one global test setup location and set
QueryLens.Dialectthere if you want Level 2 validation. - Add a few focused assertions around important queries using
IsValid,Errors, orErrorSummary. - When you are ready for Level 3, load the schema snapshot before any validation occurs.
- Call
QueryLens.Reset()between suites only when you intentionally need to reconfigure the runtime.
Common Mistakes
- Setting
QueryLens.Dialectafter a previous test has already triggered validation - Loading schema with the default generic profile still selected
- Mixing unrelated configuration patterns across test classes instead of one shared fixture
Example
public sealed class QueryLensFixture
{
public QueryLensFixture()
{
QueryLens.Reset();
QueryLens.Dialect = DialectProfile.SqlServer2019;
}
}