public void TestXboxGamepadIdSetToInvalidOnConstruction()
        {
            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            Assert.IsNotNull(gamepad, "Failed to create gamepad");
            Assert.IsNull(gamepad.Id, "id of gamepad should be null when not connected.");
        }
        public void TestXboxGamepadDisconnectThrowsWhenNotConnected()
        {
            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            this.VerifyGamepadThrowsFunc <XboxInputException>(
                () => gamepad.Disconnect(),
                "Disconnect did not throw an exception when not connected.");
        }
        public void TestXboxGamepadIdSetToValidAfterConnect()
        {
            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            Assert.IsNotNull(gamepad, "Failed to create gamepad.");
            gamepad.Connect();

            Assert.IsTrue(gamepad.Id >= 0, "Received a bad id, or failed to connect gamepad");
        }
        public void TestXboxGamepadSetXboxGamepadStateThrowsWhenNotConnected()
        {
            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            XboxGamepadState state = new XboxGamepadState();

            this.VerifyGamepadThrowsFunc <XboxInputException>(
                () => gamepad.SetXboxGamepadState(state),
                "SetGamepadState did not throw an exception when not connected.");
        }
        public void TestXboxGamepadConnectThrowsWhenAlreadyConnected()
        {
            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            gamepad.Connect();

            this.VerifyGamepadThrowsFunc <XboxInputException>(
                () => gamepad.Connect(),
                "Connect did not throw an exception when already connected.");
        }
        public void TestXboxGamepadIdSetToInvalidAfterDisconnect()
        {
            this.shimAdapter = new ShimXboxConsoleAdapterBase(new StubXboxConsoleAdapterBase(null))
            {
                DisconnectXboxGamepadStringUInt64 = (systemIpAddress, gamepadId) => { }
            };

            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            Assert.IsNotNull(gamepad, "Failed to create gamepad.");
            gamepad.Connect();
            Assert.IsTrue(gamepad.Id >= 0, "Received a bad id, or failed to connect gamepad");

            gamepad.Disconnect();

            Assert.IsNull(gamepad.Id, "Id not set to null after disconnecting");
        }
        public void TestXboxGamepadSendGamepadStateCallsAdapterSendGamepadReportCorrectly()
        {
            var gamepad      = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);
            var gamepadState = new XboxGamepadState();

            bool adapterCalled = false;

            this.shimAdapter = new ShimXboxConsoleAdapterBase(new StubXboxConsoleAdapterBase(null))
            {
                SendGamepadReportStringUInt64XboxGamepadState = (systemIpAddress, gamepadId, adapterGamepadState)
                                                                =>
                {
                    adapterCalled = true;
                    Assert.AreEqual(this.XboxConsole.SystemIpAddressString, systemIpAddress, "SystemIpAddress did not match the one from the XboxConsole");
                    Assert.AreEqual(gamepad.Id, gamepadId, "Gamepad Id is not equal to one being set");
                    Assert.AreEqual(gamepadState, adapterGamepadState, "GamepadState not equal to one being set");
                }
            };
            gamepad.Connect();
            gamepad.SetXboxGamepadState(gamepadState);

            Assert.IsTrue(adapterCalled, "Adapter SetGamepadState never called");
        }
        public void TestXboxGamepadSetGamepadStateWithNullState()
        {
            var gamepad = new GamesTest.Xbox.Input.XboxGamepad(this.XboxConsole);

            gamepad.SetXboxGamepadState(null);
        }