ClassExpr
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:
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
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
An IPropertyExpressionBuilder<T> that provides fluent methods for configuring property getter and setter behavior in mock objects.
Exceptions
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.
Thrown when attempting to mock a field instead of a property. JustMock only supports mocking properties, not fields.
Example
// 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();