dotMemory Unit 2.2 Help

Creating 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

NameDescription
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: 4 May 2016