Thanks for clarifying. Just checked the group and it looks like it flagged your earlier response for some reason (and didn't notify me :( ). Sorry about that!
In this case I don't think we need to test that the underlying code gets the 1234 value correctly. It can be assumed that NSubstitute will take care of that via the `x[1] = expectedValue;` line (we have our own tests that assert this works. See [1]). So once we've configured the substitute to set this value, we don't need to test that this is the value that comes back to our calling code.
In terms of the `Received` call, passing `expectedValue` of `1234` fails because the actual call was `lookup.TryLookup("hello", out {reference to an uninitialised int}`. It did not receive `lookup.TryLookup("hello", out {reference to an int holding 1234}`. This becomes more important when we consider values passed using `ref`, as the initial value given can be used by the called method so we need to make sure that value is correct (we use the same mechanism for `out`, which is why we have the same behaviour there).
In terms of updating this test, the fix is to pass an argument that better resembles the one it actually received:
int blankValue;
lookup.Received().TryLookup("hello", out blankValue);
This matches the `LookupAdapter` call very closely. Or, with the current C# compiler, just:
lookup.Received().TryLookup("hello", out int blankValue);
If we expand the example with an additional step of using the value from the lookup then I think it becomes a bit simpler:
notify.Received().Push(expectedValue);
lookup.Received().TryLookup("hello", out int blank); // <-- Do NOT actually need this.
}
Now we're testing that the `LookupAdapter` correctly used the stubbed value from the `ILookup` dependency by passing it to the `INotification` instance when the key is "hello" and the lookup was successful. (We should also test when the lookup fails, and when the key is not "hello").
Note that we no longer even need to explicitly test `lookup.Received().TryLookup(...)`, as it can be inferred by the fact that `expectedValue` ended up getting passed to the `INotification` instance. I almost always avoid "double testing" in this way in an attempt to avoid over-specifying the tests (which makes them more brittle).
Hope this helps. If I haven't answered your question sufficiently please let me know and I'll go in to more detail. :)
Regards,
David