public static TestableXunitTestFrameworkDiscoverer Create(IAssemblyInfo assembly = null, ISourceInformationProvider sourceProvider = null, IMessageSink diagnosticMessageSink = null, IXunitTestCollectionFactory collectionFactory = null) { return(new TestableXunitTestFrameworkDiscoverer(assembly ?? Mocks.AssemblyInfo(), sourceProvider, diagnosticMessageSink, collectionFactory)); }
public static void NoAttribute() { var assembly = Mocks.AssemblyInfo(); var proxy = new TestFrameworkProxy(assembly, null); Assert.IsType <XunitTestFramework>(proxy.InnerTestFramework); }
public void NoAttribute() { var assembly = Mocks.AssemblyInfo(); var proxy = new TestFrameworkProxy(assembly, null, diagnosticSpy); Assert.IsType <XunitTestFramework>(proxy.InnerTestFramework); Assert.Empty(diagnosticMessages); }
public void NoAttribute() { var assembly = Mocks.AssemblyInfo(); var framework = ExtensibilityPointFactory.GetTestFramework(spy, assembly); Assert.IsType <XunitTestFramework>(framework); Assert.Empty(messages); }
public static ITestAssembly TestAssembly(IReflectionAttributeInfo[] attributes) { var assemblyInfo = Mocks.AssemblyInfo(attributes: attributes); var result = Substitute.For <ITestAssembly, InterfaceProxy <ITestAssembly> >(); result.Assembly.Returns(assemblyInfo); return(result); }
public static void Attribute_NoDiscoverer() { var attribute = Mocks.TestFrameworkAttribute(typeof(AttributeWithoutDiscoverer)); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var proxy = new TestFrameworkProxy(assembly, null); Assert.IsType <XunitTestFramework>(proxy.InnerTestFramework); }
public static ITestAssembly TestAssembly(ITypeInfo[] types = null, IReflectionAttributeInfo[] attributes = null) { var assemblyInfo = Mocks.AssemblyInfo(types, attributes); var result = Substitute.For <ITestAssembly>(); result.Assembly.Returns(assemblyInfo); return(result); }
public static void NonParallel() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[collection-per-class, non-parallel\]", discoverer.TestFrameworkDisplayName); }
public static void CustomCollectionFactory() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute <CustomTestCollectionFactory>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[my-custom-test-collection-factory, parallel\]", discoverer.TestFrameworkDisplayName); }
public static void ValidCustomFactory() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute <CustomTestCollectionFactory>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType <CustomTestCollectionFactory>(discoverer.TestCollectionFactory); }
public static TestableXunitTheoryTestCase Create(Action <IMessageBus> callback = null) { var fact = Mocks.FactAttribute(); var method = Mocks.MethodInfo(); var type = Mocks.TypeInfo(methods: new[] { method }); var assmInfo = Mocks.AssemblyInfo(types: new[] { type }); return(new TestableXunitTheoryTestCase(assmInfo, type, method, fact, callback ?? (sink => sink.QueueMessage(new SpyMessage())))); }
public void DefaultTestCollectionFactoryIsCollectionPerClass() { var assembly = Mocks.AssemblyInfo(); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <CollectionPerClassTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [collection-per-class, parallel]", discoverer.TestFrameworkDisplayName); }
public void Attribute_NoDiscoverer() { var attribute = Mocks.TestFrameworkAttribute(typeof(AttributeWithoutDiscoverer)); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var proxy = new TestFrameworkProxy(assembly, null, diagnosticSpy); Assert.IsType <XunitTestFramework>(proxy.InnerTestFramework); AssertSingleDiagnosticMessage("Assembly-level test framework attribute was not decorated with [TestFrameworkDiscoverer]"); }
public void Attribute_ThrowingTestFrameworkCtor() { var attribute = Mocks.TestFrameworkAttribute(typeof(AttributeWithThrowingTestFrameworkCtor)); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var proxy = new TestFrameworkProxy(assembly, null, diagnosticSpy); Assert.IsType <XunitTestFramework>(proxy.InnerTestFramework); AssertSingleDiagnosticMessage("Exception thrown during test framework construction: System.DivideByZeroException: Attempted to divide by zero."); }
public static ITestAssembly TestAssembly(string assemblyFileName, string configFileName = null, ITypeInfo[] types = null, IReflectionAttributeInfo[] attributes = null) { var assemblyInfo = Mocks.AssemblyInfo(types, attributes, assemblyFileName); var result = Substitute.For <ITestAssembly, InterfaceProxy <ITestAssembly> >(); result.Assembly.Returns(assemblyInfo); result.ConfigFileName.Returns(configFileName); return(result); }
public void Attribute_NoDiscoverer() { var attribute = Mocks.TestFrameworkAttribute <AttributeWithoutDiscoverer>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var framework = ExtensibilityPointFactory.GetTestFramework(spy, assembly); Assert.IsType <XunitTestFramework>(framework); AssertSingleDiagnosticMessage("Assembly-level test framework attribute was not decorated with [TestFrameworkDiscoverer]"); }
public void IncompatibleOrInvalidTypesGetDefaultBehavior(string factoryTypeName) { var attr = Mocks.CollectionBehaviorAttribute(factoryTypeName, "test.xunit2"); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <CollectionPerClassTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [collection-per-class, parallel]", discoverer.TestFrameworkDisplayName); }
public void UserCanChooseFromBuiltInCollectionFactories_NonParallel() { var attr = Mocks.CollectionBehaviorAttribute(CollectionBehavior.CollectionPerAssembly, disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <CollectionPerAssemblyTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [collection-per-assembly, non-parallel]", discoverer.TestFrameworkDisplayName); }
public static void AssemblyAttributeOverride( CollectionBehavior behavior, Type expectedFactoryType) { var behaviorAttribute = Mocks.CollectionBehaviorAttribute(behavior); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType(expectedFactoryType, discoverer.TestCollectionFactory); }
public static void SendsDiscoveryStartingMessage() { var typeInfo = Reflector.Wrap(typeof(ClassWithSingleTest)); var mockAssembly = Mocks.AssemblyInfo(types: new[] { typeInfo }); var framework = TestableXunitTestFrameworkDiscoverer.Create(mockAssembly); framework.Find("abc"); framework.Sink.Finished.WaitOne(); Assert.True(framework.Sink.StartSeen); }
public static void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType, string expectedDisplayText) { var attr = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType(expectedType, discoverer.TestCollectionFactory); Assert.Equal(String.Format("{0} [{1}, non-parallel]", XunitTestFrameworkDiscoverer.DisplayName, expectedDisplayText), discoverer.TestFrameworkDisplayName); }
public void Attribute_ThrowingDiscovererMethod() { Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var attribute = Mocks.TestFrameworkAttribute(typeof(AttributeWithThrowingDiscovererMethod)); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var proxy = new TestFrameworkProxy(assembly, null, diagnosticSpy); Assert.IsType <XunitTestFramework>(proxy.InnerTestFramework); AssertSingleDiagnosticMessage("Exception thrown during test framework discoverer construction: System.DivideByZeroException: Attempted to divide by zero."); }
public static void Attribute_WithDiscoverer() { var attribute = Mocks.TestFrameworkAttribute(typeof(AttributeWithDiscoverer)); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var sourceProvider = Substitute.For <ISourceInformationProvider>(); var proxy = new TestFrameworkProxy(assembly, sourceProvider); var testFramework = Assert.IsType <MyTestFramework>(proxy.InnerTestFramework); Assert.Same(sourceProvider, testFramework.SourceInformationProvider); }
public void UserCanChooseCustomCollectionFactory() { var factoryType = typeof(MyTestCollectionFactory); var attr = Mocks.CollectionBehaviorAttribute(factoryType.FullName, factoryType.Assembly.FullName); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <MyTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [My Factory, parallel]", discoverer.TestFrameworkDisplayName); }
public void NoAttribute() { var spy = SpyMessageSink.Capture(); TestContext.Current !.DiagnosticMessageSink = spy; var assembly = Mocks.AssemblyInfo(); var framework = ExtensibilityPointFactory.GetTestFramework(assembly); Assert.IsType <XunitTestFramework>(framework); Assert.Empty(spy.Messages); }
public static ITypeInfo TypeInfo(string typeName = "MockType", IMethodInfo[] methods = null, IReflectionAttributeInfo[] attributes = null, string assemblyFileName = null) { var result = Substitute.For <ITypeInfo, InterfaceProxy <ITypeInfo> >(); result.Name.Returns(typeName); result.GetMethods(false).ReturnsForAnyArgs(methods ?? new IMethodInfo[0]); var assemblyInfo = Mocks.AssemblyInfo(assemblyFileName: assemblyFileName); result.Assembly.Returns(assemblyInfo); result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg <string>(), attributes)); return(result); }
public void Attribute_ThrowingDiscovererMethod() { CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; var attribute = Mocks.TestFrameworkAttribute <AttributeWithThrowingDiscovererMethod>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); var framework = ExtensibilityPointFactory.GetTestFramework(spy, assembly); Assert.IsType <XunitTestFramework>(framework); AssertSingleDiagnosticMessage("Exception thrown during test framework discoverer construction: System.DivideByZeroException: Attempted to divide by zero."); }
public static void DoesNotCallSourceProviderWhenNotAskedFor() { var sourceProvider = Substitute.For <ISourceInformationProvider>(); var typeInfo = Reflector.Wrap(typeof(ClassWithSingleTest)); var mockAssembly = Mocks.AssemblyInfo(types: new[] { typeInfo }); var framework = TestableXunitTestFrameworkDiscoverer.Create(mockAssembly, sourceProvider); framework.Find(); framework.Sink.Finished.WaitOne(); sourceProvider.Received(0).GetSourceInformation(Arg.Any <ITestCase>()); }
public void Attribute_WithDiscoverer_NoMessageSink() { var spy = SpyMessageSink.Capture(); TestContext.Current !.DiagnosticMessageSink = spy; var attribute = Mocks.TestFrameworkAttribute <AttributeWithDiscoverer>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { attribute }); ExtensibilityPointFactory.GetTestFramework(assembly); Assert.Empty(spy.Messages); }
public static void ExcludesAbstractTypesFromDiscovery() { var abstractClassTypeInfo = Reflector.Wrap(typeof(AbstractClass)); var assembly = Mocks.AssemblyInfo(types: new[] { abstractClassTypeInfo }); var framework = Substitute.For <TestableXunitTestFrameworkDiscoverer>(assembly); framework.FindTestsForClass(null).ReturnsForAnyArgs(true); framework.Find(); framework.Sink.Finished.WaitOne(); framework.Received(0).FindTestsForClass(Arg.Any <ITestClass>(), Arg.Any <bool>()); }