Example #1
0
        /// <summary>
        /// Gets the unit test provider for an assembly.  The framework only
        /// currently supports a single provider per test assembly, so if more
        /// than one registered provider can handle the assembly, at runtime an
        /// InvalidOperationException is thrown.
        /// </summary>
        /// <param name="harness">The test harness making the request.</param>
        /// <param name="testAssembly">Assembly reflection object.</param>
        /// <returns>The unit test provider for the test assembly.  Throws if
        /// more than one can process the assembly.  Returns null if there is
        /// not a provider for the assembly.</returns>
        public static IUnitTestProvider GetAssemblyProvider(ITestHarness harness, Assembly testAssembly)
        {
            List <IAssembly> assemblies = new List <IAssembly>();

            foreach (IUnitTestProvider provider in _providers)
            {
                IAssembly ia = provider.GetUnitTestAssembly(harness, testAssembly);
                ICollection <ITestClass> tests = ia.GetTestClasses();
                if (tests.Count > 0)
                {
                    assemblies.Add(ia);
                }
            }

            if (assemblies.Count > 1)
            {
                // TODO: Resource string needed for multiple providers in one
                // assembly
                throw new InvalidOperationException();
            }

            foreach (IAssembly a in assemblies)
            {
                return(a.Provider);
            }

            // Count == 0
            return(null);
        }
Example #2
0
        /// <summary>
        /// Gets the unit test provider for an assembly.  The framework only 
        /// currently supports a single provider per test assembly, so if more 
        /// than one registered provider can handle the assembly, at runtime an 
        /// InvalidOperationException is thrown.
        /// </summary>
        /// <param name="harness">The test harness making the request.</param>
        /// <param name="testAssembly">Assembly reflection object.</param>
        /// <returns>The unit test provider for the test assembly.  Throws if 
        /// more than one can process the assembly.  Returns null if there is 
        /// not a provider for the assembly.</returns>
        public static IUnitTestProvider GetAssemblyProvider(ITestHarness harness, Assembly testAssembly)
        {
            List<IAssembly> assemblies = new List<IAssembly>();
            foreach (IUnitTestProvider provider in _providers)
            {
                IAssembly ia = provider.GetUnitTestAssembly(harness, testAssembly);
                ICollection<ITestClass> tests = ia.GetTestClasses();
                if (tests.Count > 0) 
                {
                    assemblies.Add(ia);
                }
            }

            if (assemblies.Count > 1)
            {
                // TODO: Resource string needed for multiple providers in one 
                // assembly
                throw new InvalidOperationException();
            }

            foreach (IAssembly a in assemblies)
            {
                return a.Provider;
            }

            // Count == 0
            return null;
        }
Example #3
0
 /// <summary>
 /// VSTT unit test provider constructor; takes an assembly reference to 
 /// perform reflection on to retrieve all test class types. In this 
 /// implementation of an engine for the VSTT metadata, only a single 
 /// test Assembly can be utilized at a time for simplicity.
 /// </summary>
 /// <param name="testHarness">The unit test harness.</param>
 /// <param name="assemblyReference">Assembly reflection object.</param>
 /// <returns>Returns the assembly metadata interface.</returns>
 public IAssembly GetUnitTestAssembly(ITestHarness testHarness, Assembly assemblyReference)
 {
     if (_assemblyCache.ContainsKey(assemblyReference)) 
     {
         return _assemblyCache[assemblyReference];
     }
     else 
     {
         _assemblyCache[assemblyReference] = new UnitTestFrameworkAssembly(this, testHarness, assemblyReference);
         return _assemblyCache[assemblyReference];
     }
 }
Example #4
0
 /// <summary>
 /// VSTT unit test provider constructor; takes an assembly reference to
 /// perform reflection on to retrieve all test class types. In this
 /// implementation of an engine for the VSTT metadata, only a single
 /// test Assembly can be utilized at a time for simplicity.
 /// </summary>
 /// <param name="testHarness">The unit test harness.</param>
 /// <param name="assemblyReference">Assembly reflection object.</param>
 /// <returns>Returns the assembly metadata interface.</returns>
 public IAssembly GetUnitTestAssembly(ITestHarness testHarness, Assembly assemblyReference)
 {
     if (_assemblyCache.ContainsKey(assemblyReference))
     {
         return(_assemblyCache[assemblyReference]);
     }
     else
     {
         _assemblyCache[assemblyReference] = new UnitTestFrameworkAssembly(this, testHarness, assemblyReference);
         return(_assemblyCache[assemblyReference]);
     }
 }
Example #5
0
        /// <summary>
        /// Returns the IAssembly provider for an assembly.
        /// </summary>
        /// <param name="harness">Test harness object.</param>
        /// <param name="testAssembly">Assembly reflection object.</param>
        /// <returns>Returns null or an IAssembly instance.</returns>
        public static IAssembly GetAssemblyWrapper(ITestHarness harness, Assembly testAssembly)
        {
            IUnitTestProvider provider = GetAssemblyProvider(harness, testAssembly);

            return(provider == null ? null : provider.GetUnitTestAssembly(harness, testAssembly));
        }
Example #6
0
 /// <summary>
 /// Returns the IAssembly provider for an assembly.
 /// </summary>
 /// <param name="harness">Test harness object.</param>
 /// <param name="testAssembly">Assembly reflection object.</param>
 /// <returns>Returns null or an IAssembly instance.</returns>
 public static IAssembly GetAssemblyWrapper(ITestHarness harness, Assembly testAssembly)
 {
     IUnitTestProvider provider = GetAssemblyProvider(harness, testAssembly);
     return provider == null ? null : provider.GetUnitTestAssembly(harness, testAssembly);
 }