Ejemplo n.º 1
0
        public void auto_set_mode()
        {
            var subDevice = Substitute.For <IHOTASDevice>();
            var buttonMap = new ObservableCollection <IHotasBaseMap>();

            buttonMap.Add(new HOTASButton()
            {
                ShiftModePage = 43
            });
            subDevice.IsDeviceLoaded.Returns(true);
            subDevice.ButtonMap.Returns(buttonMap);
            subDevice.GetButtonState(Arg.Any <int>()).Returns(true);

            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.Mode = 1;
            list.AddDevice(subDevice);
            list.ListenToAllDevices();

            list.AutoSetMode();
            Assert.Equal(43, list.Mode);
        }
Ejemplo n.º 2
0
        public void clear_unassigned_actions()
        {
            var subDevice1 = Substitute.For <IHOTASDevice>();
            var subDevice2 = Substitute.For <IHOTASDevice>();

            subDevice1.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(subDevice1);

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

            list.AddDevice(subDevice1);

            subDevice2.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>());
            subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice2);
            list.AddDevice(subDevice2);

            list.ListenToAllDevices();

            list.ClearUnassignedActions();
            subDevice1.Received().ClearUnassignedActions();
            subDevice2.Received().ClearUnassignedActions();
        }
Ejemplo n.º 3
0
        public void listen_to_all_devices()
        {
            var subDevice1 = Substitute.For <IHOTASDevice>();

            subDevice1.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>());
            subDevice1.DeviceId = Guid.NewGuid();

            var subDeviceFactory = Substitute.For <HOTASDeviceFactory>();

            subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice1);

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

            list.AddDevice(subDevice1);

            var subDevice2 = Substitute.For <IHOTASDevice>();

            subDevice2.ButtonMap.Returns(new ObservableCollection <IHotasBaseMap>());
            subDevice2.DeviceId = Guid.NewGuid();

            subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(), Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice2);
            list.AddDevice(subDevice2);

            Assert.Equal(2, list.Devices.Count);

            list.ListenToAllDevices();
            subDevice1.Received().ListenAsync();
            subDevice2.Received().ListenAsync();
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void set_mode_same_mode()
        {
            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.Mode = 1;
            list.AddDevice(subDevice);
            list.ListenToAllDevices();

            list.SetMode(43);

            subDevice.DidNotReceive().SetMode(1);
        }
Ejemplo n.º 6
0
        public void set_mode()
        {
            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.Mode = 1;
            list.AddDevice(subDevice);
            list.ListenToAllDevices();


            Assert.Raises <ModeProfileChangedEventArgs>(a => list.ModeProfileChanged += a, a => list.ModeProfileChanged -= a,
                                                        () => list.SetMode(43));
            Assert.Equal(43, list.Mode);
            subDevice.Received().SetMode(43);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }