Commits

Christian Specht committed 5b9d747 Draft

throw if the device is not ready to receive commands

  • Participants
  • Parent commits 2f58708

Comments (0)

Files changed (5)

File src/MissileSharp.Tests/Library/CommandCenterTests.cs

         }
 
         [Test]
+        public void RunCommand_LauncherIsNotReady_Throws()
+        {
+            device.IsReady = false;
+            Assert.Catch<Exception>(() => cmd.RunCommand(new LauncherCommand(Command.Up, 0)));
+        }
+
+        [Test]
         public void RunCommand_Up_SendsUpCommand()
         {
             cmd.RunCommand(new LauncherCommand(Command.Up, 0));

File src/MissileSharp.Tests/MockHidDevice.cs

     /// </summary>
     class MockHidDevice : IHidDevice
     {
+        public MockHidDevice()
+        {
+            IsReady = true;
+        }
+
         public void Initialize(int vendorId, int deviceId)
         {
             ReceivedCommands = new List<byte>();
         {
         }
 
-        public bool IsReady
-        {
-            get { return true; }
-        }
+        public bool IsReady { get; set; }
 
         public void SendData(byte[] data)
         {

File src/MissileSharp/CommandCenter.cs

         /// <param name="command">The command to run</param>
         public void RunCommand(LauncherCommand command)
         {
+            if (!IsReady)
+            {
+                throw new InvalidOperationException(Resources.DeviceIsNotReady);
+            }
+
             switch (command.Command)
             {
                 case Command.Up:

File src/MissileSharp/Properties/Resources.Designer.cs

         }
         
         /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die The device is not ready, please check the connection! ähnelt.
+        /// </summary>
+        internal static string DeviceIsNotReady {
+            get {
+                return ResourceManager.GetString("DeviceIsNotReady", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Sucht eine lokalisierte Zeichenfolge, die &quot;device&quot; parameter is null! ähnelt.
         /// </summary>
         internal static string DeviceIsNull {

File src/MissileSharp/Properties/Resources.resx

   <data name="CommandSetNameEmpty" xml:space="preserve">
     <value>command set name is empty</value>
   </data>
+  <data name="DeviceIsNotReady" xml:space="preserve">
+    <value>The device is not ready, please check the connection!</value>
+  </data>
   <data name="DeviceIsNull" xml:space="preserve">
     <value>"device" parameter is null!</value>
   </data>