using System; using UnitTestSharp; namespace Clave.Glass.UnitTests { public class KeyActionTests : TestFixture { public class CtorTests : TestFixture { public void KeepsWhatItIsGiven() { Chord space = Chord.OnPress(KeyCode.Space); var action = new KeyAction("jump", "Jump", KeyStateKind.Pressed, space); CheckEqual("jump", action.Id); CheckEqual("Jump", action.Name); CheckEqual(KeyStateKind.Pressed, action.Kind); CheckEqual(1, action.Defaults.Count); CheckEqual(space, action.Defaults[0]); } public void WithoutAContext_HasNone() { CheckNull(new KeyAction("jump", "Jump", KeyStateKind.Pressed, Chord.OnPress(KeyCode.Space)).Context); } public void KeepsItsContextAndDefaults() { var context = new ChordContext("jumping"); Chord space = Chord.OnPress(KeyCode.Space); var action = new KeyAction("jump", "Jump", KeyStateKind.Pressed, context, space); CheckEqual(context, action.Context); CheckEqual(1, action.Defaults.Count); CheckEqual(space, action.Defaults[0]); } public void Defaults_AreCopied() { Chord space = Chord.OnPress(KeyCode.Space); var defaults = new[] { space }; var action = new KeyAction("jump", "Jump", KeyStateKind.Pressed, defaults); defaults[0] = Chord.OnPress(KeyCode.W); CheckEqual(space, action.Defaults[0]); } public void NoDefaults_IsAllowed() { CheckEqual(0, new KeyAction("jump", "Jump", KeyStateKind.Pressed).Defaults.Count); } public void EmptyId_Throws() { CheckThrow(typeof(ArgumentException)); new KeyAction("", "Jump", KeyStateKind.Pressed); } public void NullId_Throws() { CheckThrow(typeof(ArgumentException)); new KeyAction(null, "Jump", KeyStateKind.Pressed); } public void NullName_Throws() { CheckThrow(typeof(ArgumentNullException)); new KeyAction("jump", null, KeyStateKind.Pressed); } public void UnknownKind_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new KeyAction("jump", "Jump", (KeyStateKind)99); } public void TappedKind_IsKept() { CheckEqual(KeyStateKind.Tapped, new KeyAction("menu", "Menu", KeyStateKind.Tapped).Kind); } public void KindJustPastTapped_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new KeyAction("jump", "Jump", (KeyStateKind)5); } public void NullDefaults_Throw() { CheckThrow(typeof(ArgumentNullException)); new KeyAction("jump", "Jump", KeyStateKind.Pressed, (Chord[])null); } } public class ToStringTests : TestFixture { public void IsTheId() { CheckEqual("jump", new KeyAction("jump", "Jump", KeyStateKind.Pressed).ToString()); } } } }