public void SetUp() { var path = typeof(NavigationDataProviderTests).GetTypeInfo().Assembly.Location; //string path = Path.Combine(Directory.GetCurrentDirectory(), "dotnet-test-nunit.test.dll"); _provider = NavigationDataProvider.GetNavigationDataProvider(path); Assert.That(_provider, Is.Not.Null, $"Could not create the NavigationDataProvider for {path}"); }
public void CauseLookupFailure() { using (var navigationProvider = new NavigationDataProvider(_existingAssemblyPath, Logger, MetadataProvider)) { navigationProvider.GetNavigationData("NonExistentFixture", "SomeTest"); navigationProvider.GetNavigationData("NonExistentFixture", "SomeTest"); } }
public void SetUp() { _provider = new NavigationDataProvider( #if NETCOREAPP1_0 Path.Combine(TestContext.CurrentContext.TestDirectory, "NUnit.VisualStudio.TestAdapter.Tests.dll")); #else Path.Combine(TestContext.CurrentContext.TestDirectory, "NUnit.VisualStudio.TestAdapter.Tests.exe")); #endif }
/// <summary> /// Constructs a <see cref="BaseTestListener"/> /// </summary> /// <param name="options">The command line options passed into this run</param> /// <param name="assemblyPath">The full path of the assembly that is being executed or explored</param> public BaseTestListener(CommandLineOptions options, string assemblyPath) { Options = options; _assemblyPath = assemblyPath; _provider = NavigationDataProvider.GetNavigationDataProvider(assemblyPath); }
public void SetUp() { _provider = new NavigationDataProvider( typeof(NavigationDataTests).GetTypeInfo().Assembly.Location, Substitute.For <ITestLogger>()); }
public void SetUp() { _provider = new NavigationDataProvider(ThisAssemblyPath); }
public void SetUp() { _provider = new NavigationDataProvider( Path.Combine(TestContext.CurrentContext.TestDirectory, "NUnit.VisualStudio.TestAdapter.Tests.dll")); }
public static void AsyncMethodWithAttributeDefinedOutsideAdapterDirectory(bool withBindingRedirect) { using (var dir = new TempDirectory()) { // The tests must run in the same AppDomain as VSTest for DiaSession to work, // but that VSTest has already loaded an old version of S.C.Immutable in this AppDomain. // To avoid MissingMethodException, it’s necessary to only deal with Roslyn in a separate AppDomain. using (var compileInvoker = new AppDomainInvoker()) { compileInvoker.Invoke( marshalled => { var baseCompilation = CSharpCompilation.Create(null) .AddReferences(MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location)) .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var dependencyAssemblyPath = Path.Combine(marshalled.outputDir, "AssemblyOutsideAdapterDir.dll"); var dependencyBaseCompilation = baseCompilation .WithAssemblyName("AssemblyOutsideAdapterDir") .AddSyntaxTrees(CSharpSyntaxTree.ParseText("public sealed class AttributeDefinedOutsideAdapterDir : System.Attribute { }")); if (marshalled.withBindingRedirect) { dependencyBaseCompilation = dependencyBaseCompilation .WithOptions(baseCompilation.Options .WithPublicSign(true) .WithCryptoKeyFile(Path.Combine(Path.GetDirectoryName(typeof(NavigationDataProviderTests).Assembly.Location), "temp.snk"))); } var dependencyAssembly = dependencyBaseCompilation .AddSyntaxTrees(CSharpSyntaxTree.ParseText("[assembly: System.Reflection.AssemblyVersion(\"1.0.1.0\")]")) .Emit(Path.Combine(marshalled.outputDir, "AssemblyOutsideAdapterDir.dll")); if (!dependencyAssembly.Success) { Assert.Fail("Broken test"); } MetadataReference reference; if (marshalled.withBindingRedirect) { reference = dependencyBaseCompilation .AddSyntaxTrees(CSharpSyntaxTree.ParseText("[assembly: System.Reflection.AssemblyVersion(\"1.0.0.0\")]")) .ToMetadataReference(); } else { reference = MetadataReference.CreateFromFile(dependencyAssemblyPath); } using (var outputDll = File.Create(Path.Combine(marshalled.outputDir, "DependentAssembly.dll"))) using (var outputPdb = File.Create(Path.Combine(marshalled.outputDir, "DependentAssembly.pdb"))) { var dependentAssembly = baseCompilation .WithAssemblyName("DependentAssembly") .AddReferences(reference) .AddSyntaxTrees(CSharpSyntaxTree.ParseText("public class TestClass { [AttributeDefinedOutsideAdapterDir] public async System.Threading.Tasks.Task AsyncMethod() { } }")) .Emit(outputDll, outputPdb, options: new EmitOptions(debugInformationFormat: DebugInformationFormat.PortablePdb)); if (!dependentAssembly.Success) { Assert.Fail("Broken test"); } } }, (outputDir: dir.Path, withBindingRedirect)); } var assemblyPath = Path.Combine(dir, "DependentAssembly.dll"); if (withBindingRedirect) { File.WriteAllText( assemblyPath + ".config", @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <runtime> <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1""> <dependentAssembly> <assemblyIdentity name=""AssemblyOutsideAdapterDir"" publicKeyToken=""0bf10b92861e5519"" culture=""neutral"" /> <bindingRedirect oldVersion=""0.0.0.0-1.0.1.0"" newVersion=""1.0.1.0"" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>"); } using (var metadataProvider = NavigationDataProvider.CreateMetadataProvider(assemblyPath)) { var result = metadataProvider.GetStateMachineType(assemblyPath, "TestClass", "AsyncMethod"); Assert.That(result, Is.Not.Null); } } }