Show / Hide Table of Contents

Class MockUtility

This class is used to create instances of classes using reflection and Moq.

Inheritance
object
MockUtility
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class MockUtility

Methods

| Edit this page View Source

Build<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.

| Edit this page View Source

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 MockUtility.Build<T>() instead.

  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com