public void shift_released() { var subDevice = Substitute.For <IHOTASDevice>(); subDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>()); var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToDevice(subDevice); list.Mode = 1; subDevice.ModeProfileSelected += Raise.EventWith(subDevice, new ModeProfileSelectedEventArgs() { IsShift = true, Mode = 43 }); //just proving Mode has changed since this test is verifying we get back to Mode = 1 Assert.Equal(43, list.Mode); subDevice.ShiftReleased += Raise.EventWith(subDevice, new EventArgs()); Assert.Equal(1, list.Mode); }
public void listen_to_device() { var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), Substitute.For <HOTASDeviceFactory>()); var subDevice = Substitute.For <IHOTASDevice>(); list.ListenToDevice(subDevice); subDevice.Received().ListenAsync(); }
public void device_lost_connection_to_device() { var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), Substitute.For <HOTASDeviceFactory>()); var subDevice = Substitute.For <IHOTASDevice>(); list.ListenToDevice(subDevice); Assert.Raises <LostConnectionToDeviceEventArgs>(a => list.LostConnectionToDevice += a, a => list.LostConnectionToDevice -= a, () => subDevice.LostConnectionToDevice += Raise.EventWith(subDevice, new LostConnectionToDeviceEventArgs(subDevice))); }
public void force_button_press() { var subDevice = Substitute.For <IHOTASDevice>(); subDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>()); var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToDevice(subDevice); list.ForceButtonPress(subDevice, JoystickOffset.Button1, true); subDevice.Received().ForceButtonPress(JoystickOffset.Button1, true); }
public void keystroke_up_sent() { var subDevice = Substitute.For <IHOTASDevice>(); subDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>()); var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToDevice(subDevice); Assert.Raises <KeystrokeSentEventArgs>(a => list.KeystrokeUpSent += a, a => list.KeystrokeUpSent -= a, () => subDevice.KeystrokeUpSent += Raise.EventWith(subDevice, new KeystrokeSentEventArgs(1, 1, 1, false, true))); }
public void button_pressed() { var subDevice = Substitute.For <IHOTASDevice>(); subDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>()); var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToDevice(subDevice); Assert.Raises <ButtonPressedEventArgs>(a => list.ButtonPressed += a, a => list.ButtonPressed -= a, () => subDevice.ButtonPressed += Raise.EventWith(subDevice, new ButtonPressedEventArgs() { ButtonId = 1, Device = subDevice })); }
public void mode_profile_selected() { //this test does not test isShiftStateActive/PreviousMode logic in the method. the ShiftReleased test will do that var subDevice = Substitute.For <IHOTASDevice>(); subDevice.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>()); var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToDevice(subDevice); Assert.Raises <ModeProfileChangedEventArgs>(a => list.ModeProfileChanged += a, a => list.ModeProfileChanged -= a, () => subDevice.ModeProfileSelected += Raise.EventWith(subDevice, new ModeProfileSelectedEventArgs() { IsShift = true, Mode = 43 })); }