How to mock the "out" parameter?

I downloaded the latest version of NSubstitute, 1.1.0, May 21, 2011. Prior to this release, NSub did not seem to support parameters. It looks like some work was done to support through an interim release: NSub Google Group .

So, I have a little problem trying to get all the parts to work. I use SystemWrapper to trick DirectoryInfo

Here is my interface:

public interface INetworkPath { void SetPath(string NetworkPath); bool TryGetDirectoryInfo(out IDirectoryInfoWrap DirectoryInfo); } 

... and test:

 public void SetNetworkPath_SetDirectoryInfo() { var netPath = Substitute.For<INetworkPath>(); netPath.SetPath("SomeNetworkPath"); IDirectoryInfoWrap DirectoryInfo; netPath.TryGetDirectoryInfo(out DirectoryInfo) .Returns(d => { // cannot convert lambda expression to type bool because it is not a delegate type d[1] = Substitute.For<IDirectoryInfoWrap>(); // d[1] is read only return true; }); Assert.IsNotNull(DirectoryInfo); } 

Is there a way to trick the out parameter from the INetworkPath interface?

Refresh

Tried the following: although it compiles, DirectoryInfo returns null:

 [Test] public void SetNetworkPath_SetDirectoryInfo() { var netPath = Substitute.For<INetworkPath>(); netPath.SetPath("SomeNetworkPath"); IDirectoryInfoWrap DirectoryInfo; netPath.TryGetDirectoryInfo(out DirectoryInfo) .Returns(d => { d = (CallInfo)Substitute.For<IDirectoryInfoWrap>(); return true; }); Assert.IsNotNull(DirectoryInfo); } 
+4
source share
1 answer

I do not believe that the implementation you are looking for was released using 1.1, but later ( Link and support support ). You may have to pull the code and build it yourself.

+2
source

All Articles