TypeMockMockManager
Namespace: TypeMock
Assembly: TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
The MockManager type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | Any | Obsolete.
Obsolete, use Check.IsAny instead,
Provided for backward compatibility
|
![]() ![]() | CollectAllCalls |
When set Typemock Isolator collects data on ALL method entries, this can then be verified
using CalledCounter(String, String) |
![]() ![]() | CONTINUE_WITH_METHOD |
If CONTINUE_WITH_METHOD is returned the mocked method will continue with
normal execution. This is an un-mocked expectation that will verify that a method is called only
without mocking the method.
|
![]() ![]() | InSpecialLicenseChain |
A property that indicates if the licence is part of a special Isolator package.
|
![]() ![]() | IsInitialized |
Check if Typemock Isolator is initialized Init |
![]() ![]() | Locked | |
![]() ![]() | LogFile | Obsolete. |
![]() ![]() | ValidateArgsOnVerify | Obsolete.
Obsolete. Argument validation is now done both on calling the method and during Verify automatically.
Postpone throwing validation errors till Verify is called
|
![]() ![]() | Version |
Return Typemock Isolator version
|
Name | Description | |
---|---|---|
![]() ![]() | CalledCounter(String, String) |
Return the amount of times a method has been called
|
![]() ![]() | CalledCounter(Type, String) |
Return the amount of times a method has been called
|
![]() ![]() | CalledCounter(Type, String, Type) |
Return the amount of times a method has been called
|
![]() ![]() | CalledCounterTMockType(String) |
Return the amount of times a method has been called
|
![]() ![]() | CalledCounterTMockType(String, Type) |
Return the amount of times a method has been called
|
![]() ![]() | CalledIndexerCounter |
Return the amount of times an indexer has been called
|
![]() ![]() | CalledPropertyGetCounter |
Return the amount of times a property has been called
|
![]() ![]() | CalledPropertySetCounter |
Return the amount of times a property has been set
|
![]() ![]() | ClearAll |
Clears all expectations and mocks
|
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetInstanceMocks(Type) |
Returns a list of instance mocks of a type
|
![]() ![]() | GetInstanceMocksTMockedType |
Returns all instance mocks for TMockedType
|
![]() ![]() | GetMockAll(Type) |
Returns the mock for all instances of a type, or null if it is not mocked
|
![]() ![]() | GetMockAllTMockedType |
Returns all instances mock of TMockedType
|
![]() ![]() | GetMockedTypes |
Returns all types that are mocked
|
![]() ![]() ![]() | GetMockOfT |
Returns the mock associated with a specific instance
|
![]() ![]() | GetMocks |
Returns all mocks
|
![]() ![]() | GetMocks(Type) |
Returns all mocks for a type
|
![]() ![]() | GetMocksTMockedType |
Returns all mocks for TMockedType
|
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | Init |
Defaults to collect call information ONLY for mocked classes and
not verbose
|
![]() ![]() | Init(Boolean) |
Manually set Call Collection and verbose behaviors
|
![]() ![]() | IsTypeMocked(Type) |
Check if a type is mocked (with MockAll or instance mocks)
|
![]() ![]() | IsTypeMockedTMockedType |
Check if a type is mocked (with MockAll or instance mocks)
|
![]() ![]() | IsTypeMockedAll(Type) |
Check if a type is mocked for all instances
|
![]() ![]() | IsTypeMockedAllTMockedType |
Check if a type is mocked for all instances
|
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | Mock(Type) |
Automatically mock constructors as well, i.e. constructor code will NOT be called
|
![]() ![]() | Mock(Type, Boolean) | Obsolete.
Create a new Type Mock to intercept and mock calls made on the next instance of a type,
with ability to decide if Constructors should be mocked or not (default is to mock constructors)
|
![]() ![]() | Mock(Type, Constructor) |
Create a new Type Mock to intercept and mock calls made on the next instance of a type,
with ability to define the scope of mocked Constructors (default is to mock all constructors)
|
![]() ![]() | MockTMockedType |
Intercept and mock calls made on the next new instance of TMockedType.
|
![]() ![]() | MockTMockedType(Constructor) |
Intercept and mock calls made on the next new instance of TMockedType, with constructor behavior control
|
![]() ![]() | MockAll(Type) |
Automatically mock constructors as well, i.e. constructor code will NOT be called
|
![]() ![]() | MockAll(Type, Boolean) |
Create a new Type Mock for all instances of the type, with ability to decide if Constructors should be mocked or not
|
![]() ![]() | MockAll(Type, Constructor) |
Create a new Type Mock for all instances of the type, with ability to to define the scope of mocked Constructors (default is to mock all constructors)
|
![]() ![]() | MockAllTMockedType |
Intercept and mock calls made on the all instance of TMockedType.
|
![]() ![]() | MockAllTMockedType(Constructor) |
Intercept and mock calls made on the all instance of TMockedType, with constructor behavior control
|
![]() ![]() | MockGlobalFunctions |
Use this type when mocking global functions
|
![]() ![]() | MockObject(Type, Boolean) | Obsolete.
Create a new Dynamic Mock Object with ability to decide if Constructors should be mocked or not
|
![]() ![]() ![]() | MockObject(Type, Object) |
Automatically mock constructors as well, i.e. constructor code will NOT be called
|
![]() ![]() | MockObject(Type, Constructor, Object) |
Create a new Dynamic Mock Object with ability to define the scope of mocked Constructors (default is to mock all constructors)
|
![]() ![]() | MockObjectTMockedType |
Create an instance of TMockedType and mock calls made on the instance.
|
![]() ![]() | MockObjectTMockedType(Object) |
Create an instance of TMockedType and mock calls made on the instance, while sending constructor arguments
|
![]() ![]() | MockObjectTMockedType(Constructor) |
Create an instance of TMockedType and mock calls made on the instance, while controlling the constructor
|
![]() ![]() | MockObjectTMockedType(Constructor, Object) |
Create an instance of TMockedType and mock calls made on the instance, while controlling the constructor and sending constructor arguments
|
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() ![]() | Verify |
Verify all mocked types
|
![]() ![]() | VerifyWithTimeout |
Wait with timeout (5 seconds) for all expected methods to be called
|
![]() ![]() | VerifyWithTimeout(Int32) |
Wait with timeout (im milliseconds) for all expected methods to be called
|
Name | Description | |
---|---|---|
![]() ![]() | DynamicMocksAssembly |
Mock object tests replace domain dependencies with mock implementations used only for testing. This strategy does, however, present a technical challenge in certain situations, as the Mock objects can only mock interfaces, and these mocks have to be passed to the function, so no internal instantiation of classes can be mocked
Typemock Isolator to provide "type" mock objects. No concrete mock objects are actually created, but rather Typemock Isolator is used to weave interceptions into all code that is not part of the class under test. In this way, every method call is intercepted. If the method call is one for which mock data has been declared, then that mock data is returned in place of the actual method being run.
For example a LoginView (the class being tested) which as properties of userID and password that are set prior to calling a validate method. Following that call, the status attribute will be set to a string value that is ultimately displayed to the user. The LoginView is responsible for interpreting the status code (USER_VALID, NO_PASSWORD, NO_USERID, INVALID_USER) that is returned from an AccessController, to determine the status message to display.
public string Validate() { AccessController controller = new AccessController(); AccessStatus status = controller.Login(m_UserID,m_Password); switch (status) { case USER_VALID: ... } return returnStatus; }
However, the LoginView class makes use of the login service provided by the AccessController class. The AccessController will probably itself use other components to authenticate the user. For the tests to work it would be necessary to create some test users in the system. The tests that were written to test the behavior of LoginView would in fact also be testing the AccessController, which should of course have its own suite of tests.
The behavior we are trying to test here is to determine that the user gets the correct status message for the different cases of invalid or missing user credentials returned by the AccessController and not the actual validation of those credentials.
Using Typemock Isolator We can intercept the AccessController and return our own value[Test] public void ValidateValidUser() { //Mock all invocation of AccessController, all calls to this class, are //intercepted. Mock mock = MockManager.Mock(typeof(AccessController)); //We expect that the login method will be called (once) and we will return //AccessStatus.INVALID_USER. mock.ExpectAndReturn("Login", AccessStatus.INVALID_USER); LoginView view = new LoginView(); view.setUserID("jane"); view.setPassword("passAugust"); // run the method being tested view.Validate(); Assert.AreEqual("login successful", view.Status); // Verify that all the expected calls have actually been called. MockManager.Verify(); }
![]() |
---|
To enable mock manager do one of the following
|