MockTMockedType Class

Typemock Isolator Developer Guide
Mock is the Typemock Isolator mock type controller, this class is use for managing the virtual mocks, using generic code sugar, to ease the mock creation.
Inheritance Hierarchy

SystemObject
  TypeMockMock
    TypeMockMockObject
      TypeMockMockTMockedType
        TypeMockMockObjectTMockedType

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

public class Mock<TMockedType> : MockObject

Type Parameters

TMockedType
The Type to Mock

The MockTMockedType type exposes the following members.

Properties

  NameDescription
Public propertyCallBase (Inherited from Mock.)
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
(Inherited from Mock.)
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.
(Inherited from Mock.)
Public propertyObject
Get the Mocked Object
(Inherited from MockObject.)
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.
(Inherited from Mock.)
Public propertyStrictStatic
Can set the static methods of a mocked type to be Strict
(Inherited from Mock.)
Public propertyValidateArgsOnVerify Obsolete.
Obslolete. Argument validation is done both on calling the method and during Verify.
(Inherited from Mock.)
Top
Methods

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

  NameDescription
Public eventMockMethodCalled
Event that is fired after a mocked method is called and after argument validation is performed MockMethodCalledEventHandler
(Inherited from Mock.)
Top
Remarks

There are 3 types of mocks MockManager.MockTMockedType - Will mock the next 'new' instance of the mocked Type (and all static methods) MockManager.MockAllTMockedType - Will mock ALL (future and past) instances of the mocked Type MockManager.MockObjectTMockedType - Will create ONE instance of the Type. This instance is mocked

See Also

Reference