Class
Expr

Provides utility methods for simplifying the creation of expression trees used in mocking scenarios. This class offers a fluent API for building property access expressions that can be used to configure mock behavior for property getters and setters.

Definition

Namespace:Telerik.JustMock

Assembly:Telerik.JustMock.dll

Syntax:

cs-api-definition
public static class Expr

Inheritance: objectExpr

Methods

Property<T>(Expression<Func<T>>)

Creates an IPropertyExpressionBuilder<T> for the specified property access expression. This method analyzes a lambda expression that accesses a property and builds a property expression that can be used to configure mock behavior for property getters or setters.

Declaration

cs-api-definition
public static IPropertyExpressionBuilder<T> Property<T>(Expression<Func<T>> expression)

Parameters

expression

Expression<Func<T>>

A lambda expression representing the property access, such as () => obj.Property for instance properties or () => Class.StaticProperty for static properties.

Returns

IPropertyExpressionBuilder<T>

An IPropertyExpressionBuilder<T> that provides fluent methods for configuring property getter and setter behavior in mock objects.

Exceptions

ArgumentException

Thrown when the provided expression is not a property access expression. The expression must be in the form of accessing a property, such as obj.Property or Class.StaticProperty.

MockException

Thrown when attempting to mock a field instead of a property. JustMock only supports mocking properties, not fields.

Example

csharp
// Setting up a mock for a property getter
Mock.Arrange(Expr.Property(() => mock.SomeProperty)).Returns(expectedValue);

// Setting up a mock for a property setter
Mock.Arrange(Expr.Property(() => mock.SomeProperty).Set(Arg.IsAny<string>).DoNothing();
In this article
DefinitionMethodsProperty<T>(Expression<Func<T>>)
Not finding the help you need?
Contact Support