Start an expectation block
Namespace: TypeMock
Assembly: TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax
Return Value
Type: ExpectationBlockThe Expectation Block
Remarks
Group a number of expectation. 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 Clear(ExpectationBlock).
- Add expectations before the block using 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