Complete support for byref arguments


We are mocking Visual Studio SDK API which involves a lot of calls with byref arguments (both in and out). Using SetupByName isn't enough since there might be multiple overloads, and these calls might be in a C# project. We tried
let documentFactoryService = 
            .Calls<ITextBuffer * byref<ITextDocument>>(fun (textBuffer, textDocument) ->
                    textBuffer.Properties.TryGetProperty(typeof<ITextDocument>, &textDocument))
but F# compiler doesn't like byref arguments inside quotations (see https://github.com/fsprojects/VisualFSharpPowerTools/pull/606 for a few examples).

Sometimes I'm able to use SetUpByName and return tuples, but Foq code generation crashes NUnit test runners.

We have a few examples involving byref arguments e.g. https://github.com/fsprojects/VisualFSharpPowerTools/blob/master/tests/FSharpVSPowerTools.Tests/Mocks.fs so that you know what usage we are looking for. We would love to be able to replace these handwritten object expressions by Foq calls. Their uses are in https://github.com/fsprojects/VisualFSharpPowerTools/blob/master/tests/FSharpVSPowerTools.Tests/VsTestBase.fs.


ptrelford wrote Aug 12, 2014 at 9:09 AM

The latest change set includes initial support for passing byref args as values to Calls via SetupByName.

dungpa wrote Aug 12, 2014 at 5:24 PM

It would be great if you can live debug on our examples above. It might be more tricky than examples in current test cases.