public void add_hotas_device_with_mode_profile() { var deviceId = Guid.NewGuid(); var newDevice = new HOTASDevice() { 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(newDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); var device = new HOTASDevice(Substitute.For <IDirectInput>(), Guid.Empty, deviceId, "test device", Substitute.For <IHOTASQueue>()); device.ButtonMap.Add(new HOTASButton() { MapId = 1, MapName = "first button", ActionName = "tes action", IsShift = true, ShiftModePage = 2, Type = HOTASButton.ButtonType.Button }); device.ModeProfiles.Add(43, new ObservableCollection <IHotasBaseMap>() { { new HOTASButton() { MapName = "mode profile map" } } }); list.AddDevice(device); var addedDevice = list.Devices.First(d => d.DeviceId == deviceId); Assert.Equal("mode profile map", addedDevice.ModeProfiles[43][0].MapName); }
public void replace_device() { var deviceId = Guid.NewGuid(); var firstDevice = new HOTASDevice(Substitute.For <IDirectInput>(), Guid.Empty, deviceId, "existing device", Substitute.For <IHOTASQueue>()); var replaceDevice = new HOTASDevice(Substitute.For <IDirectInput>(), Guid.Empty, deviceId, "replace device", Substitute.For <IHOTASQueue>()); var subDeviceFactory = Substitute.For <HOTASDeviceFactory>(); subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(firstDevice); var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory); firstDevice.ButtonMap.Add(new HOTASButton()); list.AddDevice(firstDevice); var currentDevice = list.Devices.First(d => d.DeviceId == deviceId); Assert.Equal(firstDevice.Name, currentDevice.Name); list.ReplaceDevice(replaceDevice); currentDevice = list.Devices.First(d => d.DeviceId == deviceId); Assert.Equal(replaceDevice.Name, currentDevice.Name); }
public void replace_device() { var deviceVm = CreateDeviceViewMode(out var originalHotasDevice); var expectedHotasDevice = new HOTASDevice(); expectedHotasDevice.Capabilities = new Capabilities(); var expectedDeviceId = Guid.NewGuid(); var expectedProductId = Guid.NewGuid(); expectedHotasDevice.Name = "expected device name"; expectedHotasDevice.DeviceId = expectedDeviceId; expectedHotasDevice.ProductId = expectedProductId; var list = new ObservableCollection <IHotasBaseMap>(); list.Add(new HOTASButton() { MapId = 48, Type = HOTASButton.ButtonType.Button, ActionCatalogItem = new ActionCatalogItem() { Actions = new ObservableCollection <ButtonAction>() { new ButtonAction() } }, ActionName = "first" }); expectedHotasDevice.ApplyButtonMap(list); Assert.Equal(originalHotasDevice.Name, deviceVm.Name); Assert.Equal(originalHotasDevice.DeviceId, deviceVm.InstanceId); Assert.Equal(deviceVm.PID, DeviceViewModel.GetPID(originalHotasDevice.ProductId)); Assert.Equal(deviceVm.VID, DeviceViewModel.GetVID(originalHotasDevice.ProductId)); Assert.PropertyChanged(deviceVm, "IsDeviceLoaded", () => deviceVm.ReplaceDevice(expectedHotasDevice)); Assert.NotEqual(originalHotasDevice.Name, deviceVm.Name); Assert.Equal(expectedHotasDevice.Name, deviceVm.Name); Assert.Equal(deviceVm.PID, DeviceViewModel.GetPID(expectedHotasDevice.ProductId)); Assert.Equal(deviceVm.VID, DeviceViewModel.GetVID(expectedHotasDevice.ProductId)); Assert.True(deviceVm.IsDeviceLoaded); }
public void device_list_button_pressed_button_not_found() { const int mode = 1; const string expectedDeviceName = "not set"; var activationButtonList = new Dictionary <int, ModeActivationItem> { { 1, new ModeActivationItem() { ButtonId = 1, ButtonName = "test button", ProfileName = "select combat mode" } } }; var profileVm = new ModeProfileConfigWindowViewModel(Substitute.For <IEventAggregator>(), Substitute.For <IDispatcher>(), mode, activationButtonList); profileVm.DeviceName = expectedDeviceName; var device = new HOTASDevice(); profileVm.DeviceList_ButtonPressed(new object(), new ButtonPressedEventArgs() { ButtonId = 1, Device = device }); Assert.Equal(expectedDeviceName, profileVm.DeviceName); }
public void device_list_button_pressed_button_found() { const int mode = 1; var activationButtonList = new Dictionary <int, ModeActivationItem> { { 1, new ModeActivationItem() { ButtonId = 1, ButtonName = "test button", ProfileName = "select combat mode" } } }; var profileVm = new ModeProfileConfigWindowViewModel(Substitute.For <IEventAggregator>(), new TestDispatcher(), mode, activationButtonList); profileVm.DeviceName = "not set"; var device1 = new HOTASDevice(Substitute.For <IDirectInput>(), Guid.NewGuid(), Guid.NewGuid(), "test device 1", Substitute.For <IHOTASQueue>()); device1.ButtonMap.Add(new HOTASButton() { MapId = 1 }); device1.ButtonMap.Add(new HOTASButton() { MapId = 2 }); profileVm.DeviceList_ButtonPressed(new object(), new ButtonPressedEventArgs() { ButtonId = 1, Device = device1 }); Assert.Equal("test device 1", profileVm.DeviceName); var device2 = new HOTASDevice(Substitute.For <IDirectInput>(), Guid.NewGuid(), Guid.NewGuid(), "test device 2", Substitute.For <IHOTASQueue>()); device2.ButtonMap.Add(new HOTASButton() { MapId = 4, MapName = "test activation name" }); device2.ButtonMap.Add(new HOTASButton() { MapId = 5 }); //button and device do not match up so devicename does not change profileVm.DeviceList_ButtonPressed(new object(), new ButtonPressedEventArgs() { ButtonId = 1, Device = device2 }); Assert.Equal("test device 1", profileVm.DeviceName); profileVm.PropertyChanged += ProfileVm_PropertyChanged_for_basic_constructor_no_valid_mode_test; property_chagned_for_basic_constructor_no_valid_mode_test = false; profileVm.DeviceList_ButtonPressed(new object(), new ButtonPressedEventArgs() { ButtonId = 4, Device = device2 }); Assert.Equal("test device 2", profileVm.DeviceName); Assert.Equal("test activation name", profileVm.ActivationButtonName); Assert.False(profileVm.IsActivationErrorVisible); Assert.True(property_chagned_for_basic_constructor_no_valid_mode_test); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (objectType == typeof(IHOTASDevice)) { var device = new HOTASDevice(); try { serializer.Populate(reader, device); } catch (Exception e) { Logging.Log.Error(e, "Failed to deserialize a HOTASDevice"); throw; } return(device); } if (objectType == typeof(HOTASButton)) { var buttonMap = new HOTASButton(); try { serializer.Populate(reader, buttonMap); } catch (Exception e) { Logging.Log.Error(e, "Failed to deserialize a HOTASButton"); throw; } return(buttonMap); } if (objectType == typeof(ButtonAction)) { var action = new ButtonAction(); try { serializer.Populate(reader, action); } catch (Exception e) { Logging.Log.Error(e, "Failed to deserialize a ButtonAction"); throw; } return(action); } var dic = new Dictionary <int, ObservableCollection <IHotasBaseMap> >(); var jsonDictionary = JObject.Load(reader); foreach (var kv in jsonDictionary) { var key = int.Parse(kv.Key); var jsonArray = kv.Value; var list = new ObservableCollection <IHotasBaseMap>(); foreach (var jsonObject in jsonArray) { IHotasBaseMap map; var testValue = jsonObject.Value <string>("Type"); Enum.TryParse(testValue, out HOTASButton.ButtonType testType); try { switch (testType) { case HOTASButton.ButtonType.AxisLinear: case HOTASButton.ButtonType.AxisRadial: map = new HOTASAxis(); serializer.Populate(jsonObject.CreateReader(), map); break; default: map = new HOTASButton(); serializer.Populate(jsonObject.CreateReader(), map); break; } } catch (Exception e) { Console.WriteLine(e); throw; } list.Add(map); } dic.Add(key, list); } return(dic); }