Assign Class

Typemock Isolator Developer Guide
Passing this class as to Args as a Parameter Checker to mock ref and out parameters. Enterprise Edition users can swap normal argument too. See IParameters
Inheritance Hierarchy

SystemObject
  TypeMockAssign

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

public class Assign

The Assign type exposes the following members.

Constructors

  NameDescription
Public methodAssign
Create a new Assign object that will mock ref and out arguments
Top
Methods

  NameDescription
Public methodAndCheck
Validate the parameter before assigning it a value.
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.)
Public methodIsCheckingSameType
A boolean method the checks if the "other" object is the same type as the object that called the method.
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

Use this class to mock ref and out parameters. Enterprise Edition Users can use the Assign class to replace arguments of a method at run time. This is useful in conjunction with Mock.ExpectUnmockedCall(String, Type) and complex types, where it is easier to change an argument then to mock all the methods. Here is an example of using Assign
[Test]
public void CheckRefAndOut() 
{
    Mock mock = MockManager.Mock(typeof(TestedClass));
    TestedClass t = new TestedClass();
    // Check that first arg is "rr" and assign it with "changed"
    // Assign the second arg with 3, don't check (same as Check.IsAny())
    mock.ExpectCall("SomeMethod").Args(new Assign("changed").AndCheck("rr"), new Assign(3));
    int a ;
    string s = "rr";
    t.SomeMethod(ref s,out a);
    Assert.AreEqual(3,a);
    Assert.AreEqual("changed",s);
    MockManager.Verify();
}
Another way to assign ref and out parameter is by using the DynamicReturnValue
Note Note
Typemock Isolator doesn't check that the parameter is actually passed by ref
Note Note
Assign will might work correctly for un-mocked expectations. See CONTINUE_WITH_METHOD
Note Note
Assigning arrays is currently not supported
See Also

Reference