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
0 votes
Can you use Isolate.Verify.WasCalledWithExactArguments and verfiy only the first parameter of the method you are checking? For instance, if I have a method that takes four parameters, but I'm only interested in verifying the first parameter.
asked by burtfin (1.1k points)

1 Answer

0 votes
Hi,

It's possible to verify the parameter using DoInstead functionality. When DoInstead is called you can save the parameters you wish to verify against.

For example:
public class UnderTest
{
    readonly Random numberGenerator = new Random();

    public void PerformAction()
    {
        int nextRandomNumber = numberGenerator.Next(1,100);
        PerformActionWithParameters(1, nextRandomNumber);
    }

    public void PerformActionWithParameters(int known, int random)
    {

    }
}

[TestClass]
public class TestClass
{
    [TestMethod]
    public void PerformAction_ObjectAskedToPerformAction_KnownParameterIsOne()
    {
        int actualKnown = 0;
        var underTest = Isolate.Fake.Instance<UnderTest>(Members.CallOriginal);
        Isolate.WhenCalled(() => underTest.PerformActionWithParameters(0, 0))
            .DoInstead(context => actualKnown = (int) context.Parameters[0]);

        underTest.PerformAction();

        Assert.AreEqual(1, actualKnown);
    }
}


Please let me know if it helps.

Best Regards,
Elisha
Typemock Support Team
answered by Elisha (12k points)
...