Commits

Christian Specht committed 15f17db Draft

do NOT shutdown app if device is not ready, just display a message

Comments (0)

Files changed (4)

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

         }
         
         /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die Couldn&apos;t send commands to the launcher.
+        ///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 The config file doesn&apos;t contain any command sets! ähnelt.
         /// </summary>
         internal static string NoCommandSetsInConfig {

src/MissileSharp.Launcher/Properties/Resources.resx

   <data name="ConfigFileMissing" xml:space="preserve">
     <value>Config file missing: </value>
   </data>
+  <data name="DeviceIsNotReady" xml:space="preserve">
+    <value>Couldn't send commands to the launcher.
+The device is not ready, please check the connection!</value>
+  </data>
   <data name="NoCommandSetsInConfig" xml:space="preserve">
     <value>The config file doesn't contain any command sets!</value>
   </data>

src/MissileSharp.Launcher/ViewModels/MainWindowViewModel.cs

 
         private void FireMissile(Object obj)
         {
+            if (!this.model.IsReady)
+            {
+                this.messageService.ShowMessage(Resources.DeviceIsNotReady);
+                return;
+            }
+
             try
             {
                 this.model.RunCommandSet(obj.ToString());

src/MissileSharp.Tests/Launcher/MainWindowViewModelTests.cs

         private Mock<IShutdownService> shutdownservice;
         private Mock<ICommandCenterService> commandcenterservice;
         private Mock<ICommandCenter> commandcenter;
+        private Mock<IMessageService> messageservice;
         
         [SetUp]
         public void Setup()
 
             this.commandcenter = new Mock<ICommandCenter>();
             this.commandcenter.Setup(mock => mock.LoadCommandSets(It.IsAny<string[]>())).Returns(true);
+            this.commandcenter.Setup(stub => stub.IsReady).Returns(true);
             var list = new List<string>();
             list.Add("test");
             this.commandcenter.Setup(mock => mock.GetLoadedCommandSetNames()).Returns(list);
+
+            this.messageservice = new Mock<IMessageService>();
         }
 
         public MainWindowViewModel SetupViewModel(ICommandCenterService commandCenterService = null, IConfigService configService = null, IMessageService messageService = null, IShutdownService shutdownService = null)
 
             if (messageService == null)
             {
-                messageService = new Mock<IMessageService>().Object;
+                messageService = this.messageservice.Object;
             }
 
             if (shutdownService == null)
 
             this.shutdownservice.Verify(mock => mock.Shutdown());
         }
+
+        [Test]
+        public void FireCommand_LauncherIsNotReady_MessageIsDisplayed()
+        {
+            this.commandcenter.Setup(stub => stub.IsReady).Returns(false);
+            var viewmodel = SetupViewModel();
+            viewmodel.FireCommand.Execute("test");
+
+            this.messageservice.Verify(mock => mock.ShowMessage(It.IsAny<string>()));
+        }
     }
 }