chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Some code I want to test is making use of an implicit operator and I can't find any way to have it return a mock object. The implicit operator is sort of a static method, but I can't refer to it explicitly... And I don't see anything in the Typemock docs covering operators. Anyone know if this is even possible, or have any suggestions?
asked by zakzak (600 points)

1 Answer

0 votes

Please see the example below:

Under Test:
public class MyClass
    public static implicit operator int(MyClass d)
        return 0;

public void TestMethod2()
    var myClass = new MyClass();
    int num = 1;

    Isolate.WhenCalled(() => num = myClass).WillReturn(5);
    num = myClass;

    Assert.AreEqual(5 , num);

Let me know if it helps.
answered by alex (17k points)