Mock Class

Typemock Isolator Developer Guide
Mock is the Typemock Isolator mock type controller, this class is use for managing the virtual mocks
Inheritance Hierarchy

SystemObject
  TypeMockMock
    TypeMockMockObject

Namespace:  TypeMock
Assembly:  TypeMock (in TypeMock.dll) Version: 9.3.5.0 (9.3.5.0)
Syntax

public class Mock : IMockControl

The Mock type exposes the following members.

Constructors

  NameDescription
Protected methodMock
Constructer, keep internal
Top
Properties

  NameDescription
Public propertyCallBase
Public propertyCallStatic
Allow mocking a static method when that method is overloaded with an instance method
Remarks

In most cases there is no need to use this method as Typemock Isolator will mock all static methods of the mocked type. CallStatic should be used when an instance method and a static method have the same name By default the instance methods are returned. If instance methods are mocked
Public propertyMockedInstance
Get the actual instance that is being mocked and controlled. This enables tracking instance mocks to the actual instance
Public propertyMockedType
Get the type that is mocked and controlled.
Public propertyStrict
Can set the mock to be Strict The default is the Methods of Abstract and Interfaces are Strict and Arbitrary calls fail while Arbitrary Methods of concrete classes are allowed.
Public propertyStrictStatic
Can set the static methods of a mocked type to be Strict
Public propertyValidateArgsOnVerify Obsolete.
Obslolete. Argument validation is done both on calling the method and during Verify.
Top
Methods

  NameDescription
Public methodAlwaysCallOriginal
Sets the expectaion of this method to always call the original method.
Public methodAlwaysReturn(String, Object, Type)
Expect unlimited calls from method, and always returns mock value
Public methodAlwaysReturn(String, Object, Type, Type)
Expect unlimited calls from method, and always returns mock value
Public methodAlwaysThrow(String, Exception, Type)
Expect unlimited calls from method, and always throws exception
Public methodAlwaysThrow(String, Exception, Type, Type)
Expect unlimited calls from method, and always throws exception
Public methodCode exampleAnonymousMethodOf
Use to mock all anonymous methods that are called from within a method
Public methodCode exampleAssignField
Assign a new value to the given field.
Protected methodChangeConstructor
Constructer swaping with the mocked one, keep internal
Public methodClear
Clear all expectations
Public methodClear(String)
Clear expectation of a method
Public methodClear(ExpectationBlock)
Clear expectation of an expectation block
Public methodEndBlock
End an expectation block
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExpectAddEvent(String)
Expect 1 event listener to be added (event += new EventHandler())
Public methodExpectAddEvent(String, Int32)
Expect a number of event listeners to be added (event += new EventHandler())
Public methodExpectAddEventAlways
Expect unlimited number of event listeners to be added (event += new EventHandler())
Public methodExpectAlways
Expect unlimited calls from method
Public methodExpectAndReturn(String, Object, Type)
Expect 1 call from method, and mock return value
Public methodExpectAndReturn(String, Object, Int32, Type)
Expect a number of calls from method, and mock return value
Public methodExpectAndThrow(String, Exception, Type)
Expect 1 call from method, and mock throwing an exception
Public methodExpectAndThrow(String, Exception, Int32, Type)
Expect a number of calls from method, and mock throwing an exception
Public methodExpectCall(String, Type)
Expect 1 call from method
Public methodExpectCall(String, Int32, Type)
Expect a number of calls from method
Public methodExpectCallAndVerify Obsolete.
Verify 1 call from method , continue with method as normal
Public methodExpectConstructor
Mock Constructor
Public methodExpectConstructor(Int32)
Mock Constructor
Public methodExpectConstructorAlways
Mock unlimited calls from Constructor
Public methodExpectConstructorAndThrow
Mock Constructor and throw exception when constructor is called
Public methodExpectGet(String, Object)
Expect 1 get of a Property and mock the Property's value
Public methodExpectGet(String, Object, Int32)
Expect a number of gets of a Property and mock the Property's value
Public methodExpectGetAlways
Expect unlimited get of a Property and always mock the Property's value
Public methodExpectGetAndAlwaysThrow
Expect unlimited get of a Property and always mock throwing an exception
Public methodExpectGetAndThrow(String, Exception)
Expect 1 get of a Property and mock throwing an exception
Public methodExpectGetAndThrow(String, Exception, Int32)
Expect a number of gets of a Property and mock throwing an exception
Public methodExpectGetIndex(Object)
Expect 1 get of an Index and mock the index value
Public methodExpectGetIndex(Object, Int32)
Expect a number of get of an Index and mock the index value
Public methodExpectGetIndexAlways
Expect unlimited set of an Index and mock throwing an exception
Public methodExpectGetIndexAndAlwaysThrow
Expect unlimited set of an Index and mock throwing an exception
Public methodExpectGetIndexAndThrow(Exception)
Expect 1 get of an Index and mock throwing an exception
Public methodExpectGetIndexAndThrow(Exception, Int32)
Expect a number of gets of an Index and mock throwing an exception
Public methodExpectRemoveEvent(String)
Expect 1 event listener to be removed (event -= new EventHandler())
Public methodExpectRemoveEvent(String, Int32)
Expect a number of event listeners to be removed (event -= new EventHandler())
Public methodExpectSet(String)
Expect 1 set of a Property
Public methodExpectSet(String, Int32)
Expect a number of sets of a Property
Public methodExpectSetAlways
Expect unlimited set of a Property
Public methodExpectSetAndAlwaysThrow
Expect unlimited set of a Property and always mock throwing an exception
Public methodExpectSetAndThrow(String, Exception)
Expect 1 set of a Property and mock throwing an exception
Public methodExpectSetAndThrow(String, Exception, Int32)
Expect a number of sets of a Property and mock throwing an exception
Public methodExpectSetIndex
Expect 1 set of an Index
Public methodExpectSetIndex(Int32)
Expect a number of sets of an Index
Public methodExpectSetIndexAlways
Expect unlimited set of an Index
Public methodExpectSetIndexAndAlwaysThrow
Expect unlimited set of an Index and mock throwing an exception
Public methodExpectSetIndexAndThrow(Exception)
Expect 1 set of an Index and mock throwing an exception
Public methodExpectSetIndexAndThrow(Exception, Int32)
Expect a number of sets of an Index and mock throwing an exception
Public methodExpectUnmockedCall(String, Type)
Verify 1 call from method , continue with method as normal
Public methodExpectUnmockedCall(String, Int32, Type)
Verify a number of calls from method , continue with method as normal
Public methodExpectUnmockedConstructor
Don't Mock Constructor but verify arguments
Public methodExpectUnmockedConstructor(Int32)
Don't Mock Constructor but verify arguments
Public methodExpectUnmockedGet(String)
Verify 1 get of a Property , continue with get method as normal
Public methodExpectUnmockedGet(String, Int32)
Verify a number of gets of a Property , continue with get method as normal
Public methodExpectUnmockedSet(String)
Verify 1 set of a Property , continue with set method as normal
Public methodExpectUnmockedSet(String, Int32)
Verify a number of sets of a Property , continue with set method as normal
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetBlock
Retrieve Expectation Block, by its label name
Public methodGetCallCount(String)
Return the amount of times a method has been called
Public methodGetCallCount(String, Type)
Return the amount of times a method has been called
Public methodGetCallIndexerCounter
Return the amount of times an indexer has been called
Public methodGetCallPropertyGetCounter
Return the amount of times a property has been called
Public methodGetCallPropertySetCounter
Return the amount of times a property has been set
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMethodSettings
Perform Behavior tweaking on methods rather then the whole mocked type
Public methodMethodSettingsGetIndex
Perform Behavior tweaking on methods rather then the whole mocked type
Public methodMethodSettingsGetProperty
Perform Behavior tweaking on methods rather then the whole mocked type
Public methodMethodSettingsSetIndex
Perform Behavior tweaking on methods rather then the whole mocked type
Public methodMethodSettingsSetProperty
Perform Behavior tweaking on methods rather then the whole mocked type
Public methodMockConstructor Obsolete.
Mock Constructor
Public methodCode exampleMockField
Create a Mock object and assign it to a given field.
Protected methodRemoveStaticCtor
Remobing static constructer, keep internal
Public methodStartBlock
Start an expectation block
Public methodStartBlock(String)
Start an expectation block with a label name
Public methodStartBlock(VerifyMode)
Start an expectation block with a verify mode
Public methodStartBlock(String, VerifyMode)
Start an expectation block with a label and a verify mode
Public methodStartBlockBefore(ExpectationBlock)
Start an expectation block and adds the expectations before another expectation block
Public methodStartBlockBefore(ExpectationBlock, String)
Start an expectation block with a label and adds the expectations before another expectation block
Public methodStartBlockBefore(ExpectationBlock, VerifyMode)
Start an expectation block with a verify mode and adds the expectations before another expectation block
Public methodStartBlockBefore(ExpectationBlock, String, VerifyMode)
Start an expectation block with a label and a verify mode, and adds the expectations before another expectation block
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodVerify
Verify mocked type
Public methodVerifyWithTimeout
Wait with timeout (5 seconds) for all expected methods to be called
Public methodVerifyWithTimeout(Int32)
Wait with timeout (im milliseconds) for all expected methods to be called
Top
Events

  NameDescription
Public eventMockMethodCalled
Event that is fired after a mocked method is called and after argument validation is performed MockMethodCalledEventHandler
Top
Remarks

Mock object have 3 stages.
  1. Set Up - This is the stage where you 'record' what the mocked type/object expects to do and what to return
  2. Run - Run the actual class under test
  3. Verify - Make sure that the mocked object acted as expected

These phases are managed by the Mock object.

Note Note
You cannot create a Mock directly use MockManager.Mock(Type)
Note Note
When mocking a method that is declared in When mocking a method that is declared in a base class, Typemock Isolator will only mock that method when called from the mocked type. When a base method is mocked and a derived class calls that method, it WON'T be mocked

See Also

Reference