Class MockUtility
This class is used to create instances of classes using reflection and Moq.
Inherited Members
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class MockUtility
Methods
| Edit this page View SourceBuild<T>()
Creates a fluent builder for constructing an instance of a class with a mix of Moq-based mocks and explicit values for constructor parameters. Use this when the class has multiple constructors or has non-mockable parameters like strings, primitives, or enums.
Declaration
public static MockInstanceBuilder<T> Build<T>() where T : class
Returns
| Type | Description |
|---|---|
| MockInstanceBuilder<T> | A MockInstanceBuilder for fluent configuration. |
Type Parameters
| Name | Description |
|---|---|
| T | The type to create. This is typically the system under test. |
CreateInstance<T>()
Creates an instance of a class using reflection and Moq. If the class has a parameterless constructor, it will be used. If the class has a constructor with parameters, mocks will be created for each parameter type. ///
Declaration
public static MockCreationResult<T> CreateInstance<T>() where T : class
Returns
| Type | Description |
|---|---|
| MockCreationResult<T> | MockCreationResult that provides access to the instance of T that was instantiated and also access to the Moq mocks. |
Type Parameters
| Name | Description |
|---|---|
| T | Create an instance of this type. This is typically the system under test. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Exceptions are thrown if the class does not have any constructors or has multiple constructors.
For classes with multiple constructors or non-mockable parameters, use |