コード例 #1
0
        /// <summary>
        /// Core implementation to discover unit tests in a given test class.
        /// </summary>
        /// <param name="type">The test class.</param>
        /// <param name="includeSourceInformation">Set to <c>true</c> to attempt to include source information.</param>
        /// <param name="messageBus">The message sink to send discovery messages to.</param>
        /// <returns>Returns <c>true</c> if discovery should continue; <c>false</c> otherwise.</returns>
        protected virtual bool FindImpl(ITypeInfo type, bool includeSourceInformation, IMessageBus messageBus)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            var    testCollection   = TestCollectionFactory.Get(type);

            try
            {
                if (!String.IsNullOrEmpty(assemblyInfo.AssemblyPath))
                {
                    Directory.SetCurrentDirectory(Path.GetDirectoryName(assemblyInfo.AssemblyPath));
                }

                foreach (var method in type.GetMethods(includePrivateMethods: true))
                {
                    var factAttribute = method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
                    if (factAttribute != null)
                    {
                        var discovererAttribute = factAttribute.GetCustomAttributes(typeof(TestCaseDiscovererAttribute)).FirstOrDefault();
                        if (discovererAttribute != null)
                        {
                            var args           = discovererAttribute.GetConstructorArguments().Cast <string>().ToList();
                            var discovererType = Reflector.GetType(args[1], args[0]);
                            if (discovererType != null)
                            {
                                var discoverer = GetDiscoverer(discovererType);

                                if (discoverer != null)
                                {
                                    foreach (var testCase in discoverer.Discover(testCollection, assemblyInfo, type, method, factAttribute))
                                    {
                                        if (!messageBus.QueueMessage(new TestCaseDiscoveryMessage(UpdateTestCaseWithSourceInfo(testCase, includeSourceInformation))))
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                messageAggregator.Add(new EnvironmentalWarning {
                                    Message = String.Format("Could not create discoverer type '{0}, {1}'", args[0], args[1])
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                messageAggregator.Add(new EnvironmentalWarning {
                    Message = String.Format("Exception during discovery:{0}{1}", Environment.NewLine, ex)
                });
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectory);
            }

            return(true);
        }
コード例 #2
0
 protected override ITestClass CreateTestClass(ITypeInfo typeInfo)
 {
     if (IsSpecFlowTypeInfo(typeInfo))
     {
         return(new SpecFlowFeatureTestClass(TestCollectionFactory.Get(typeInfo), typeInfo));
     }
     return(base.CreateTestClass(typeInfo));
 }
コード例 #3
0
 protected override ITestClass CreateTestClass(ITypeInfo @class)
 {
     return(new TestClass(TestCollectionFactory.Get(@class), @class));
 }
コード例 #4
0
 /// <inheritdoc/>
 protected internal override _ITestClass CreateTestClass(_ITypeInfo @class) =>
 new TestClass(TestCollectionFactory.Get(@class), @class);