Creating Custom Expectations in DotNetMock
------------------------------------------
     
This document details the creation of a Custom Expectation using the DotNetMock? framework. 

To create a custom expectation, follow the below steps. 


1) Create a new class that subclasses from DotNetMock.AbstractExpectation. In the new class, create a constructor that takes a string parameter and calls the base constructor with the same method sig. For example: 

public CustomExpectation( string name ) : base( name ) { 
} 


2) Create two private variables that will hold the actual & expected values for this expectation. The constructor call in the base AbstractExpectation? will make calls to ClearActual() & ClearExpected(), so make sure the variables are initialized. 

3) Depending on your needs, add accessibility properties for the private variables created in the previous step. Any set method for the expected value should include a call to AbstractExpectation.HasExpectations, passing in true for the property value. 

4) Override the ClearActual() & ClearExpected() methods from the AbstractExpectation class. These methods should reset both the expected and actual values of the expectation, according to your needs. 

5) Lastly, override the AbstractExpectation.Verify() method. This method will be responsible for comparing the expected and actual values of the expectation. This can be as simple as a arithmetic operation, or it can be a complex Equals() implementation by the custom objects you are comparing. The only requirement is that an exception should be thrown in the case of inequality. 

At this point, the expectation is ready to use in your Mock Objects. 

For more information, check out DotNetMock.Examples for a complete example of a Custom Expectation. 

Any other questions or support issues should be submitted to http://www.sourceforge.net/projects/dotnetmock

--Griffin
( gcaprio@users.sourceforge.net )