-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from tmezups/deftsharp-keyboardbindertests
Add tests for KeyBoardBinder resolves #12
- Loading branch information
Showing
1 changed file
with
136 additions
and
0 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
DeftSharp.Windows.Input.Tests/Keyboard/KeyboardBinderTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System.Windows.Input; | ||
using DeftSharp.Windows.Input.Keyboard; | ||
|
||
namespace DeftSharp.Windows.Input.Tests.Keyboard; | ||
|
||
public class KeyboardBinderTests | ||
{ | ||
private readonly WPFEmulator _emulator; | ||
|
||
public KeyboardBinderTests() | ||
{ | ||
_emulator = new WPFEmulator(); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_IsKeyBound() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
keyboardBinder.Bind(Key.A, Key.B); | ||
Assert.True(keyboardBinder.IsKeyBounded(Key.A)); | ||
Assert.False(keyboardBinder.IsKeyBounded(Key.B)); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_IsKeyBoundWhenBindingTheSameKey() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
keyboardBinder.Bind(Key.C, Key.C); | ||
Assert.False(keyboardBinder.IsKeyBounded(Key.C)); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_BindMultipleKeysAtOnce() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
var keys = new List<Key> | ||
{ | ||
Key.W, | ||
Key.X, | ||
Key.Y, | ||
Key.Z | ||
}; | ||
keyboardBinder.BindMany(keys, Key.A); | ||
Assert.True(keyboardBinder.IsKeyBounded(Key.W)); | ||
Assert.True(keyboardBinder.IsKeyBounded(Key.X)); | ||
Assert.True(keyboardBinder.IsKeyBounded(Key.Y)); | ||
Assert.True(keyboardBinder.IsKeyBounded(Key.Z)); | ||
Assert.False(keyboardBinder.IsKeyBounded(Key.A)); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_BindEmptyKeyCollection() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
var keys = new List<Key>(); | ||
keyboardBinder.BindMany(keys, Key.A); | ||
Assert.Empty(keyboardBinder.BoundedKeys); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_Unbind() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
keyboardBinder.Bind(Key.A, Key.B); | ||
Assert.True(keyboardBinder.IsKeyBounded(Key.A)); | ||
keyboardBinder.Unbind(Key.A); | ||
Assert.Empty(keyboardBinder.BoundedKeys); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_UnbindAll() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
var keys = new List<Key> | ||
{ | ||
Key.Cancel, | ||
Key.Enter, | ||
Key.End, | ||
Key.Tab | ||
}; | ||
keyboardBinder.BindMany(keys, Key.A); | ||
Assert.Equal(4, keyboardBinder.BoundedKeys.Count); | ||
keyboardBinder.UnbindAll(); | ||
Assert.Empty(keyboardBinder.BoundedKeys); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void KeyboardBinder_UnbindKeyThatHasNotBeenBound() | ||
{ | ||
var keyboardBinder = new KeyboardBinder(); | ||
|
||
_emulator.Run(() => | ||
{ | ||
Assert.Empty(keyboardBinder.BoundedKeys); | ||
keyboardBinder.Unbind(Key.A); | ||
Assert.Empty(keyboardBinder.BoundedKeys); | ||
}); | ||
} | ||
} |