public void remove_mode_profile_only_one_profile() { var subDevice = Substitute.For <IHOTASDevice>(); var buttonMap = new ObservableCollection <IHotasBaseMap>(); var map = new HOTASButton() { MapId = 1, IsShift = true, ShiftModePage = 1 }; buttonMap.Add(map); subDevice.ButtonMap.Returns(buttonMap); var deviceId = Guid.NewGuid(); subDevice.DeviceId = deviceId; 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 profile = new Dictionary <int, ObservableCollection <IHotasBaseMap> >() { { 1, new ObservableCollection <IHotasBaseMap> { buttonMap[0] } } }; subDevice.ModeProfiles.Returns(profile); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); list.AddDevice(subDevice); list.ListenToAllDevices(); var item = new ModeActivationItem() { DeviceId = deviceId, ButtonId = 1, Mode = 1 }; list.ModeProfileActivationButtons.Add(1, item); Assert.True(map.IsShift); Assert.Equal(1, map.ShiftModePage); var isRemoved = list.RemoveModeProfile(item); Assert.Empty(list.ModeProfileActivationButtons); Assert.True(isRemoved); Assert.False(map.IsShift); Assert.Equal(0, map.ShiftModePage); Assert.Equal(1, list.Mode); }
public void remove_mode_profile_not_exist() { 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.ListenToAllDevices(); var item = new ModeActivationItem(); list.ModeProfileActivationButtons.Add(1, item); var isRemoved = list.RemoveModeProfile(new ModeActivationItem()); Assert.Same(item, list.ModeProfileActivationButtons[1]); Assert.False(isRemoved); }