dotMemory Unit 3.2 Help

Create Reusable Queries

Quite often, test assertions use identical dotMemory Unit queries (say, returning a set of objects selected by some condition). In such a case, you can create a reusable query just once and use it anywhere in the code. The static QueryBuilder class allows you to create queries that return object sets and filter traffic by specific conditions. Such queries can then be passed as a parameter to the ObjectSet.GetObjects or Traffic.Where methods.

Example

// create reusable query var preset = QueryBuilder.GetObjects(where => where.Generation.Is(Generation.LOH)) .GetObjects(where => where.Namespace.Like("MyNamespace*")); dotMemory.Check(memory => { // use the query Assert.That(memory.GetObjects(preset).ObjectsCount, Is.EqualTo(0)); });

QueryBuilder static class

Allows creating reusable queries.

QueryBuilder methods

Name

Description

GetObjects(Func<ObjectProperty, Query> query): ObjectSetQuery

Creates a query that gets a subset of objects by a specific condition. The condition is defined by a Query that should be returned by a lambda expression. The ObjectProperty object passed to the lambda allows creating queries that select objects by type, interface, and other parameters.

Returns an instance of the ObjectSetQuery type.

TrafficQuery(Func<TrafficProperty, Query> query): TrafficQuery

Creates a query that gets memory traffic data by a specific condition. The condition is defined by a Query that should be returned by a lambda expression. The TrafficProperty instance passed to the lambda allows creating queries that filter traffic data by object type, interface, and other parameters.

Returns an instance of the TrafficQuery type.

Last modified: 10 May 2022