Commits

Christian Specht committed 3c0829a Draft

shutdown if no command sets were loaded

Comments (0)

Files changed (4)

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

                 return ResourceManager.GetString("ConfigFileMissing", resourceCulture);
             }
         }
+        
+        /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die The config file doesn&apos;t contain any command sets! ähnelt.
+        /// </summary>
+        internal static string NoCommandSetsInConfig {
+            get {
+                return ResourceManager.GetString("NoCommandSetsInConfig", resourceCulture);
+            }
+        }
     }
 }

src/MissileSharp.Launcher/Properties/Resources.resx

   <data name="ConfigFileMissing" xml:space="preserve">
     <value>Config file missing: </value>
   </data>
+  <data name="NoCommandSetsInConfig" xml:space="preserve">
+    <value>The config file doesn't contain any command sets!</value>
+  </data>
 </root>

src/MissileSharp.Launcher/ViewModels/MainWindowViewModel.cs

 using System;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
+using System.Linq;
 using System.Windows.Input;
 using MissileSharp.Launcher.Properties;
 using MissileSharp.Launcher.Services;
             }
             catch (Exception ex)
             {
-                this.messageService.ShowMessage(string.Format(Resources.ConfigFileError, Environment.NewLine, ex.Message));
-                this.shutdownService.Shutdown();
+                Shutdown(string.Format(Resources.ConfigFileError, Environment.NewLine, ex.Message));
+                return;
+            }
+
+            if (!this.model.GetLoadedCommandSetNames().Any())
+            {
+                Shutdown(Resources.NoCommandSetsInConfig);
                 return;
             }
 
         {
             this.model.RunCommandSet(obj.ToString());
         }
+
+        private void Shutdown(string message)
+        {
+            this.messageService.ShowMessage(message);
+            this.shutdownService.Shutdown();
+        }
     }
 }

src/MissileSharp.Tests/Launcher/MainWindowViewModelTests.cs

 
             this.commandcenter = new Mock<ICommandCenter>();
             this.commandcenter.Setup(mock => mock.LoadCommandSets(It.IsAny<string[]>())).Returns(true);
-            this.commandcenter.Setup(mock => mock.GetLoadedCommandSetNames()).Returns(new List<string>());
+            var list = new List<string>();
+            list.Add("test");
+            this.commandcenter.Setup(mock => mock.GetLoadedCommandSetNames()).Returns(list);
         }
 
         public MainWindowViewModel SetupViewModel(ICommandCenterService commandCenterService = null, IConfigService configService = null, IMessageService messageService = null, IShutdownService shutdownService = null)
         [Test]
         public void Initialize_LoadCommandSetsThrows_AppShutsDown()
         {
-            this.commandcenter.Setup(m => m.LoadCommandSets(It.IsAny<string[]>())).Throws<NotImplementedException>();
+            this.commandcenter.Setup(stub => stub.LoadCommandSets(It.IsAny<string[]>())).Throws<NotImplementedException>();
+            var viewmodel = SetupViewModel();
+            this.shutdownservice.Verify(mock => mock.Shutdown());
+        }
+
+        [Test]
+        public void Initialize_GetLoadedCommandSetsIsEmpty_AppShutsDown()
+        {
+            this.commandcenter.Setup(stub => stub.GetLoadedCommandSetNames()).Returns(new List<string>());
             var viewmodel = SetupViewModel();
             this.shutdownservice.Verify(mock => mock.Shutdown());
         }