Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created September 18, 2013 05:25
Show Gist options
  • Save dtchepak/6604890 to your computer and use it in GitHub Desktop.
Save dtchepak/6604890 to your computer and use it in GitHub Desktop.
Example from NSub list
using System.Collections.Generic;
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using Shouldly;
namespace Workshop
{
public class NSubMisc
{
public interface ICommand { }
private class DerivedCommand : ICommand { }
public interface IInterface { void SendCommand(ICommand c); }
[Test]
public void TestWhenDo()
{
var commands = new List<ICommand>();
var sub = Substitute.For<IInterface>();
sub.When(x => x.SendCommand(Arg.Any<ICommand>())).Do(c => commands.Add(c.Arg<ICommand>()));
var c1 = new DerivedCommand();
var c2 = Substitute.For<ICommand>();
sub.SendCommand(c1);
sub.SendCommand(c2);
commands.Select(x => x).ShouldBe(new[] {c1, c2});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment