Created
September 18, 2013 05:25
-
-
Save dtchepak/6604890 to your computer and use it in GitHub Desktop.
Example from NSub list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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