예제 #1
0
 public static void StringIsNullOrWhiteSpace_NullOrWhiteSpaceArg_ArgumentNullException(string arg)
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         ThrowIf.StringIsNullOrWhiteSpace(arg, nameof(arg));
     }, "{0}.{1}() should throw a {2} if passed a null or white space argument!",
                                           nameof(ThrowIf), nameof(ThrowIf.StringIsNullOrWhiteSpace), nameof(ArgumentNullException));
 }
예제 #2
0
 public static void StringIsNullOrWhiteSpace_ValidArgs_NoException()
 {
     Assert.DoesNotThrow(() =>
     {
         ThrowIf.StringIsNullOrWhiteSpace("abcd1234", "foo");
     }, "{0}.{1}() should not throw an exception if passed an argument that isn't null or white space!",
                         nameof(ThrowIf), nameof(ThrowIf.StringIsNullOrWhiteSpace));
 }
예제 #3
0
        /// <summary>
        /// Loads the plugin.
        /// </summary>
        /// <param name="dllFile">The path to the DLL file.</param>
        /// <param name="xmlConfig">The NTestController.xml config path and filename.</param>
        /// <returns>The plugin.</returns>
        /// <exception cref="ArgumentNullException">A null or whitespace only argument was passed in.</exception>
        /// <exception cref="DllNotFoundException">The DLL doesn't exist.</exception>
        /// <exception cref="EntryPointNotFoundException">The DLL doesn't implement the IPlugin interface.</exception>
        public static IPlugin LoadPlugin(string dllFile, string xmlConfig)
        {
            ThrowIf.StringIsNullOrWhiteSpace(dllFile, nameof(dllFile));
            ThrowIf.StringIsNullOrWhiteSpace(xmlConfig, nameof(xmlConfig));

            if (!File.Exists(dllFile))
            {
                throw new DllNotFoundException(StringUtils.FormatInvariant("Could not find: '{0}'!", dllFile));
            }

            IPlugin plugin = null;

            AssemblyName an       = AssemblyName.GetAssemblyName(dllFile);
            Assembly     assembly = Assembly.Load(an);

            Type[] types = assembly.GetTypes();

            foreach (Type type in types)
            {
                if (type.IsInterface || type.IsAbstract)
                {
                    continue;
                }
                else
                {
                    if (type.GetInterface(typeof(IPluginFactory).FullName) != null)
                    {
                        IPluginFactory pluginFactory = (IPluginFactory)Activator.CreateInstance(type);
                        plugin = pluginFactory.GetPlugin(xmlConfig);
                    }
                }
            }

            if (plugin == null)
            {
                throw new EntryPointNotFoundException(StringUtils.FormatInvariant("No implementations of IPlugin were found in: '{0}'!", dllFile));
            }

            return(plugin);
        }
예제 #4
0
        /// <summary>
        /// Splits the full test name into it's namespace, class and test name components.
        /// </summary>
        /// <param name="testName">The full test name.</param>
        private void ParseTestName(string testName)
        {
            ThrowIf.StringIsNullOrWhiteSpace(testName, nameof(testName));

            var nameParts = testName.Split('.');

            TestNamespace = nameParts[0];

            if (nameParts.Length > 1)
            {
                // Find the last part that isn't the test function name.
                int testNameIndex;

                for (testNameIndex = 1; testNameIndex < nameParts.Length; ++testNameIndex)
                {
                    if (nameParts[testNameIndex].Contains("("))
                    {
                        break;
                    }
                }

                Logger.WriteDebug("testName = {0}", testName);
                Logger.WriteDebug("nameParts.Length = {0}", nameParts.Length);
                Logger.WriteDebug("testNameIndex = {0}", testNameIndex);

                TestClass = string.Join(".", nameParts, startIndex: 1, count: testNameIndex - 1);
                Logger.WriteDebug("TestClass = {0}", TestClass);

                // Everything else must be the test function name (and any parameters).
                if ((nameParts.Length > 2) && (testNameIndex < nameParts.Length))
                {
                    TestFunction = string.Join(".", nameParts, startIndex: testNameIndex, count: nameParts.Length - testNameIndex);
                    Logger.WriteDebug("TestFunction = {0}", TestFunction);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NUnitReporterPlugin"/> class.
        /// </summary>
        /// <param name="testInputFile">NTestController.xml file path.</param>
        public NUnitReporterPlugin(string testInputFile)
        {
            ThrowIf.StringIsNullOrWhiteSpace(testInputFile, nameof(testInputFile));

            _testInputFile = testInputFile;
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NUnitExecutorPlugin"/> class.
        /// </summary>
        /// <param name="xmlConfig">NTestController.xml file path.</param>
        public NUnitExecutorPlugin(string xmlConfig)
        {
            ThrowIf.StringIsNullOrWhiteSpace(xmlConfig, nameof(xmlConfig));

            _xmlConfig = xmlConfig;
        }