Commits

Christian Specht committed 01cf99f Draft

throw exception if loaded launcher model doesn't implement ILauncherModel

Comments (0)

Files changed (4)

src/MissileSharp.Tests/Library/LauncherModelFactoryTests.cs

         }
 
         [Test]
+        public void GetLauncher_ExistingClassDoesNotImplementILauncher_ThrowsException()
+        {
+            Assert.Throws<ArgumentOutOfRangeException>(() => LauncherModelFactory.GetLauncher("MissileSharp.CommandSetList"));
+        }
+
+        [Test]
         public void GetLauncher_InvalidLauncherName_ThrowsException()
         {
             Assert.Throws<TypeLoadException>(() => LauncherModelFactory.GetLauncher("MissileSharp.InvalidLauncher"));
         }
 
         [Test]
-        public void GetLauncher_InvalidAssemblyName_Throws()
+        public void GetLauncher_InvalidAssemblyName_ThrowsException()
         {
             Assert.Throws<FileNotFoundException>(() => LauncherModelFactory.GetLauncher("MissileSharp.InvalidLauncher", "Invalid.dll"));
         }

src/MissileSharp/LauncherModelFactory.cs

                 throw new TypeLoadException(Resources.LauncherModelNotFound + className);
             }
 
+            if (!typeof(ILauncherModel).IsAssignableFrom(type))
+            {
+                throw new ArgumentOutOfRangeException(string.Format(Resources.LauncherModelIsNotILauncherModel, className));
+            }
+
             return (ILauncherModel)Activator.CreateInstance(type);
         }
 

src/MissileSharp/Properties/Resources.Designer.cs

         }
         
         /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die Launcher model &apos;{0}&apos; does not implement interface ILauncherModel ähnelt.
+        /// </summary>
+        internal static string LauncherModelIsNotILauncherModel {
+            get {
+                return ResourceManager.GetString("LauncherModelIsNotILauncherModel", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Sucht eine lokalisierte Zeichenfolge, die No launcher model with this name available:  ähnelt.
         /// </summary>
         internal static string LauncherModelNotFound {

src/MissileSharp/Properties/Resources.resx

   <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="LauncherModelIsNotILauncherModel" xml:space="preserve">
+    <value>Launcher model '{0}' does not implement interface ILauncherModel</value>
+  </data>
   <data name="LauncherModelNotFound" xml:space="preserve">
     <value>No launcher model with this name available: </value>
   </data>