Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created February 17, 2012 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shiftkey/1852096 to your computer and use it in GitHub Desktop.
Save shiftkey/1852096 to your computer and use it in GitHub Desktop.
Testing IObservable processing
public class ExampleTest
{
private readonly List<KeyPress> outputs;
private readonly KeyProvider provider;
private readonly Subject<InterceptKeyEventArgs> subject;
private IProcessLookup processLookup;
public ExampleTest()
{
outputs = new List<KeyPress>();
subject = new Subject<InterceptKeyEventArgs>();
processLookup = Substitute.For<IProcessLookup>();
provider = new KeyProvider(subject, processLookup);
provider.Subscribe(outputs.Add);
}
[Fact]
public void this_is_how_to_write_a_carnac_test()
{
var keys = new List<InterceptKeyEventArgs>
{
new InterceptKeyEventArgs(Keys.LControlKey, KeyDirection.Down, false, false, false),
new InterceptKeyEventArgs(Keys.LShiftKey, KeyDirection.Down, false, true, false),
new InterceptKeyEventArgs(Keys.L, KeyDirection.Down, false, true, true),
new InterceptKeyEventArgs(Keys.L, KeyDirection.Up, false, true, true),
new InterceptKeyEventArgs(Keys.LShiftKey, KeyDirection.Up, false, true, true),
new InterceptKeyEventArgs(Keys.LControlKey, KeyDirection.Up, false, true, false)
};
foreach (var key in keys)
{
subject.OnNext(key);
}
Assert.True(outputs.Count == 6); // we're not actually testing anything here, right? ShellViewModel is the bits you want to test.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment