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
+2 votes

Hi,

I am having toruble with veryfing matching argumetns for recursive fake object.

The "args" in matching predicate is empty object array ( {object[0]} ), therefore getting IndexOutOfRangeException.

When debugging, I see "createParameters.GetField(details.Name, details.Step.Name);" returned  fakeStepInputField.

This is code in my Unit Test:


    // ARRANGE
    var fakeDetails = Isolate.Fake.NextInstance<WorkflowStep.DetailsSection>();

    Isolate.WhenCalled(() => fakeDetails.Name).WillReturn("Details");
    Isolate.WhenCalled(() => fakeDetails.Step.Name).WillReturn("Step");

    var fakeCreateParameters = Isolate.Fake.Instance<CreateParameters>();
    var fakeStepInputField = Isolate.Fake.Instance<InputField>();

    Isolate.WhenCalled(() => fakeCreateParameters.GetField("Details", "Step")).WithExactArguments().WillReturn(fakeStepInputField);

    var controller = new StepController();

    // ACT
    controller.Create(fakeCreateParameters);

    // ASSERT
    Isolate.Verify.WasCalledWithArguments(() => fakeDetails.Step.SetReceivedValue(null)).Matching(
        args =>
	{
             return (InputField) args[0] == fakeStepInputField;
        });

 

The code under test:

    public class StepController
    {
        public void Create(CreateParameters createParameters)
        {
            var details = new WorkflowStep.DetailsSection();
			
            var stepInputField = createParameters.GetField(details.Name, details.Step.Name);
            details.Step.SetReceivedValue(stepInputField);
			
            // ...
        }
    }

Thanks.

asked by Ctvt (2.7k points)
edited by Ctvt

Please log in or register to answer this question.

...