public void TestBlink1NotifyUsbDeviceTestAllRequests()
        {
            LightsManager lightsManager = null;
            try
            {
                // Mocks
                Mock<LightsDeviceController> lightsDeviceController = this.mockFactory.CreateMock<LightsDeviceController>();

                // Expectations
                lightsDeviceController.Expects.AtLeastOne.Method(x => x.GetFeatureReportByteLength()).WillReturn(10);
                lightsDeviceController.Expects.AtLeastOne.Method(x => x.SendCommand(new byte[10])).WithAnyArguments().WillReturn(LightsDeviceResult.Ack);

                // Run and test
                lightsManager = new LightsManager(lightsDeviceController.MockObject, UsbProtocolType.Blink1);

                // Build activity
                LightsDeviceResult buildActiveRequestResult = lightsManager.NotifyLightsDevice(new BuildActiveRequest(true));
                Assert.That(buildActiveRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));
                buildActiveRequestResult = lightsManager.NotifyLightsDevice(new BuildActiveRequest(false));
                Assert.That(buildActiveRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));

                // Attention
                LightsDeviceResult attentionRequestResult = lightsManager.NotifyLightsDevice(new AttentionRequest(true));
                Assert.That(attentionRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));
                attentionRequestResult = lightsManager.NotifyLightsDevice(new AttentionRequest(false));
                Assert.That(attentionRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));
                attentionRequestResult = lightsManager.NotifyLightsDevice(new AttentionRequest(true, true));
                Assert.That(attentionRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));

                // System status
                LightsDeviceResult statusRequestRequestResult = lightsManager.NotifyLightsDevice(new StatusRequest(true));
                Assert.That(statusRequestRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));
                statusRequestRequestResult = lightsManager.NotifyLightsDevice(new StatusRequest(false));
                Assert.That(statusRequestRequestResult, NUnit.Framework.Is.EqualTo(LightsDeviceResult.Ack));
            }
            finally
            {
                if (lightsManager != null)
                {
                    lightsManager.Dispose();
                }
            }
        }
        public void TestNotifyUsbDeviceRespondsToBuildAttentionRequest()
        {
            LightsManager lightsManager = null;
            try
            {
                // Mocks
                Mock<IHidDevice> mockDevice = this.mockFactory.CreateMock<IHidDevice>();

                // Expectations
                mockDevice.Expects.AtLeastOne.GetProperty(x => x.IsConnected).WillReturn(false);

                // Run
                LightsDeviceController lightsDeviceController = new LightsDeviceController(0, 0, 0, 0, 1000, UsbControlTransferType.Raw) {
                                                                                                                                                 Device = mockDevice.MockObject
                                                                                                                                         };
                lightsManager = new LightsManager(lightsDeviceController, UsbProtocolType.DasBlinkenlichten);
                AttentionRequest request = new AttentionRequest(true);

                // Test
                Assert.That(lightsManager.NotifyLightsDevice(request), NUnit.Framework.Is.EqualTo(LightsDeviceResult.NotConnected));
                this.mockFactory.VerifyAllExpectationsHaveBeenMet();
            }
            finally
            {
                if (lightsManager != null)
                {
                    lightsManager.Dispose();
                }
            }
        }
        public void TestNotifyUsbDeviceIsNullRespondsNotConnected()
        {
            // Run
            LightsDeviceController lightsDeviceController = new LightsDeviceController(0, 0, 0, 0, 1000, UsbControlTransferType.Raw) {
                                                                                                                                             Device = null
                                                                                                                                     };
            LightsManager lightsManager = null;
            try
            {
                lightsManager = new LightsManager(lightsDeviceController, UsbProtocolType.DasBlinkenlichten);
                BuildActiveRequest buildActiveRequest = new BuildActiveRequest(true);

                // Test
                Assert.That(lightsManager.NotifyLightsDevice(buildActiveRequest), NUnit.Framework.Is.EqualTo(LightsDeviceResult.NotConnected));
            }
            finally
            {
                if (lightsManager != null)
                {
                    lightsManager.Dispose();
                }
            }
        }
        public void TestNotifyUsbDeviceRespondsNak()
        {
            LightsManager lightsManager = null;
            try
            {
                // Mocks
                Mock<IHidDevice> mockDevice = this.mockFactory.CreateMock<IHidDevice>();
                byte[] mockDataBytes = Encoding.ASCII.GetBytes(UsbResponse.Nak);
                HidDeviceData mockData = new HidDeviceData(mockDataBytes, HidDeviceData.ReadStatus.Success);
                HidReport mockReport = new HidReport(1, mockData);

                // Expectations
                mockDevice.Expects.AtLeastOne.GetProperty(x => x.IsConnected).WillReturn(true);
                using (this.mockFactory.Ordered)
                {
                    mockDevice.Expects.One.GetProperty(x => x.IsOpen).WillReturn(false);
                    mockDevice.Expects.AtLeastOne.GetProperty(x => x.IsOpen).WillReturn(true);
                }

                mockDevice.Expects.AtLeastOne.Method(x => x.OpenDevice());
                mockDevice.Expects.AtLeastOne.Method(x => x.CreateReport()).WillReturn(mockReport);
                mockDevice.Expects.AtLeastOne.Method(x => x.WriteReport(null)).WithAnyArguments().WillReturn(true);
                mockDevice.Expects.AtLeastOne.Method(x => x.Read()).WillReturn(mockData);

                // Run
                LightsDeviceController lightsDeviceController = new LightsDeviceController(0, 0, 0, 0, 1000, UsbControlTransferType.Raw) {
                                                                                                                                                 Device = mockDevice.MockObject
                                                                                                                                         };
                lightsManager = new LightsManager(lightsDeviceController, UsbProtocolType.DasBlinkenlichten);
                BuildActiveRequest buildActiveRequest = new BuildActiveRequest(true);

                // Test
                Assert.That(lightsManager.NotifyLightsDevice(buildActiveRequest), NUnit.Framework.Is.EqualTo(LightsDeviceResult.Nak));
                this.mockFactory.VerifyAllExpectationsHaveBeenMet();
            }
            finally
            {
                if (lightsManager != null)
                {
                    lightsManager.Dispose();
                }
            }
        }
        public void TestBlink1ThrowsExceptionForUnsupportedUsbProtocolType()
        {
            // Mocks
            Mock<LightsDeviceController> lightsDeviceController = this.mockFactory.CreateMock<LightsDeviceController>();

            // Expectations
            lightsDeviceController.Expects.AtLeastOne.Method(x => x.GetFeatureReportByteLength()).WillReturn(10);
            lightsDeviceController.Expects.AtLeastOne.Method(x => x.SendCommand(new byte[10])).WithAnyArguments().WillReturn(LightsDeviceResult.Ack);

            // Run and test
            LightsManager lightsManager = new LightsManager(lightsDeviceController.MockObject, UsbProtocolType.None);
            Assert.Throws<UnsupportedUsbProtocolTypeException>(() => lightsManager.NotifyLightsDevice(new BuildActiveRequest(true)));
        }