-
-
Save JakeGinnivan/1852112 to your computer and use it in GitHub Desktop.
Testing IObservable processing
This file contains 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
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