Use to mock all anonymous methods that are called from within a method
Namespace: TypeMock
Assembly: TypeMock (in TypeMock.dll) Version: 9.3.6.0 (9.3.6.0)
Syntax
Parameters
- calledFromMethod
- Type: SystemString
Method from which the anonymous method is called
Return Value
Type: StringAnonymous Method Mock Name
Implements
IMockControlAnonymousMethodOf(String)Examples
C#
public void DoSomething() { button1.Click += delegate { MessageBox.Show("Click!"); }; } public void FireClick() { button1.PerformClick(); }
C#
[Test] public void AnonymousTest() { // Mock TestedClass Mock mock = MockManager.Mock(typeof(TestedClass)); // set up our expectations for anonymous method called in DoSomething // check that the delegate will be called without displaying the message box mock.ExpectCall(mock.AnonymousMethod("DoSomething")); // create the instances TestedClass tested = new TestedClass(); // Test the code tested.DoSomething(); tested.FireClick(); // Verify that all calls were made (This can be done in the [Teardown]) MockManager.Verify(); }
See Also