An expectation block (Enterprise Edition Only)
Inheritance Hierarchy
TypeMockExpectationBlock
Namespace: TypeMock
Assembly: TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax
Return Value
Type:The Expectation Block
The ExpectationBlock type exposes the following members.
Properties
Name | Description | |
---|---|---|
![]() | Name |
Return the default expectation block
|
Methods
Name | Description | |
---|---|---|
![]() | 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.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Remarks
Group a number of expectation. Define an expectation block using Mock.StartBlock and Mock.EndBlock. When grouping expectations in a block you can control The expectation dynamically. This is very useful when setting up a mock infrastructure. After defining a block it is possible to:
- Remove the block using Mock.Clear(ExpectationBlock).
- Add expectations before the block using Mock.StartBlockBefore(ExpectationBlock).
Examples
private Mock SetupExpectations() { //Mock all invocation of AccessController, Mock mock = MockManager.MockAll(typeof(AccessController)); // start a block called loginLabel, this will be verified normally mock.StartBlock("loginLabel",VerifyMode.Normal); // We expect that the login method will be called and we will return // AccessStatus.INVALID_USER the first time and AccessStatus.VALIDATED the // second time mock.ExpectAndReturn("Login", AccessStatus.INVALID_USER); mock.ExpectAndReturn("Login", AccessStatus.VALIDATED); mock.EndBlock(); // expect another call and return validated. mock.ExpectAndReturn("Login", AccessStatus.VALIDATED); return mock; } [Test] public void TestSomething() { Mock mock = SetupExpectations(); // In this test we need to add an expectation before our block mock.StartBlockBefore(mock.GetBlock("loginLabel")); mock.ExpectAndReturn("Login", AccessStatus.VALIDATED); mock.EndBlock(); // continue with test } [Test] public void TestSomething2() { Mock mock = SetupExpectations(); // In this test we need to remove the expectation our block mock.Clear(mock.GetBlock("loginLabel")); // continue with test }
See Also