Commits

Christian Specht committed 02f4d84 Draft

make sure that CommandCenter throws when constructor parameters are null

  • Participants
  • Parent commits 15aab99

Comments (0)

Files changed (4)

src/MissileSharp.Tests/Library/CommandCenterTests.cs

         }
 
         [Test]
+        public void Constructor_LauncherIsNull_Throws()
+        {
+            Assert.Catch<Exception>(()=> new CommandCenter(null, device));
+        }
+
+        [Test]
+        public void Constructor_DeviceIsNull_Throws()
+        {
+            Assert.Catch<Exception>(() => new CommandCenter(launcher, null));
+        }
+
+        [Test]
         public void SendCommand_Fire_SendsFire()
         {
             cmd.SendCommand(launcher.Fire);

src/MissileSharp/CommandCenter.cs

         /// <remarks>This is only for testing - HidLibrary is the default library for production use</remarks>
         internal CommandCenter(ILauncherModel launcher, IHidDevice device)
         {
+            if (launcher == null)
+            {
+                throw new ArgumentException(Resources.LauncherIsNull);
+            }
+
+            if (device == null)
+            {
+                throw new ArgumentException(Resources.DeviceIsNull);
+            }
+
             this.launcher = launcher;
             this.device = device;
             this.sets = new CommandSetList();

src/MissileSharp/Properties/Resources.Designer.cs

         }
         
         /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die &quot;device&quot; parameter is null! ähnelt.
+        /// </summary>
+        internal static string DeviceIsNull {
+            get {
+                return ResourceManager.GetString("DeviceIsNull", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Sucht eine lokalisierte Zeichenfolge, die The first line in the config must be a command set name. There can be no commands before the first command set name! ähnelt.
         /// </summary>
         internal static string FirstLineMustBeCommandSetName {
         }
         
         /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die &quot;launcher&quot; parameter is null! ähnelt.
+        /// </summary>
+        internal static string LauncherIsNull {
+            get {
+                return ResourceManager.GetString("LauncherIsNull", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Sucht eine lokalisierte Zeichenfolge, die Launcher model &apos;{0}&apos; does not implement interface ILauncherModel ähnelt.
         /// </summary>
         internal static string LauncherModelIsNotILauncherModel {

src/MissileSharp/Properties/Resources.resx

   <data name="CommandSetNameEmpty" xml:space="preserve">
     <value>command set name is empty</value>
   </data>
+  <data name="DeviceIsNull" xml:space="preserve">
+    <value>"device" parameter is null!</value>
+  </data>
   <data name="FirstLineMustBeCommandSetName" xml:space="preserve">
     <value>The first line in the config must be a command set name. There can be no commands before the first command set name!</value>
   </data>
+  <data name="LauncherIsNull" xml:space="preserve">
+    <value>"launcher" parameter is null!</value>
+  </data>
   <data name="LauncherModelIsNotILauncherModel" xml:space="preserve">
     <value>Launcher model '{0}' does not implement interface ILauncherModel</value>
   </data>