MockObject is the Typemock Isolator dynamic mock object controller, this class is use for managing the
dynamic mocks
Inheritance Hierarchy
TypeMockMock
TypeMockMockObject
TypeMockMockTMockedType
Namespace: TypeMock
Assembly: TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax
The MockObject type exposes the following members.
Properties
Name | Description | |
---|---|---|
![]() | CallBase | (Inherited from Mock.) |
![]() | CallStatic |
Allow mocking a static method when that method is overloaded with an instance method
(Inherited from Mock.)Remarks |
![]() | MockedInstance |
Get the actual instance that is being mocked and controlled. This
enables tracking instance mocks to the actual instance
(Inherited from Mock.) |
![]() | MockedType |
Get the type that is mocked and controlled.
(Inherited from Mock.) |
![]() | Object |
Get the Mocked Object
|
![]() | Strict |
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.) |
![]() | StrictStatic |
Can set the static methods of a mocked type to be Strict
(Inherited from Mock.) |
![]() | ValidateArgsOnVerify | Obsolete.
Obslolete. Argument validation is done both on calling the method and during Verify.
(Inherited from Mock.) |
Methods
Name | Description | |
---|---|---|
![]() | AlwaysCallOriginal |
Sets the expectaion of this method to always call the original method.
(Inherited from Mock.) |
![]() | AlwaysReturn(String, Object, Type) |
Expect unlimited calls from method, and always returns mock value
(Inherited from Mock.) |
![]() | AlwaysReturn(String, Object, Type, Type) |
Expect unlimited calls from method, and always returns mock value
(Inherited from Mock.) |
![]() | AlwaysThrow(String, Exception, Type) |
Expect unlimited calls from method, and always throws exception
(Inherited from Mock.) |
![]() | AlwaysThrow(String, Exception, Type, Type) |
Expect unlimited calls from method, and always throws exception
(Inherited from Mock.) |
![]() ![]() | AnonymousMethodOf |
Use to mock all anonymous methods that are called from within a method
(Inherited from Mock.) |
![]() ![]() | AssignField |
Assign a new value to the given field.
(Inherited from Mock.) |
![]() | ChangeConstructor |
Constructer swaping with the mocked one, keep internal
(Inherited from Mock.) |
![]() | Clear |
Clear all expectations
(Inherited from Mock.) |
![]() | Clear(String) |
Clear expectation of a method
(Inherited from Mock.) |
![]() | Clear(ExpectationBlock) |
Clear expectation of an expectation block
(Inherited from Mock.) |
![]() | EndBlock |
End an expectation block
(Inherited from Mock.) |
![]() | Equals | (Inherited from Object.) |
![]() | ExpectAddEvent(String) |
Expect 1 event listener to be added (event += new EventHandler())
(Inherited from Mock.) |
![]() | ExpectAddEvent(String, Int32) |
Expect a number of event listeners to be added (event += new EventHandler())
(Inherited from Mock.) |
![]() | ExpectAddEventAlways |
Expect unlimited number of event listeners to be added (event += new EventHandler())
(Inherited from Mock.) |
![]() | ExpectAlways |
Expect unlimited calls from method
(Inherited from Mock.) |
![]() | ExpectAndReturn(String, Object, Type) |
Expect 1 call from method, and mock return value
(Inherited from Mock.) |
![]() | ExpectAndReturn(String, Object, Int32, Type) |
Expect a number of calls from method, and mock return value
(Inherited from Mock.) |
![]() | ExpectAndThrow(String, Exception, Type) |
Expect 1 call from method, and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectAndThrow(String, Exception, Int32, Type) |
Expect a number of calls from method, and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectCall(String, Type) |
Expect 1 call from method
(Inherited from Mock.) |
![]() | ExpectCall(String, Int32, Type) |
Expect a number of calls from method
(Inherited from Mock.) |
![]() | ExpectCallAndVerify | Obsolete.
Verify 1 call from method , continue with method as normal
(Inherited from Mock.) |
![]() | ExpectConstructor |
Mock Constructor
(Inherited from Mock.) |
![]() | ExpectConstructor(Int32) |
Mock Constructor
(Inherited from Mock.) |
![]() | ExpectConstructorAlways |
Mock unlimited calls from Constructor
(Inherited from Mock.) |
![]() | ExpectConstructorAndThrow |
Mock Constructor and throw exception when constructor is called
(Inherited from Mock.) |
![]() | ExpectGet(String, Object) |
Expect 1 get of a Property and mock the Property's value
(Inherited from Mock.) |
![]() | ExpectGet(String, Object, Int32) |
Expect a number of gets of a Property and mock the Property's value
(Inherited from Mock.) |
![]() | ExpectGetAlways |
Expect unlimited get of a Property and always mock the Property's value
(Inherited from Mock.) |
![]() | ExpectGetAndAlwaysThrow |
Expect unlimited get of a Property and always mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectGetAndThrow(String, Exception) |
Expect 1 get of a Property and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectGetAndThrow(String, Exception, Int32) |
Expect a number of gets of a Property and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectGetIndex(Object) |
Expect 1 get of an Index and mock the index value
(Inherited from Mock.) |
![]() | ExpectGetIndex(Object, Int32) |
Expect a number of get of an Index and mock the index value
(Inherited from Mock.) |
![]() | ExpectGetIndexAlways |
Expect unlimited set of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectGetIndexAndAlwaysThrow |
Expect unlimited set of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectGetIndexAndThrow(Exception) |
Expect 1 get of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectGetIndexAndThrow(Exception, Int32) |
Expect a number of gets of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectRemoveEvent(String) |
Expect 1 event listener to be removed (event -= new EventHandler())
(Inherited from Mock.) |
![]() | ExpectRemoveEvent(String, Int32) |
Expect a number of event listeners to be removed (event -= new EventHandler())
(Inherited from Mock.) |
![]() | ExpectSet(String) |
Expect 1 set of a Property
(Inherited from Mock.) |
![]() | ExpectSet(String, Int32) |
Expect a number of sets of a Property
(Inherited from Mock.) |
![]() | ExpectSetAlways |
Expect unlimited set of a Property
(Inherited from Mock.) |
![]() | ExpectSetAndAlwaysThrow |
Expect unlimited set of a Property and always mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectSetAndThrow(String, Exception) |
Expect 1 set of a Property and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectSetAndThrow(String, Exception, Int32) |
Expect a number of sets of a Property and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectSetIndex |
Expect 1 set of an Index
(Inherited from Mock.) |
![]() | ExpectSetIndex(Int32) |
Expect a number of sets of an Index
(Inherited from Mock.) |
![]() | ExpectSetIndexAlways |
Expect unlimited set of an Index
(Inherited from Mock.) |
![]() | ExpectSetIndexAndAlwaysThrow |
Expect unlimited set of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectSetIndexAndThrow(Exception) |
Expect 1 set of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectSetIndexAndThrow(Exception, Int32) |
Expect a number of sets of an Index and mock throwing an exception
(Inherited from Mock.) |
![]() | ExpectUnmockedCall(String, Type) |
Verify 1 call from method , continue with method as normal
(Inherited from Mock.) |
![]() | ExpectUnmockedCall(String, Int32, Type) |
Verify a number of calls from method , continue with method as normal
(Inherited from Mock.) |
![]() | ExpectUnmockedConstructor |
Don't Mock Constructor but verify arguments
(Inherited from Mock.) |
![]() | ExpectUnmockedConstructor(Int32) |
Don't Mock Constructor but verify arguments
(Inherited from Mock.) |
![]() | ExpectUnmockedGet(String) |
Verify 1 get of a Property , continue with get method as normal
(Inherited from Mock.) |
![]() | ExpectUnmockedGet(String, Int32) |
Verify a number of gets of a Property , continue with get method as normal
(Inherited from Mock.) |
![]() | ExpectUnmockedSet(String) |
Verify 1 set of a Property , continue with set method as normal
(Inherited from Mock.) |
![]() | ExpectUnmockedSet(String, Int32) |
Verify a number of sets of a Property , continue with set method as normal
(Inherited from Mock.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetBlock |
Retrieve Expectation Block, by its label name
(Inherited from Mock.) |
![]() | GetCallCount(String) |
Return the amount of times a method has been called
(Inherited from Mock.) |
![]() | GetCallCount(String, Type) |
Return the amount of times a method has been called
(Inherited from Mock.) |
![]() | GetCallIndexerCounter |
Return the amount of times an indexer has been called
(Inherited from Mock.) |
![]() | GetCallPropertyGetCounter |
Return the amount of times a property has been called
(Inherited from Mock.) |
![]() | GetCallPropertySetCounter |
Return the amount of times a property has been set
(Inherited from Mock.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MethodSettings |
Perform Behavior tweaking on methods rather then the whole mocked type
(Inherited from Mock.) |
![]() | MethodSettingsGetIndex |
Perform Behavior tweaking on methods rather then the whole mocked type
(Inherited from Mock.) |
![]() | MethodSettingsGetProperty |
Perform Behavior tweaking on methods rather then the whole mocked type
(Inherited from Mock.) |
![]() | MethodSettingsSetIndex |
Perform Behavior tweaking on methods rather then the whole mocked type
(Inherited from Mock.) |
![]() | MethodSettingsSetProperty |
Perform Behavior tweaking on methods rather then the whole mocked type
(Inherited from Mock.) |
![]() | MockConstructor | Obsolete.
Mock Constructor
(Inherited from Mock.) |
![]() ![]() | MockField | Create a Mock object and assign it to a given field. (Inherited from Mock.) |
![]() | RemoveStaticCtor |
Remobing static constructer, keep internal
(Inherited from Mock.) |
![]() | StartBlock |
Start an expectation block
(Inherited from Mock.) |
![]() | StartBlock(String) |
Start an expectation block with a label name
(Inherited from Mock.) |
![]() | StartBlock(VerifyMode) |
Start an expectation block with a verify mode
(Inherited from Mock.) |
![]() | StartBlock(String, VerifyMode) |
Start an expectation block with a label and a verify mode
(Inherited from Mock.) |
![]() | StartBlockBefore(ExpectationBlock) |
Start an expectation block and adds the expectations before another expectation
block
(Inherited from Mock.) |
![]() | StartBlockBefore(ExpectationBlock, String) |
Start an expectation block with a label and adds the expectations before another expectation
block
(Inherited from Mock.) |
![]() | StartBlockBefore(ExpectationBlock, VerifyMode) |
Start an expectation block with a verify mode and adds the expectations before another expectation
block
(Inherited from Mock.) |
![]() | StartBlockBefore(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.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | Verify |
Verify mocked type
(Inherited from Mock.) |
![]() | VerifyWithTimeout |
Wait with timeout (5 seconds) for all expected methods to be called
(Inherited from Mock.) |
![]() | VerifyWithTimeout(Int32) |
Wait with timeout (im milliseconds) for all expected methods to be called
(Inherited from Mock.) |
Events
Name | Description | |
---|---|---|
![]() | MockMethodCalled |
Event that is fired after a mocked method is called and after argument validation is performed
MockMethodCalledEventHandler (Inherited from Mock.) |
Remarks
- Set Up - This is the stage where you 'record' what the mocked type/object expects to do and what to return
- Run - Run the actual class under test
- Verify - Make sure that the mocked object acted as expected
These phases are managed by the Mock object.
![]() |
---|
You cannot create a MockObject directly use MockManager.MockObject(Type, Object) |
![]() |
---|
You can create a mock object from abstract classes and interfaces. Typemock Isolator will dynamically create a new concrete Type that implements the abstract methods and will return an instance of the derived type when the Object is called. When creating a mock object of a concrete type, Typemock Isolator will create an instance of that type, and return the instance when the Object is called. This way you can mock sealed classes too. When mocking a method that is declared in a base class, Typemock Isolator will automatically create a mock for the base class and the mock definitions are propagated to this mock (Strict and MockConstructors). Note that if a base method is mocked all calls to the method are mocked even though they are called from derived classes |
See Also