ExpectationBlock Class

Typemock Isolator Developer Guide
An expectation block (Enterprise Edition Only)
Inheritance Hierarchy

SystemObject
  TypeMockExpectationBlock

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

public class ExpectationBlock

Return Value

Type: 
The Expectation Block

The ExpectationBlock type exposes the following members.

Properties

  NameDescription
Public propertyName
Return the default expectation block
Top
Methods

  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
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 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 methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
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:

  1. Remove the block using Mock.Clear(ExpectationBlock).
  2. Add expectations before the block using Mock.StartBlockBefore(ExpectationBlock).
Blocks can be labeled and can be later on referred to by Mock.GetBlock(String). Blocks can have different VerifyModes.
Examples

The following example shows a utility method that sets up expectations for an AccessController
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

Reference