Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Forked from shiftkey/gist:1852096
Created February 17, 2012 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeGinnivan/1852112 to your computer and use it in GitHub Desktop.
Save JakeGinnivan/1852112 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()
{
//Imagine provider is a KeyTokeniser
var matches = Drain(provider, ()=>CtrlShiftL());
Assert.Equal("Ctrl + Shift + L", matches.Single().ToString());
Assert.True(matches.Single().IsShortcut);
Assert.True("Locate File in Solution", matches.Single().ShortcutDescription);
}
public void CtrlShiftL()
{
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)
};
Push(keys);
}
public void Push(IEnumerable<InterceptKeyEventArgs> keys)
{
foreach (var key in keys)
{
subject.OnNext(key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment