public void ItShouldRaiseAnEvent() { InputReceivedEventArgs actualArgs = null; var expectedArgs = new InputReceivedEventArgs("testInput"); var resetEvent = new AutoResetEvent(false); Sut.InputReceived += (sender, args) => { actualArgs = args; resetEvent.Set(); }; using (var reader = new StringReader("testInput")) { Console.SetIn(reader); Sut.ReadLine(); } if (!resetEvent.WaitOne(100)) Assert.Fail("The input event was never raised."); actualArgs.ShouldBeEquivalentTo(expectedArgs); }
bool ReportInputPredicate(InputReceivedEventArgs e) { if (e.Input.Dimensionality != Dimensionality) { return false; } switch (e.Input.Dimensionality) { case InputDimensionality.Digital: return ((DigitalInputReceivedEventArgs)e).State; case InputDimensionality.Linear: case InputDimensionality.Planar: return true; default: return false; } }
protected override void Context() { base.Context(); testInput = "input"; testEventArgs = new InputReceivedEventArgs(testInput); const string sampleSum = "42"; A.CallTo(() => Calculator.GetSum(A<string>._)) .Returns(sampleSum); }
protected override void Context() { base.Context(); testInput = "input"; testEventArgs = new InputReceivedEventArgs(testInput); A.CallTo(() => Calculator.GetSum(A<string>._)) .Throws(new InvalidInputException()); }
protected void OnInputReceived(InputReceivedEventArgs e) { if (InputReceived != null) { InputReceived(this, e); } }
public virtual void OnInputReceived(object sender, InputReceivedEventArgs args) { }
static void gameContext_InputReceived(object sender, InputReceivedEventArgs e) { Console.WriteLine($"Input reveived: {e.Player}, {e.InputKey}"); gameContext.CurrentState.UserInput(e.Player, e.InputKey); }
void InputAggregator_InputReceived(object sender, InputReceivedEventArgs e) { var de = e as DigitalInputReceivedEventArgs; if (de == null || de.Input.ID.DeviceName != "Keyboard0") { return; } InputSection inputConfig = _config.Input; if (de.State) { if (inputConfig.Joypad1.Up.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Up; } if (inputConfig.Joypad1.Down.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Down; } if (inputConfig.Joypad1.Left.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Left; } if (inputConfig.Joypad1.Right.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Right; } if (inputConfig.Joypad1.B.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.B; } if (inputConfig.Joypad1.A.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.A; } if (inputConfig.Joypad1.Y.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Y; } if (inputConfig.Joypad1.X.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.X; } if (inputConfig.Joypad1.L.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.L; } if (inputConfig.Joypad1.R.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.R; } if (inputConfig.Joypad1.Start.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Start; } if (inputConfig.Joypad1.Select.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Select; } _snes.SetInputState(1, 0, (int)_buttonStates, 0, 0); } else { if (inputConfig.Joypad1.Up.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Up; } if (inputConfig.Joypad1.Down.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Down; } if (inputConfig.Joypad1.Left.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Left; } if (inputConfig.Joypad1.Right.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Right; } if (inputConfig.Joypad1.B.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.B; } if (inputConfig.Joypad1.A.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.A; } if (inputConfig.Joypad1.Y.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Y; } if (inputConfig.Joypad1.X.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.X; } if (inputConfig.Joypad1.L.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.L; } if (inputConfig.Joypad1.R.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.R; } if (inputConfig.Joypad1.Start.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Start; } if (inputConfig.Joypad1.Select.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Select; } _snes.SetInputState(1, 0, (int)_buttonStates, 0, 0); } }
void InputHandler(object sender, InputReceivedEventArgs e) { OnInputReceived(e); }