Commits

Christian Specht committed 86486e8 Draft

throw better exceptions
(ArgumentNullException and ArgumentOutOfRangeException make more sense than InvalidOperationException)

Comments (0)

Files changed (4)

src/MissileSharp.Tests/CommandSetListTests.cs

         [Test]
         public void Add_CommandSetNameIsEmpty_ThrowsException()
         {
-            Assert.Throws<InvalidOperationException>(() => list.Add(string.Empty, Command.Up, 1));
+            Assert.Throws<ArgumentNullException>(() => list.Add(string.Empty, Command.Up, 1));
         }
 
         [Test]
         public void Add_CommandSetNameIsNull_ThrowsException()
         {
-            Assert.Throws<InvalidOperationException>(() => list.Add(null, Command.Up, 1));
+            Assert.Throws<ArgumentNullException>(() => list.Add(null, Command.Up, 1));
         }
 
         [Test]
         public void Add_CommandIsNull_ThrowsException()
         {
-            Assert.Throws<InvalidOperationException>(() => list.Add("name", null));
+            Assert.Throws<ArgumentNullException>(() => list.Add("name", null));
         }
 
         [Test]

src/MissileSharp.Tests/LauncherCommandTests.cs

         [Test]
         public void CommandIsEmpty_ThrowsException()
         {
-            Assert.Throws<InvalidOperationException>(()=> new LauncherCommand(string.Empty, 0));
+            Assert.Throws<ArgumentNullException>(() => new LauncherCommand(string.Empty, 0));
         }
 
         [Test]
         public void CommandIsNull_ThrowsException()
         {
-            Assert.Throws<InvalidOperationException>(() => new LauncherCommand(null, 0));
+            Assert.Throws<ArgumentNullException>(() => new LauncherCommand(null, 0));
         }
 
         [Test]
         public void ValueIsSmallerThanZero_ThrowsException()
         {
-            Assert.Throws<InvalidOperationException>(() => new LauncherCommand(Command.Up, -1));
+            Assert.Throws<ArgumentOutOfRangeException>(() => new LauncherCommand(Command.Up, -1));
         }
 
         [Test]

src/MissileSharp/CommandSetList.cs

         /// Add a new item to a command set (command set will be created if it doesn't exist)
         /// </summary>
         /// <param name="commandSetName">The name of the command set</param>
-        /// <param name="command">The actual command set (a list of commands)</param>
+        /// <param name="command">The actual command</param>
         public void Add(string commandSetName, LauncherCommand command)
         {
             if (string.IsNullOrEmpty(commandSetName))
             {
-                throw new InvalidOperationException("command set name is empty");
+                throw new ArgumentNullException("command set name is empty");
             }
 
             if (command == null)
             {
-                throw new InvalidOperationException("command set is empty");
+                throw new ArgumentNullException("command is empty");
             }
 
             if (!dict.ContainsKey(commandSetName.ToLower()))

src/MissileSharp/LauncherCommand.cs

         {
             if (string.IsNullOrEmpty(command))
             {
-                throw new InvalidOperationException("command is empty");
+                throw new ArgumentNullException("command is empty");
             }
 
             if (value < 0)
             {
-                throw new InvalidOperationException("value must be equal or greater than zero");
+                throw new ArgumentOutOfRangeException("value must be equal or greater than zero");
             }
 
             switch (command.ToLower())
         {
             if (value < 0)
             {
-                throw new InvalidOperationException("value must be equal or greater than zero");
+                throw new ArgumentOutOfRangeException("value must be equal or greater than zero");
             }
 
             this.Command = command;