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);
        }
示例#2
0
        public void save_mode_profile_command_remove_existing_activation_button()
        {
            const int modeToRemove = 2;

            var activationButton = new ModeActivationItem()
            {
                ButtonId = 1, ButtonName = "test button 1", ProfileName = "select combat mode"
            };
            var removeThisItem = new ModeActivationItem()
            {
                ButtonId = 2, ButtonName = "test button 2", ProfileName = "select nav mode"
            };
            var activationButtonList = new Dictionary <int, ModeActivationItem>
            {
                { 1, activationButton },
                { 2, removeThisItem }
            };

            var subEventAggregator = Substitute.For <IEventAggregator>();
            var profileVm          = new ModeProfileConfigWindowViewModel(subEventAggregator, Substitute.For <IDispatcher>(), modeToRemove, activationButtonList);

            profileVm.SaveModeProfileCommand.Execute(default);
        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);
        }
        public void apply_activation_button_to_all_profiles()
        {
            var subDevice         = Substitute.For <IHOTASDevice>();
            var buttonMapProfile1 = new ObservableCollection <IHotasBaseMap>();
            var button_1_1        = new HOTASButton()
            {
                MapId = 1, IsShift = false, ShiftModePage = 1
            };
            var button_1_2 = new HOTASButton()
            {
                MapId = 2, IsShift = false, ShiftModePage = 2
            };
            var button_1_3 = new HOTASAxis()
            {
                MapId = 3, ButtonMap = new ObservableCollection <HOTASButton>()
                {
                    new HOTASButton()
                    {
                        MapId = 3, ShiftModePage = 3
                    }
                }
            };

            buttonMapProfile1.Add(button_1_1);
            buttonMapProfile1.Add(button_1_2);
            buttonMapProfile1.Add(button_1_3);

            var buttonMapProfile2 = new ObservableCollection <IHotasBaseMap>();
            var button_2_1        = new HOTASButton()
            {
                MapId = 1, IsShift = false, ShiftModePage = 0
            };                                                                                    //simulate a new profile that does not have links back to previous profiles
            var button_2_2 = new HOTASButton()
            {
                MapId = 2, IsShift = false, ShiftModePage = 0
            };                                                                                    //simulate a new profile that does not have links back to previous profiles
            var button_2_3 = new HOTASAxis()
            {
                MapId = 3, ButtonMap = new ObservableCollection <HOTASButton>()
                {
                    new HOTASButton()
                    {
                        MapId = 3, ShiftModePage = 0
                    }
                }
            };

            buttonMapProfile2.Add(button_2_1);
            buttonMapProfile2.Add(button_2_2);
            buttonMapProfile2.Add(button_2_3);

            subDevice.ButtonMap.Returns(buttonMapProfile1);


            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 profiles = new Dictionary <int, ObservableCollection <IHotasBaseMap> >()
            {
                {
                    1, buttonMapProfile1
                },
                {
                    2, buttonMapProfile2
                },
                {
                    3, buttonMapProfile2
                }
            };

            subDevice.ModeProfiles.Returns(profiles);

            var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory);

            list.AddDevice(subDevice);
            list.ListenToAllDevices();

            var item1 = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 1,
                Mode     = 1
            };

            var item2 = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 2,
                Mode     = 2
            };

            var item3 = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 3,
                Mode     = 3
            };

            list.ModeProfileActivationButtons.Add(1, item1);
            list.ModeProfileActivationButtons.Add(2, item2);
            list.ModeProfileActivationButtons.Add(3, item3);

            Assert.Equal(0, button_2_1.ShiftModePage);
            Assert.Equal(0, button_2_2.ShiftModePage);
            Assert.Equal(0, button_2_3.ButtonMap[0].ShiftModePage);

            list.ApplyActivationButtonToAllProfiles();

            Assert.Equal(1, button_2_1.ShiftModePage);
            Assert.Equal(2, button_2_2.ShiftModePage);
            Assert.Equal(3, button_2_3.ButtonMap[0].ShiftModePage);
        }
 public DeleteModeProfileEvent(ModeActivationItem activationItem)
 {
     ActivationItem = activationItem;
 }