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 => {
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); }
source share