jeudi 31 mars 2016

Can I change the input parameter value in a Moq.Callback() if it is a reference type?

I'm doing a unit test where the interesting part looks like this

_filter.Setup(x => x.Filter(It.IsNotNull<List<MyObject>>()))
            .Callback<List<MyObject>>(input => 
            {
                // input has two items while filteredObjects have one item.
                input = filteredObjects;
            });

The code

List<MyObject> myObjects = _repo.GetTheUnfilteredObjects(); // returns two items

// void
_filter.Filter(myObjects); 
// still two items

When I debug the test I can step into the moq callback method and see that it sets the input parameter to the new value (in this case a list of one item instead of two items as it was before). When I step on and looks in the method I test the property myObjects hasn't changed, it's still two items.

The question is, is it possible for me to set the parameter's value inside the callback method since it is a reference type? Thanks!

Aucun commentaire:

Enregistrer un commentaire