/// <summary>
 /// A container type that handles an entire test class throughout the 
 /// test run.
 /// </summary>
 /// <param name="filter">Test run filter object.</param>
 /// <param name="testHarness">The unit test harness.</param>
 /// <param name="testClass">The test class metadata interface.</param>
 /// <param name="instance">The object instance.</param>
 /// <param name="provider">The unit test provider.</param>
 public TestClassManager(TestRunFilter filter, UnitTestHarness testHarness, ITestClass testClass, object instance, IUnitTestProvider provider) : base(testHarness, provider)
 {
     _filter = filter;
     _testClass = testClass;
     _testExecutionQueue = new CompositeWorkItem();
     _instance = instance;
 }
Esempio n. 2
0
 public override List<ITestMethod> GetTestMethods(ITestClass test, object instance)
 {
     return new List<ITestMethod>
     {
         _method
     };
 }
 /// <summary>
 /// Constructor for a test method manager, which handles executing a single test method 
 /// for a unit test provider.
 /// </summary>
 /// <param name="testHarness">The unit test harness object.</param>
 /// <param name="testClass">The test class metadata object.</param>
 /// <param name="testMethod">The test method metadata object.</param>
 /// <param name="instance">The test class instance.</param>
 /// <param name="provider">The unit test provider.</param>
 public TestMethodManager(UnitTestHarness testHarness, ITestClass testClass, ITestMethod testMethod, object instance, IUnitTestProvider provider)
     : base(testHarness, provider)
 {
     _testClass = testClass;
     _testMethod = testMethod;
     _instance = instance;
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new test run filter using an existing settings file.
 /// </summary>
 /// <param name="test">The test class metadata.</param>
 /// <param name="method">The test method metadata.</param>
 public RetryTestRunFilter(ITestClass test, ITestMethod method) : base(null, null)
 {
     TestRunName = "Retry of " + test.Name + " " + method.Name;
     
     _test = test;
     _method = method;
 }
 /// <summary>
 /// Creates a result record.
 /// </summary>
 /// <param name="method">Test method metadata object.</param>
 /// <param name="testClass">Test class metadata object.</param>
 /// <param name="result">Test result object.</param>
 /// <param name="exception">Exception instance, if any.</param>
 public ScenarioResult(ITestMethod method, ITestClass testClass, TestOutcome result, Exception exception)
 {
     TestClass = testClass;
     TestMethod = method;
     Exception = exception;
     Result = result;
 }
        /// <summary>
        /// Initializes a new instance of the TestClassData type.
        /// </summary>
        /// <param name="testClass">The test class metadata.</param>
        /// <param name="parent">The parent test assembly data object.</param>
        public TestClassData(ITestClass testClass, TestAssemblyData parent)
        {
            _methods = new ObservableCollection<TestMethodData>();
            _parent = parent;

            Name = testClass.Name;
            Namespace = testClass.Namespace;
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestMethod"/> class.
        /// </summary>
        /// <param name="class">The test class</param>
        /// <param name="method">The test method</param>
        public TestMethod(ITestClass @class, IMethodInfo method)
        {
            Guard.ArgumentNotNull("class", @class);
            Guard.ArgumentNotNull("method", method);

            Method = method;
            TestClass = @class;
        }
Esempio n. 8
0
        /// <inheritdoc/>
        public void Deserialize(IXunitSerializationInfo info)
        {
            TestClass = info.GetValue<ITestClass>("TestClass");

            var methodName = info.GetValue<string>("MethodName");

            Method = TestClass.Class.GetMethod(methodName, includePrivateMethod: true);
        }
Esempio n. 9
0
        /// <inheritdoc/>
        public void SetData(XunitSerializationInfo info)
        {
            TestClass = info.GetValue<ITestClass>("TestClass");

            var methodName = info.GetString("MethodName");

            Method = TestClass.Class.GetMethod(methodName, includePrivateMethod: false);
        }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassCleanupFailure"/> class.
 /// </summary>
 public TestClassCleanupFailure(IEnumerable<ITestCase> testCases, ITestClass testClass, string[] exceptionTypes, string[] messages, string[] stackTraces, int[] exceptionParentIndices)
     : base(testCases, testClass)
 {
     StackTraces = stackTraces;
     Messages = messages;
     ExceptionTypes = exceptionTypes;
     ExceptionParentIndices = exceptionParentIndices;
 }
Esempio n. 11
0
        /// <inheritdoc/>
        protected TestMethod(SerializationInfo info, StreamingContext context)
        {
            TestClass = info.GetValue<ITestClass>("TestClass");

            var methodName = info.GetString("MethodName");

            Method = TestClass.Class.GetMethod(methodName, includePrivateMethod: false);
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassFinished"/> class.
 /// </summary>
 public TestClassFinished(IEnumerable<ITestCase> testCases, ITestClass testClass, decimal executionTime, int testsRun, int testsFailed, int testsSkipped)
     : base(testCases, testClass)
 {
     ExecutionTime = executionTime;
     TestsRun = testsRun;
     TestsFailed = testsFailed;
     TestsSkipped = testsSkipped;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassCleanupFailure"/> class.
 /// </summary>
 public TestClassCleanupFailure(IEnumerable<ITestCase> testCases, ITestClass testClass, Exception ex)
     : base(testCases, testClass)
 {
     var failureInfo = ExceptionUtility.ConvertExceptionToFailureInformation(ex);
     ExceptionTypes = failureInfo.ExceptionTypes;
     Messages = failureInfo.Messages;
     StackTraces = failureInfo.StackTraces;
     ExceptionParentIndices = failureInfo.ExceptionParentIndices;
 }
Esempio n. 14
0
 public TestClassDispatcher(
     UnitTestHarness testHarness, ITestClass testClass, 
     object instance, IUnitTestProvider provider) 
     : base(testHarness, provider)
 {
     _testClass = testClass;
     _testExecutionQueue = new TestWorkItemDispatcher();
     _instance = instance;
 }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new failure web control.
        /// </summary>
        /// <param name="testClass">The test class metadata object.</param>
        /// <param name="summaryControl">The overall summary control.</param>
        public FailureControl(ITestClass testClass, FailureSummaryControl summaryControl) : base()
        {
            _summary = summaryControl;

            Margin.All = 0;
            Margin.Top = 4;
            Margin.Bottom = 2;

            CreateClassHeader(testClass.Name);
        }
		protected override Task<RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable<IXunitTestCase> testCases)
		{
			var combinedFixtures = new Dictionary<Type, object>(assemblyFixtureMappings);
			foreach (var kvp in CollectionFixtureMappings)
				combinedFixtures[kvp.Key] = kvp.Value;

			// We've done everything we need, so let the built-in types do the rest of the heavy lifting

			return new XunitTestClassRunner(testClass, @class, testCases, diagnosticMessageSink, MessageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), CancellationTokenSource, combinedFixtures).RunAsync();
		}
 /// <summary>
 /// Logs and Exception that was intercepted or observed.
 /// </summary>
 /// <param name="exception">The actual Exception instance.</param>
 /// <param name="test">The test class metadata.</param>
 /// <param name="method">The test method metadata.</param>
 public void LogException(Exception exception, ITestClass test, ITestMethod method)
 {
   string message = String.Format(CultureInfo.CurrentCulture, Properties.UnitTestMessage.LogException, exception.GetType().ToString(), exception.Message);
   LogMessage m = Create(LogMessageType.Error, message);
   MarkUnitTestMessage(m);
   DecorateTestGranularity(m, TestGranularity.TestScenario);
   m[UnitTestLogDecorator.ActualException] = exception;
   m[UnitTestLogDecorator.TestClassMetadata] = test;
   m[UnitTestLogDecorator.TestMethodMetadata] = method;
   Enqueue(m);
 }
 /// <summary>
 /// No Exception was intercepted, yet one was expected.
 /// </summary>
 /// <param name="expectedExceptionType">The expected exception type.</param>
 /// <param name="test">The test class metadata.</param>
 /// <param name="method">The test method metadata.</param>
 public void NoExceptionWhenExpected(Type expectedExceptionType, ITestClass test, ITestMethod method)
 {
   string message = String.Format(CultureInfo.CurrentCulture, Properties.UnitTestMessage.LogNoException, expectedExceptionType.ToString());
   LogMessage m = Create(LogMessageType.Error, message);
   MarkUnitTestMessage(m);
   DecorateTestGranularity(m, TestGranularity.TestScenario);
   m[UnitTestLogDecorator.IncorrectExceptionMessage] = true;
   m[UnitTestLogDecorator.ExpectedExceptionType] = expectedExceptionType;
   m[UnitTestLogDecorator.TestClassMetadata] = test;
   m[UnitTestLogDecorator.TestMethodMetadata] = method;
   Enqueue(m);
 }
        protected override bool FindTestsForType(ITestClass testClass,
                                                 bool includeSourceInformation,
                                                 IMessageBus messageBus,
                                                 ITestFrameworkDiscoveryOptions discoveryOptions)
        {
            var methodDisplay = discoveryOptions.MethodDisplayOrDefault();

            foreach (var method in testClass.Class.GetMethods(includePrivateMethods: true))
                if (!FindTestsForMethod(new TestMethod(testClass, method), methodDisplay, includeSourceInformation, messageBus))
                    return false;

            return true;
        }
 public void IncorrectException(Type expectedExceptionType, Type actualExceptionType, ITestClass test, ITestMethod method)
 {
     string message = String.Format(System.Globalization.CultureInfo.CurrentCulture, Properties.UnitTestMessage.LogIncorrectExceptionType, actualExceptionType.Name, expectedExceptionType.Name);
     LogMessage m = Create(LogMessageType.Error, message);
     MarkUnitTestMessage(m);
     DecorateTestGranularity(m, TestGranularity.TestScenario);
     m[UnitTestLogDecorator.IncorrectExceptionMessage] = true;
     m[UnitTestLogDecorator.ExpectedExceptionType] = expectedExceptionType;
     m[UnitTestLogDecorator.ActualExceptionType] = actualExceptionType;
     m[UnitTestLogDecorator.TestClassMetadata] = test;
     m[UnitTestLogDecorator.TestMethodMetadata] = method;
     Enqueue(m);
 }
		public VsixTestClassRunner (IVsClient vsClient,
								   ITestClass testClass,
								   IReflectionTypeInfo @class,
								   IEnumerable<IXunitTestCase> testCases,
								   IMessageSink diagnosticMessageSink,
								   IMessageBus messageBus,
								   ITestCaseOrderer testCaseOrderer,
								   ExceptionAggregator aggregator,
								   CancellationTokenSource cancellationTokenSource,
								   IDictionary<Type, object> collectionFixtureMappings)
			: base (testClass, @class, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource, collectionFixtureMappings)
		{
			this.vsClient = vsClient;
		}
		protected override Task<RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable<IXunitTestCase> testCases)
		{
			foreach (var fixtureType in @class.Type.GetTypeInfo().ImplementedInterfaces
					.Where(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == typeof(IAssemblyFixture<>))
					.Select(i => i.GetTypeInfo().GenericTypeArguments.Single())
					// First pass at filtering out before locking
					.Where(i => !assemblyFixtureMappings.ContainsKey(i)))
			{
				// ConcurrentDictionary's GetOrAdd does not lock around the value factory call, so we need
				// to do it ourselves.
				lock (assemblyFixtureMappings)
					if (!assemblyFixtureMappings.ContainsKey(fixtureType))
						Aggregator.Run(() => assemblyFixtureMappings.Add(fixtureType, Activator.CreateInstance(fixtureType)));
			}

			// Don't want to use .Concat + .ToDictionary because of the possibility of overriding types,
			// so instead we'll just let collection fixtures override assembly fixtures.
			var combinedFixtures = new Dictionary<Type, object>(assemblyFixtureMappings);
			foreach (var kvp in CollectionFixtureMappings)
				combinedFixtures[kvp.Key] = kvp.Value;

			// We've done everything we need, so let the built-in types do the rest of the heavy lifting
			return new XunitTestClassRunner(testClass, @class, testCases, diagnosticMessageSink, MessageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), CancellationTokenSource, combinedFixtures).RunAsync();
		}
Esempio n. 23
0
        /// <summary>
        /// Gets or creates the data model object for a test class.
        /// </summary>
        /// <param name="testClass">The test class.</param>
        /// <returns>Returns the data object.</returns>
        public TestClassData GetClassModel(ITestClass testClass)
        {
            TestClassData data;
            if (!_classData.TryGetValue(testClass, out data))
            {
                TestAssemblyData tad = GetAssemblyModel(testClass.Assembly);
                data = new TestClassData(testClass, tad);
                _classData.Add(testClass, data);

                // Make sure in parent collection
                tad.TestClasses.Add(data);
            }

            return data;
        }
 public virtual bool FindTestsForClass(ITestClass testClass, bool includeSourceInformation = false)
 {
     using (var messageBus = new MessageBus(Sink))
         return base.FindTestsForType(testClass, includeSourceInformation, messageBus, TestFrameworkOptions.ForDiscovery());
 }
 /// <summary>
 /// Initializes a new instance of the TestClassCompletedEventArgs
 /// class.
 /// </summary>
 /// <param name="testClass">Test class metadata.</param>
 /// <param name="harness">The harness instance.</param>
 public TestClassCompletedEventArgs(ITestClass testClass, UnitTestHarness harness)
     : base(harness)
 {
     TestClass = testClass;
 }
Esempio n. 26
0
 /// <summary>
 /// Initializes a new instance of the TestMethodStartingEventArgs type.
 /// </summary>
 /// <param name="testMethod">The test method metadata.</param>
 /// <param name="testClass">The test class metadata.</param>
 /// <param name="harness">The test harness instance.</param>
 public TestMethodStartingEventArgs(ITestMethod testMethod, ITestClass testClass, UnitTestHarness harness)
     : base(harness)
 {
     TestMethod = testMethod;
     TestClass  = testClass;
 }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassMessage"/> class.
 /// </summary>
 public TestClassMessage(IEnumerable<ITestCase> testCases, ITestClass testClass)
     : base(testCases, testClass.TestCollection)
 {
     TestClass = testClass;
 }
Esempio n. 28
0
 protected override Task <RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable <IXunitTestCase> testCases)
 {
     return(Task.FromResult(new RunSummary()));
 }
Esempio n. 29
0
        public static void RegisterClassFixturesAndModules(this ContainerBuilder builder, ITestClass testClass, IReflectionTypeInfo @class)
        {
            foreach (var fixtureType in @class.Type.GetTypeParametersFromInterfaces(typeof(IClassFixture <>)))
            {
                builder.RegisterModules(fixtureType);
                builder.RegisterType(fixtureType).AsSelf().SingleInstance();
            }

            if (testClass.TestCollection.CollectionDefinition != null)
            {
                var declarationType = ((IReflectionTypeInfo)testClass.TestCollection.CollectionDefinition).Type;
                foreach (var fixtureType in declarationType.GetTypeParametersFromInterfaces(typeof(IClassFixture <>)))
                {
                    builder.RegisterModules(fixtureType);
                    builder.RegisterType(fixtureType).AsSelf().SingleInstance();
                }
            }
        }
 public NestedClassWithInterfaces(ITestClass childOne, IMultipleConstructors childTwo)
 {
     ChildOne = childOne;
     ChildTwo = childTwo;
 }
Esempio n. 31
0
 public HomeController(ITestClass klass)
 {
     _klass = klass;
 }
Esempio n. 32
0
 protected override Task <RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo typeInfo, IEnumerable <IXunitTestCase> testCases)
 {
     return(new ClassRunner(testClass, typeInfo, testCases, _diagnosticMessageSink, MessageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), CancellationTokenSource, CollectionFixtureMappings, _assemblyFixtureMappings).RunAsync());
 }
Esempio n. 33
0
        protected override bool FindTestsForType(ITestClass testClass, bool includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
        {
            EnsureArg.IsNotNull(testClass, nameof(testClass));
            EnsureArg.IsNotNull(messageBus, nameof(messageBus));
            EnsureArg.IsNotNull(discoveryOptions, nameof(discoveryOptions));

            var attributeInfo = testClass.Class.GetCustomAttributes(typeof(FixtureArgumentSetsAttribute)).SingleOrDefault();

            if (attributeInfo == null)
            {
                return(base.FindTestsForType(testClass, includeSourceInformation, messageBus, discoveryOptions));
            }

            // get the class-level parameter sets in the form (Arg1.OptionA, Arg1.OptionB), (Arg2.OptionA, Arg2.OptionB)
            SingleFlag[][] classLevelOpenParameterSets = ExpandEnumFlagsFromAttributeData(attributeInfo);

            // convert these to the form (Arg1.OptionA, Arg2.OptionA), (Arg1.OptionA, Arg2.OptionB), (Arg1.OptionB, Arg2.OptionA), (Arg1.OptionB, Arg2.OptionB)
            SingleFlag[][] classLevelClosedParameterSets = CartesianProduct(classLevelOpenParameterSets).Select(e => e.ToArray()).ToArray();

            foreach (var method in testClass.Class.GetMethods(true))
            {
                IAttributeInfo fixtureParameterAttributeInfo = method.GetCustomAttributes(typeof(FixtureArgumentSetsAttribute)).SingleOrDefault();

                SingleFlag[][] closedSets = classLevelClosedParameterSets;

                if (fixtureParameterAttributeInfo != null)
                {
                    // get the method-level parameter sets in the form (Arg1.OptionA, Arg1.OptionB), (Arg2.OptionA, Arg2.OptionB)
                    SingleFlag[][] methodLevelOpenParameterSets = ExpandEnumFlagsFromAttributeData(fixtureParameterAttributeInfo);

                    bool hasOverride = false;
                    for (int i = 0; i < methodLevelOpenParameterSets.Length; i++)
                    {
                        if (methodLevelOpenParameterSets[i]?.Length > 0)
                        {
                            hasOverride = true;
                        }
                        else
                        {
                            // means take the class-level set
                            methodLevelOpenParameterSets[i] = classLevelOpenParameterSets[i];
                        }
                    }

                    if (hasOverride)
                    {
                        // convert to the form (Arg1.OptionA, Arg2.OptionA), (Arg1.OptionA, Arg2.OptionB), (Arg1.OptionB, Arg2.OptionA), (Arg1.OptionB, Arg2.OptionB)
                        closedSets = CartesianProduct(methodLevelOpenParameterSets).Select(e => e.ToArray()).ToArray();
                    }
                }

                foreach (SingleFlag[] closedVariant in closedSets)
                {
                    var closedVariantTestClass  = new TestClassWithFixtureArguments(testClass.TestCollection, testClass.Class, closedVariant);
                    var closedVariantTestMethod = new TestMethod(closedVariantTestClass, method);

                    if (!FindTestsForMethod(closedVariantTestMethod, includeSourceInformation, messageBus, discoveryOptions))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 34
0
 public GenericTestMethod(ITestClass @class, IMethodInfo method, ITypeInfo genericArgument)
 {
     this.Method          = method;
     this.TestClass       = @class;
     this.GenericArgument = genericArgument;
 }
Esempio n. 35
0
 void LogTestClassDetails(ITestClass klass, Action <string> log = null, StringBuilder sb = null)
 {
     do_log($"   Class name: {klass.Class.Name}", log, sb);
     do_log($"   Class assembly: {klass.Class.Assembly.Name}", OnDebug, sb);
     do_log($"   Class assembly path: {klass.Class.Assembly.AssemblyPath}", OnDebug, sb);
 }
 /// <summary>
 /// Initializes a new instance of the TestClassStartingEventArgs type.
 /// </summary>
 /// <param name="testClass">The test class metadata.</param>
 /// <param name="harness">The unit test harness reference.</param>
 public TestClassStartingEventArgs(ITestClass testClass, UnitTestHarness harness)
     : base(harness)
 {
     TestClass = testClass;
 }
Esempio n. 37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassMessage"/> class.
 /// </summary>
 public TestClassMessage(IEnumerable <ITestCase> testCases, ITestClass testClass)
     : base(testCases, testClass.TestCollection)
 {
     TestClass = testClass;
 }
Esempio n. 38
0
 private bool IsSpecFlowTest(ITestClass testClass)
 {
     return(testClass is SpecFlowFeatureTestClass);
 }
Esempio n. 39
0
 /// <summary>
 /// Creates a new TestMethodManager.
 /// </summary>
 /// <param name="provider">The unit test provider.</param>
 /// <param name="testClass">The test class metadata.</param>
 /// <param name="method">The test method metadata.</param>
 /// <param name="instance">The test class instance.</param>
 /// <returns>Returns a new TestMethodManager.</returns>
 public TestMethodManager CreateTestMethodManager(IUnitTestProvider provider, ITestClass testClass, ITestMethod method, object instance)
 {
     return(new TestMethodManager(_harness, testClass, method, instance, provider));
 }
Esempio n. 40
0
 public ClassRunner(ITestClass testClass, IReflectionTypeInfo typeInfo, IEnumerable <IXunitTestCase> testCases, IMessageSink diagnosticMessageSink, IMessageBus messageBus, ITestCaseOrderer testCaseOrderer, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource, IDictionary <Type, object> collectionFixtureMappings, IReadOnlyDictionary <Type, object> assemblyFixtureMappings, XunitTestEnvironment testEnvironment)
     : base(testClass, typeInfo, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource, collectionFixtureMappings)
 {
     _assemblyFixtureMappings = assemblyFixtureMappings;
     _testEnvironment         = testEnvironment;
 }
Esempio n. 41
0
 public VsRemoteTestClassRunner(ITestClass testClass, IReflectionTypeInfo @class, ExceptionAggregator aggregator, Dictionary <Type, object> collectionFixtureMappings)
     : base(testClass, @class, Enumerable.Empty <IXunitTestCase>(), new NullMessageSink(), null,
            new DefaultTestCaseOrderer(new NullMessageSink()), aggregator, new CancellationTokenSource(), collectionFixtureMappings)
 {
 }
        XElement CreateTestResultElement(ITestResultMessage testResult, string resultText)
        {
            ITest       test       = testResult.Test;
            ITestCase   testCase   = testResult.TestCase;
            ITestMethod testMethod = testCase.TestMethod;
            ITestClass  testClass  = testMethod.TestClass;

            var collectionElement = GetTestCollectionElement(testClass.TestCollection);
            var testResultElement =
                new XElement("test",
                             new XAttribute("name", XmlEscape(test.DisplayName)),
                             new XAttribute("type", testClass.Class.Name),
                             new XAttribute("method", testMethod.Method.Name),
                             new XAttribute("time", testResult.ExecutionTime.ToString(CultureInfo.InvariantCulture)),
                             new XAttribute("result", resultText)
                             );
            var testOutput = testResult.Output;

            if (!string.IsNullOrWhiteSpace(testOutput))
            {
                testResultElement.Add(new XElement("output", new XCData(testOutput)));
            }

            ISourceInformation sourceInformation = testCase.SourceInformation;

            if (sourceInformation != null)
            {
                var fileName = sourceInformation.FileName;
                if (fileName != null)
                {
                    testResultElement.Add(new XAttribute("source-file", fileName));
                }

                var lineNumber = sourceInformation.LineNumber;
                if (lineNumber != null)
                {
                    testResultElement.Add(new XAttribute("source-line", lineNumber.GetValueOrDefault()));
                }
            }

            var traits = testCase.Traits;

            if (traits != null && traits.Count > 0)
            {
                var traitsElement = new XElement("traits");

                foreach (var keyValuePair in traits)
                {
                    foreach (var val in keyValuePair.Value)
                    {
                        traitsElement.Add(
                            new XElement("trait",
                                         new XAttribute("name", XmlEscape(keyValuePair.Key)),
                                         new XAttribute("value", XmlEscape(val))
                                         )
                            );
                    }
                }

                testResultElement.Add(traitsElement);
            }

            collectionElement.Add(testResultElement);

            if (_logger != null)
            {
                _logger.LogMessage($"collectionElement: {collectionElement}");
            }

            return(testResultElement);
        }
Esempio n. 43
0
 public CustomTestClassRunner(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable <IXunitTestCase> testCases, IMessageSink diagnosticMessageSink, IMessageBus messageBus, ITestCaseOrderer testCaseOrderer, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource, IDictionary <Type, object> collectionFixtureMappings)
     : base(testClass, @class, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource, collectionFixtureMappings)
 {
 }
 /// <summary>
 /// Core implementation to discover unit tests in a given test class.
 /// </summary>
 /// <param name="testClass">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>
 /// <param name="discoveryOptions">The options used by the test framework during discovery.</param>
 /// <returns>Returns <c>true</c> if discovery should continue; <c>false</c> otherwise.</returns>
 protected abstract bool FindTestsForType(ITestClass testClass, bool includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions);
        public void IncorrectException(Type expectedExceptionType, Type actualExceptionType, ITestClass test, ITestMethod method)
        {
            string     message = String.Format(CultureInfo.CurrentCulture, Properties.UnitTestMessage.LogIncorrectExceptionType, actualExceptionType.Name, expectedExceptionType.Name);
            LogMessage m       = Create(LogMessageType.Error, message);

            MarkUnitTestMessage(m);
            DecorateTestGranularity(m, TestGranularity.TestScenario);
            m[UnitTestLogDecorator.IncorrectExceptionMessage] = true;
            m[UnitTestLogDecorator.ExpectedExceptionType]     = expectedExceptionType;
            m[UnitTestLogDecorator.ActualExceptionType]       = actualExceptionType;
            m[UnitTestLogDecorator.TestClassMetadata]         = test;
            m[UnitTestLogDecorator.TestMethodMetadata]        = method;
            Enqueue(m);
        }
        protected override Task <RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable <IXunitTestCase> testCases)
        {
            RunTestClassAsync_AggregatorResult = Aggregator.ToException();

            return(Task.FromResult(new RunSummary()));
        }
Esempio n. 47
0
 protected override Task <RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable <IXunitTestCase> testCases)
 {
     return(new VsixTestClassRunner(_vs, testClass, @class, testCases, _diagnosticMessageSink, MessageBus, TestCaseOrderer,
                                    Aggregator, CancellationTokenSource, CollectionFixtureMappings).RunAsync());
 }
Esempio n. 48
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XunitTestMethod"/> class.
 /// </summary>
 public XunitTestMethod(ITestClass testClass, IMethodInfo method)
 {
     Method    = method;
     TestClass = testClass;
 }
Esempio n. 49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassMessage"/> class.
 /// </summary>
 internal TestClassMessage(ITestCase testCase, ITestClass testClass)
     : base(testCase, testClass.TestCollection)
 {
     TestClass = testClass;
 }
 protected override Task <RunSummary> RunTestClassAsync(ITestClass testClass,
                                                        IReflectionTypeInfo @class, IEnumerable <IXunitTestCase> testCases) =>
 new DependencyInjectionTestClassRunner(_provider, testClass, @class, testCases,
                                        _diagnosticMessageSink, MessageBus, TestCaseOrderer,
                                        new ExceptionAggregator(Aggregator), CancellationTokenSource, CollectionFixtureMappings)
 .RunAsync();
Esempio n. 51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestClassMessage"/> class.
 /// </summary>
 internal TestClassMessage(ITestCase testCase, ITestClass testClass)
     : base(testCase, testClass.TestCollection)
 {
     TestClass = testClass;
 }
Esempio n. 52
0
        public static async Task <RunSummary> RunAsync(CancellationToken token, Func <Task <RunSummary> >[] tasks, ITestClass testClass)
        {
            var summary = new RunSummary();

            if (tasks.Length > 1 && IsParallelizable(testClass))
            {
                var results = await Task.WhenAll(tasks.Select(task => RunOnThreadPool(token, task)));

                foreach (var result in results)
                {
                    summary.Aggregate(result);
                }
            }
            else
            {
                foreach (var task in tasks)
                {
                    summary.Aggregate(await task());
                }
            }

            return(summary);
        }
 protected sealed override bool FindTestsForType(ITestClass testClass, bool includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
 {
     return FindTestsForClass(testClass, includeSourceInformation);
 }
Esempio n. 54
0
 protected sealed override bool FindTestsForType(ITestClass testClass, bool includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
 {
     return(FindTestsForClass(testClass, includeSourceInformation));
 }
 /// <summary>
 /// Initializes a new instance of the TestMethodStartingEventArgs type.
 /// </summary>
 /// <param name="testMethod">The test method metadata.</param>
 /// <param name="testClass">The test class metadata.</param>
 /// <param name="harness">The test harness instance.</param>
 public TestMethodStartingEventArgs(ITestMethod testMethod, ITestClass testClass, UnitTestHarness harness) : base(harness)
 {
     TestMethod = testMethod;
     TestClass = testClass;
 }
Esempio n. 56
0
 public virtual bool FindTestsForClass(ITestClass testClass, bool includeSourceInformation = false)
 {
     using (var messageBus = new MessageBus(Visitor))
         return(base.FindTestsForType(testClass, includeSourceInformation, messageBus, TestFrameworkOptions.ForDiscovery()));
 }
        public virtual List<ITestMethod> GetTestMethods(ITestClass test, object instance)
        {
            List<ITestMethod> methods = new List<ITestMethod>(test.GetTestMethods());

            // Get any dynamically provided test methods
            IProvideDynamicTestMethods provider = instance as IProvideDynamicTestMethods;
            if (provider != null)
            {
                IEnumerable<ITestMethod> dynamicTestMethods = provider.GetDynamicTestMethods();
                if (dynamicTestMethods != null)
                {
                    methods.AddRange(dynamicTestMethods);
                }
            }

            FilterTestMethods(methods);
            SortTestMethods(methods);
            return methods;
        }
Esempio n. 58
0
 public TestClass6(ITestClass myProperty)
 {
     MyProperty = myProperty;
 }
Esempio n. 59
0
 public TestCoreClass(ITestClass testClass)
 {
     TestClass = testClass;
 }
Esempio n. 60
0
 /// <summary>
 /// Creates a new TestClassManager.
 /// </summary>
 /// <param name="provider">The unit test provider.</param>
 /// <param name="filter">The run filter.</param>
 /// <param name="testClass">The test class metadata.</param>
 /// <param name="instance">The test class instance.</param>
 /// <returns>Returns a new TestClassManager.</returns>
 public TestClassManager CreateTestClassManager(IUnitTestProvider provider, TestRunFilter filter, ITestClass testClass, object instance)
 {
     return(new TestClassManager(filter, _harness, testClass, instance, provider));
 }