diff --git a/src/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs b/src/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs index e755bab6..11aadeaa 100644 --- a/src/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs +++ b/src/Machine.Specifications.Runner.Utility.Specs/CompileContext.cs @@ -74,7 +74,7 @@ public AssemblyPath Compile(string code, params string[] references) parameters.ReferencedAssemblies.AddRange(new [] { "System.dll", - "Machine.Specifications.Core.dll", + "Machine.Specifications.dll", "Machine.Specifications.Should.dll", "netstandard.dll" }); diff --git a/src/Machine.Specifications.Runner.Utility/AppDomainRunner.cs b/src/Machine.Specifications.Runner.Utility/AppDomainRunner.cs index b91a7f26..ed2194ed 100644 --- a/src/Machine.Specifications.Runner.Utility/AppDomainRunner.cs +++ b/src/Machine.Specifications.Runner.Utility/AppDomainRunner.cs @@ -154,7 +154,6 @@ private ISpecificationRunner CreateRunnerInSeparateAppDomain(AppDomain appDomain } var mspecAssemblyFilename = Path.Combine(path, "Machine.Specifications.dll"); - var coreAssemblyFilename = Path.Combine(path, "Machine.Specifications.Core.dll"); AssemblyName mspecAssemblyName = null; @@ -162,10 +161,6 @@ private ISpecificationRunner CreateRunnerInSeparateAppDomain(AppDomain appDomain { mspecAssemblyName = AssemblyName.GetAssemblyName(mspecAssemblyFilename); } - else if (File.Exists(coreAssemblyFilename)) - { - mspecAssemblyName = AssemblyName.GetAssemblyName(coreAssemblyFilename); - } if (mspecAssemblyName == null) { diff --git a/src/Machine.Specifications.Runner.VisualStudio/Discovery/BuiltInSpecificationDiscoverer.cs b/src/Machine.Specifications.Runner.VisualStudio/Discovery/BuiltInSpecificationDiscoverer.cs deleted file mode 100644 index 56a18c92..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Discovery/BuiltInSpecificationDiscoverer.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Machine.Specifications.Runner.VisualStudio.Helpers; - -namespace Machine.Specifications.Runner.VisualStudio.Discovery -{ - public class BuiltInSpecificationDiscoverer : ISpecificationDiscoverer - { - public IEnumerable DiscoverSpecs(string assemblyFilePath) - { -#if NETFRAMEWORK - using (var scope = new IsolatedAppDomainExecutionScope(assemblyFilePath)) - { - var discoverer = scope.CreateInstance(); -#else - var discoverer = new TestDiscoverer(); -#endif - return discoverer.DiscoverTests(assemblyFilePath).ToList(); -#if NETFRAMEWORK - } -#endif - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Discovery/ISpecificationDiscoverer.cs b/src/Machine.Specifications.Runner.VisualStudio/Discovery/ISpecificationDiscoverer.cs deleted file mode 100644 index e0e723f4..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Discovery/ISpecificationDiscoverer.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Machine.Specifications.Runner.VisualStudio.Discovery -{ - public interface ISpecificationDiscoverer - { - IEnumerable DiscoverSpecs(string assemblyPath); - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Discovery/SpecTestCase.cs b/src/Machine.Specifications.Runner.VisualStudio/Discovery/SpecTestCase.cs deleted file mode 100644 index 84e22f5d..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Discovery/SpecTestCase.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; - -namespace Machine.Specifications.Runner.VisualStudio.Discovery -{ -#if NETFRAMEWORK - [Serializable] -#endif - public class SpecTestCase - { - public string Subject { get; set; } - - public string ContextFullType { get; set; } - - public object ContextDisplayName { get; set; } - - public string ClassName { get; set; } - - public string SpecificationDisplayName { get; set; } - - public string SpecificationName { get; set; } - - public string BehaviorFieldName { get; set; } - - public string BehaviorFieldType { get; set; } - - public string CodeFilePath { get; set; } - - public int LineNumber { get; set; } - - public string[] Tags { get; set; } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Discovery/TestDiscoverer.cs b/src/Machine.Specifications.Runner.VisualStudio/Discovery/TestDiscoverer.cs deleted file mode 100644 index 829c00fa..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Discovery/TestDiscoverer.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Machine.Specifications.Explorers; -using Machine.Specifications.Model; -using Machine.Specifications.Runner.VisualStudio.Helpers; -using Machine.Specifications.Runner.VisualStudio.Navigation; - -namespace Machine.Specifications.Runner.VisualStudio.Discovery -{ - public class TestDiscoverer -#if NETFRAMEWORK - : MarshalByRefObject -#endif - { -#if NETFRAMEWORK - [System.Security.SecurityCritical] - public override object InitializeLifetimeService() - { - return null; - } -#endif - private readonly PropertyInfo behaviorProperty = typeof(BehaviorSpecification).GetProperty("BehaviorFieldInfo"); - - public IEnumerable DiscoverTests(string assemblyPath) - { - var assemblyExplorer = new AssemblyExplorer(); - - var assembly = AssemblyHelper.Load(assemblyPath); - var contexts = assemblyExplorer.FindContextsIn(assembly); - - using (var session = new NavigationSession(assemblyPath)) - { - return contexts.SelectMany(context => CreateTestCase(context, session)).ToList(); - } - } - - private IEnumerable CreateTestCase(Context context, NavigationSession session) - { - foreach (var spec in context.Specifications.ToList()) - { - var testCase = new SpecTestCase - { - ClassName = context.Type.Name, - ContextFullType = context.Type.FullName, - ContextDisplayName = GetContextDisplayName(context.Type), - SpecificationName = spec.FieldInfo.Name, - SpecificationDisplayName = spec.Name - }; - - string fieldDeclaringType; - - if (spec.FieldInfo.DeclaringType.GetTypeInfo().IsGenericType && !spec.FieldInfo.DeclaringType.GetTypeInfo().IsGenericTypeDefinition) - fieldDeclaringType = spec.FieldInfo.DeclaringType.GetGenericTypeDefinition().FullName; - else - fieldDeclaringType = spec.FieldInfo.DeclaringType.FullName; - - var locationInfo = session.GetNavigationData(fieldDeclaringType, spec.FieldInfo.Name); - - if (locationInfo != null) - { - testCase.CodeFilePath = locationInfo.CodeFile; - testCase.LineNumber = locationInfo.LineNumber; - } - - if (spec is BehaviorSpecification behaviorSpec) - PopulateBehaviorField(testCase, behaviorSpec); - - if (context.Tags != null) - testCase.Tags = context.Tags.Select(tag => tag.Name).ToArray(); - - if (context.Subject != null) - testCase.Subject = context.Subject.FullConcern; - - yield return testCase; - } - } - - private void PopulateBehaviorField(SpecTestCase testCase, BehaviorSpecification specification) - { - if (behaviorProperty?.GetValue(specification) is FieldInfo field) - { - testCase.BehaviorFieldName = field.Name; - testCase.BehaviorFieldType = field.FieldType.GenericTypeArguments.FirstOrDefault()?.FullName; - } - } - - private string GetContextDisplayName(Type contextType) - { - var displayName = contextType.Name.Replace("_", " "); - - if (contextType.IsNested) - { - return GetContextDisplayName(contextType.DeclaringType) + " " + displayName; - } - - return displayName; - } - } - -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/AssemblyLocationAwareRunListener.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/AssemblyLocationAwareRunListener.cs deleted file mode 100644 index 6bdd0e75..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/AssemblyLocationAwareRunListener.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public class AssemblyLocationAwareRunListener : ISpecificationRunListener - { - private readonly IEnumerable assemblies; - - public AssemblyLocationAwareRunListener(IEnumerable assemblies) - { - this.assemblies = assemblies ?? throw new ArgumentNullException(nameof(assemblies)); - } - - public void OnAssemblyStart(AssemblyInfo assembly) - { - var loadedAssembly = assemblies.FirstOrDefault(a => a.GetName().Name.Equals(assembly.Name, StringComparison.OrdinalIgnoreCase)); - - Directory.SetCurrentDirectory(Path.GetDirectoryName(loadedAssembly.Location)); - } - - public void OnAssemblyEnd(AssemblyInfo assembly) - { - } - - public void OnRunStart() - { - } - - public void OnRunEnd() - { - } - - public void OnContextStart(ContextInfo context) - { - } - - public void OnContextEnd(ContextInfo context) - { - } - - public void OnSpecificationStart(SpecificationInfo specification) - { - } - - public void OnSpecificationEnd(SpecificationInfo specification, Result result) - { - } - - public void OnFatalError(ExceptionResult exception) - { - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/IFrameworkLogger.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/IFrameworkLogger.cs deleted file mode 100644 index 36ab2734..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/IFrameworkLogger.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public interface IFrameworkLogger - { - void SendErrorMessage(string message, Exception exception); - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/ISpecificationExecutor.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/ISpecificationExecutor.cs deleted file mode 100644 index 77e538c6..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/ISpecificationExecutor.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using Machine.Specifications.Runner.VisualStudio.Helpers; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public interface ISpecificationExecutor - { - void RunAssemblySpecifications(string assemblyPath, IEnumerable specifications, Uri adapterUri, IFrameworkHandle frameworkHandle); - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/ISpecificationFilterProvider.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/ISpecificationFilterProvider.cs deleted file mode 100644 index d7e1735e..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/ISpecificationFilterProvider.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public interface ISpecificationFilterProvider - { - IEnumerable FilteredTests(IEnumerable testCases, IRunContext runContext, IFrameworkHandle frameworkHandle); - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/ProxyAssemblySpecificationRunListener.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/ProxyAssemblySpecificationRunListener.cs deleted file mode 100644 index ee35c6d8..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/ProxyAssemblySpecificationRunListener.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System; -using Machine.Specifications.Runner.VisualStudio.Helpers; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public class ProxyAssemblySpecificationRunListener : -#if NETFRAMEWORK - MarshalByRefObject, -#endif - ISpecificationRunListener, IFrameworkLogger - { - private readonly IFrameworkHandle frameworkHandle; - - private readonly string assemblyPath; - - private readonly Uri executorUri; - - private ContextInfo currentContext; - - private RunStats currentRunStats; - - public ProxyAssemblySpecificationRunListener(string assemblyPath, IFrameworkHandle frameworkHandle, Uri executorUri) - { - this.frameworkHandle = frameworkHandle ?? throw new ArgumentNullException(nameof(frameworkHandle)); - this.assemblyPath = assemblyPath ?? throw new ArgumentNullException(nameof(assemblyPath)); - this.executorUri = executorUri ?? throw new ArgumentNullException(nameof(executorUri)); - } - -#if NETFRAMEWORK - [System.Security.SecurityCritical] - public override object InitializeLifetimeService() - { - return null; - } -#endif - - public void OnFatalError(ExceptionResult exception) - { - if (currentRunStats != null) - { - currentRunStats.Stop(); - currentRunStats = null; - } - - frameworkHandle.SendMessage(TestMessageLevel.Error, - "Machine Specifications Visual Studio Test Adapter - Fatal error while executing test." + - Environment.NewLine + exception); - } - - public void OnSpecificationStart(SpecificationInfo specification) - { - var testCase = ConvertSpecificationToTestCase(specification); - frameworkHandle.RecordStart(testCase); - currentRunStats = new RunStats(); - } - - public void OnSpecificationEnd(SpecificationInfo specification, Result result) - { - if (currentRunStats != null) - { - currentRunStats.Stop(); - } - - var testCase = ConvertSpecificationToTestCase(specification); - - frameworkHandle.RecordEnd(testCase, MapSpecificationResultToTestOutcome(result)); - frameworkHandle.RecordResult(ConverResultToTestResult(testCase, result, currentRunStats)); - } - - public void OnContextStart(ContextInfo context) - { - currentContext = context; - } - - public void OnContextEnd(ContextInfo context) - { - currentContext = null; - } - - private TestCase ConvertSpecificationToTestCase(SpecificationInfo specification) - { - var vsTestId = specification.ToVisualStudioTestIdentifier(currentContext); - - return new TestCase(vsTestId.FullyQualifiedName, executorUri, assemblyPath) - { - DisplayName = $"{currentContext?.TypeName}.{specification.FieldName}", - }; - } - - private static TestOutcome MapSpecificationResultToTestOutcome(Result result) - { - switch (result.Status) - { - case Status.Failing: - return TestOutcome.Failed; - - case Status.Passing: - return TestOutcome.Passed; - - case Status.Ignored: - return TestOutcome.Skipped; - - case Status.NotImplemented: - return TestOutcome.NotFound; - - default: - return TestOutcome.None; - } - } - - private static TestResult ConverResultToTestResult(TestCase testCase, Result result, RunStats runStats) - { - var testResult = new TestResult(testCase) - { - ComputerName = Environment.MachineName, - Outcome = MapSpecificationResultToTestOutcome(result), - DisplayName = testCase.DisplayName - }; - - if (result.Exception != null) - { - testResult.ErrorMessage = result.Exception.Message; - testResult.ErrorStackTrace = result.Exception.ToString(); - } - - if (runStats != null) - { - testResult.StartTime = runStats.Start; - testResult.EndTime = runStats.End; - testResult.Duration = runStats.Duration; - } - - return testResult; - } - - public void OnAssemblyEnd(AssemblyInfo assembly) - { - } - - public void OnAssemblyStart(AssemblyInfo assembly) - { - } - - public void OnRunEnd() - { - } - - public void OnRunStart() - { - } - - public void SendErrorMessage(string message, Exception exception) - { - frameworkHandle?.SendMessage(TestMessageLevel.Error, message + Environment.NewLine + exception); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/RunStats.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/RunStats.cs deleted file mode 100644 index f669b178..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/RunStats.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Diagnostics; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public class RunStats - { - private readonly Stopwatch stopwatch = new Stopwatch(); - - public RunStats() - { - stopwatch.Start(); - Start = DateTime.Now; - } - - public DateTimeOffset Start { get; } - - public DateTimeOffset End { get; private set; } - - public TimeSpan Duration => stopwatch.Elapsed; - - public void Stop() - { - stopwatch.Stop(); - - End = Start + stopwatch.Elapsed; - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/SingleBehaviorTestRunListenerWrapper.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/SingleBehaviorTestRunListenerWrapper.cs deleted file mode 100644 index 86649d7c..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/SingleBehaviorTestRunListenerWrapper.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using Machine.Specifications.Runner.VisualStudio.Helpers; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - /// - /// The purpose of this class is to ignore everything, but a single specification's notifications. - /// Also because [Behavior] It's get reported as belonging to the Behavior class rather than test class - /// we need to map from one to the other for Visual Studio to capture the results. - /// - public class SingleBehaviorTestRunListenerWrapper : ISpecificationRunListener - { - private readonly ISpecificationRunListener runListener; - - private readonly VisualStudioTestIdentifier listenFor; - - private ContextInfo currentContext; - - public SingleBehaviorTestRunListenerWrapper(ISpecificationRunListener runListener, VisualStudioTestIdentifier listenFor) - { - this.runListener = runListener ?? throw new ArgumentNullException(nameof(runListener)); - this.listenFor = listenFor ?? throw new ArgumentNullException(nameof(listenFor)); - } - - public void OnContextEnd(ContextInfo context) - { - currentContext = null; - runListener.OnContextEnd(context); - } - - public void OnContextStart(ContextInfo context) - { - currentContext = context; - runListener.OnContextStart(context); - } - - public void OnSpecificationEnd(SpecificationInfo specification, Result result) - { - if (listenFor != null && !listenFor.Equals(specification.ToVisualStudioTestIdentifier(currentContext))) - { - return; - } - - runListener.OnSpecificationEnd(specification, result); - } - - public void OnSpecificationStart(SpecificationInfo specification) - { - if (listenFor != null && !listenFor.Equals(specification.ToVisualStudioTestIdentifier(currentContext))) - { - return; - } - - runListener.OnSpecificationStart(specification); - } - - public void OnAssemblyEnd(AssemblyInfo assembly) - { - runListener.OnAssemblyEnd(assembly); - } - - public void OnAssemblyStart(AssemblyInfo assembly) - { - runListener.OnAssemblyStart(assembly); - } - - public void OnFatalError(ExceptionResult exception) - { - runListener.OnFatalError(exception); - } - - public void OnRunEnd() - { - runListener.OnRunEnd(); - } - - public void OnRunStart() - { - runListener.OnRunStart(); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/SpecificationExecutor.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/SpecificationExecutor.cs deleted file mode 100644 index 055468d3..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/SpecificationExecutor.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using Machine.Specifications.Runner.VisualStudio.Helpers; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public class SpecificationExecutor : ISpecificationExecutor - { - public void RunAssemblySpecifications(string assemblyPath, - IEnumerable specifications, - Uri adapterUri, - IFrameworkHandle frameworkHandle) - { - assemblyPath = Path.GetFullPath(assemblyPath); - -#if NETFRAMEWORK - using (var scope = new IsolatedAppDomainExecutionScope(assemblyPath)) - { - var executor = scope.CreateInstance(); -#else - var executor = new TestExecutor(); -#endif - var listener = new ProxyAssemblySpecificationRunListener(assemblyPath, frameworkHandle, adapterUri); - - executor.RunTestsInAssembly(assemblyPath, specifications, listener); -#if NETFRAMEWORK - } -#endif - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/SpecificationFilterProvider.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/SpecificationFilterProvider.cs deleted file mode 100644 index e076449d..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/SpecificationFilterProvider.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Machine.Specifications.Model; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public class SpecificationFilterProvider : ISpecificationFilterProvider - { - private static readonly TestProperty TagProperty = - TestProperty.Register(nameof(Tag), nameof(Tag), typeof(string), typeof(TestCase)); - - private static readonly TestProperty SubjectProperty = - TestProperty.Register(nameof(Subject), nameof(Subject), typeof(string), typeof(TestCase)); - - private readonly Dictionary testCaseProperties = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - [TestCaseProperties.FullyQualifiedName.Id] = TestCaseProperties.FullyQualifiedName, - [TestCaseProperties.DisplayName.Id] = TestCaseProperties.DisplayName - }; - - private readonly Dictionary traitProperties = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - [TagProperty.Id] = TagProperty, - [SubjectProperty.Id] = SubjectProperty - }; - - private readonly string[] supportedProperties; - - public SpecificationFilterProvider() - { - supportedProperties = testCaseProperties.Keys - .Concat(traitProperties.Keys) - .ToArray(); - } - - public IEnumerable FilteredTests(IEnumerable testCases, IRunContext runContext, IFrameworkHandle handle) - { - var filterExpression = runContext.GetTestCaseFilter(supportedProperties, propertyName => - { - if (testCaseProperties.TryGetValue(propertyName, out var testProperty)) - { - return testProperty; - } - if (traitProperties.TryGetValue(propertyName, out var traitProperty)) - { - return traitProperty; - } - return null; - }); - - handle?.SendMessage(TestMessageLevel.Informational, $"Machine Specifications Visual Studio Test Adapter - Filter property set '{filterExpression?.TestCaseFilterValue}'"); - - if (filterExpression == null) - { - return testCases; - } - - var filteredTests = testCases - .Where(x => filterExpression.MatchTestCase(x, propertyName => GetPropertyValue(propertyName, x))); - - return filteredTests; - } - - private object GetPropertyValue(string propertyName, TestObject testCase) - { - if (testCaseProperties.TryGetValue(propertyName, out var testProperty)) - { - if (testCase.Properties.Contains(testProperty)) - { - return testCase.GetPropertyValue(testProperty); - } - } - - if (traitProperties.TryGetValue(propertyName, out var traitProperty)) - { - var val = TraitContains(testCase, traitProperty.Id); - - if (val.Length == 1) - { - return val[0]; - } - - if (val.Length > 1) - { - return val; - } - } - - return null; - } - - private static string[] TraitContains(TestObject testCase, string traitName) - { - return testCase?.Traits? - .Where(x => x.Name == traitName) - .Select(x => x.Value) - .ToArray(); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Execution/TestExecutor.cs b/src/Machine.Specifications.Runner.VisualStudio/Execution/TestExecutor.cs deleted file mode 100644 index 9958339c..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Execution/TestExecutor.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Machine.Specifications.Runner.Impl; -using Machine.Specifications.Runner.VisualStudio.Helpers; - -namespace Machine.Specifications.Runner.VisualStudio.Execution -{ - public class TestExecutor -#if NETFRAMEWORK - : MarshalByRefObject -#endif - { -#if NETFRAMEWORK - [System.Security.SecurityCritical] - public override object InitializeLifetimeService() - { - return null; - } -#endif - - private DefaultRunner CreateRunner(Assembly assembly, ISpecificationRunListener specificationRunListener) - { - var listener = new AggregateRunListener(new[] { - specificationRunListener, - new AssemblyLocationAwareRunListener(new[] { assembly }) - }); - - return new DefaultRunner(listener, RunOptions.Default); - } - - public void RunTestsInAssembly(string pathToAssembly, IEnumerable specsToRun, ISpecificationRunListener specificationRunListener) - { - DefaultRunner mspecRunner = null; - Assembly assemblyToRun = null; - - try - { - assemblyToRun = AssemblyHelper.Load(pathToAssembly); - mspecRunner = CreateRunner(assemblyToRun, specificationRunListener); - - var specsByContext = specsToRun.GroupBy(x => x.ContainerTypeFullName); - - mspecRunner.StartRun(assemblyToRun); - - foreach (var specs in specsByContext) - { - var fields = specs.Select(x => x.FieldName); - - mspecRunner.RunType(assemblyToRun, assemblyToRun.GetType(specs.Key), fields.ToArray()); - } - } - catch (Exception e) - { - specificationRunListener.OnFatalError(new ExceptionResult(e)); - } - finally - { - try - { - if (mspecRunner != null && assemblyToRun != null) - { - mspecRunner.EndRun(assemblyToRun); - } - } - catch (Exception exception) - { - try - { - var frameworkLogger = specificationRunListener as IFrameworkLogger; - - frameworkLogger?.SendErrorMessage("Machine Specifications Visual Studio Test Adapter - Error Ending Test Run.", exception); - } - catch - { - // ignored - } - } - } - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Helpers/AssemblyHelper.cs b/src/Machine.Specifications.Runner.VisualStudio/Helpers/AssemblyHelper.cs deleted file mode 100644 index 9712a802..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Helpers/AssemblyHelper.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.IO; -using System.Reflection; - -namespace Machine.Specifications.Runner.VisualStudio.Helpers -{ - internal static class AssemblyHelper - { - public static Assembly Load(string path) - { - try - { -#if NETCOREAPP - return Assembly.Load(new AssemblyName(Path.GetFileNameWithoutExtension(path))); -#else - return Assembly.LoadFile(path); -#endif - } catch (Exception e) - { - Console.WriteLine(e); - throw; - } - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Helpers/IsolatedAppDomainExecutionScope.cs b/src/Machine.Specifications.Runner.VisualStudio/Helpers/IsolatedAppDomainExecutionScope.cs deleted file mode 100644 index a622c547..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Helpers/IsolatedAppDomainExecutionScope.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Reflection.Metadata; -using System.Threading; - -namespace Machine.Specifications.Runner.VisualStudio.Helpers -{ -#if NETFRAMEWORK - public class IsolatedAppDomainExecutionScope : IDisposable - where T : MarshalByRefObject, new() - { - private readonly string assemblyPath; - - private readonly string appName = typeof(IsolatedAppDomainExecutionScope<>).Assembly.GetName().Name; - - private AppDomain appDomain; - - public IsolatedAppDomainExecutionScope(string assemblyPath) - { - if (string.IsNullOrEmpty(assemblyPath)) - { - throw new ArgumentException($"{nameof(assemblyPath)} is null or empty.", nameof(assemblyPath)); - } - - this.assemblyPath = assemblyPath; - } - - public T CreateInstance() - { - if (appDomain == null) - { - // Because we need to copy files around - we create a global cross-process mutex here to avoid multi-process race conditions - // in the case where both of those are true: - // 1. VSTest is told to run tests in parallel, so it spawns multiple processes - // 2. There are multiple test assemblies in the same directory - using (var mutex = new Mutex(false, $"{appName}_{Path.GetDirectoryName(assemblyPath).Replace(Path.DirectorySeparatorChar, '_')}")) - { - try - { - mutex.WaitOne(TimeSpan.FromMinutes(1)); - } - catch (AbandonedMutexException) - { - } - - try - { - appDomain = CreateAppDomain(assemblyPath, appName); - } - finally - { - try - { - mutex.ReleaseMutex(); - } - catch - { - } - } - } - } - - return (T)appDomain.CreateInstanceAndUnwrap(typeof(T).Assembly.FullName, typeof(T).FullName); - } - - - private static AppDomain CreateAppDomain(string assemblyPath, string appName) - { - // This is needed in the following two scenarios, so that the target test dll and its dependencies are loaded correctly: - // - // 1. pre-.NET Standard (old) .csproj and Visual Studio IDE Test Explorer run - // 2. vstest.console.exe run against .dll which is not in the build output folder (e.g. packaged build artifact) - // - CopyRequiredRuntimeDependencies(new[] - { - typeof(IsolatedAppDomainExecutionScope<>).Assembly, - typeof(MetadataReaderProvider).Assembly - }, Path.GetDirectoryName(assemblyPath)); - - var setup = new AppDomainSetup(); - setup.ApplicationName = appName; - setup.ShadowCopyFiles = "true"; - setup.ApplicationBase = setup.PrivateBinPath = Path.GetDirectoryName(assemblyPath); - setup.CachePath = Path.Combine(Path.GetTempPath(), appName, Guid.NewGuid().ToString()); - setup.ConfigurationFile = Path.Combine(Path.GetDirectoryName(assemblyPath), (Path.GetFileName(assemblyPath) + ".config")); - - return AppDomain.CreateDomain($"{appName}.dll", null, setup); - } - - private static void CopyRequiredRuntimeDependencies(IEnumerable assemblies, string destination) - { - foreach (Assembly assembly in assemblies) - { - var sourceAssemblyFile = assembly.Location; - var destinationAssemblyFile = Path.Combine(destination, Path.GetFileName(sourceAssemblyFile)); - - // file doesn't exist or is older - if (!File.Exists(destinationAssemblyFile) || File.GetLastWriteTimeUtc(sourceAssemblyFile) > File.GetLastWriteTimeUtc(destinationAssemblyFile)) - { - CopyWithoutLockingSourceFile(sourceAssemblyFile, destinationAssemblyFile); - } - } - } - - private static void CopyWithoutLockingSourceFile(string sourceFile, string destinationFile) - { - const int bufferSize = 10 * 1024; - - using (var inputFile = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize)) - using (var outputFile = new FileStream(destinationFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize)) - { - var buffer = new byte[bufferSize]; - int bytes; - - while ((bytes = inputFile.Read(buffer, 0, buffer.Length)) > 0) - { - outputFile.Write(buffer, 0, bytes); - } - } - } - - public void Dispose() - { - if (appDomain != null) - { - try - { - var cacheDirectory = appDomain.SetupInformation.CachePath; - - AppDomain.Unload(appDomain); - appDomain = null; - - if (Directory.Exists(cacheDirectory)) - { - Directory.Delete(cacheDirectory, true); - } - } - catch - { - // TODO: Logging here - } - } - } - } -#endif -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Helpers/NamingConversionExtensions.cs b/src/Machine.Specifications.Runner.VisualStudio/Helpers/NamingConversionExtensions.cs deleted file mode 100644 index 86d4dc6a..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Helpers/NamingConversionExtensions.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Globalization; -using Machine.Specifications.Model; -using Machine.Specifications.Runner.VisualStudio.Discovery; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; - -namespace Machine.Specifications.Runner.VisualStudio.Helpers -{ - public static class NamingConversionExtensions - { - public static VisualStudioTestIdentifier ToVisualStudioTestIdentifier(this SpecificationInfo specification, ContextInfo context) - { - return new VisualStudioTestIdentifier(string.Format(CultureInfo.InvariantCulture, "{0}::{1}", context?.TypeName ?? specification.ContainingType, specification.FieldName)); - } - - public static VisualStudioTestIdentifier ToVisualStudioTestIdentifier(this SpecTestCase specification) - { - return new VisualStudioTestIdentifier(string.Format(CultureInfo.InvariantCulture, "{0}::{1}", specification.ContextFullType, specification.SpecificationName)); - } - - public static VisualStudioTestIdentifier ToVisualStudioTestIdentifier(this TestCase testCase) - { - return new VisualStudioTestIdentifier(testCase.FullyQualifiedName); - } - - public static VisualStudioTestIdentifier ToVisualStudioTestIdentifier(this Specification specification, Context context) - { - return new VisualStudioTestIdentifier(string.Format(CultureInfo.InvariantCulture, "{0}::{1}", context.Type.FullName, specification.FieldInfo.Name)); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Helpers/SpecTestHelper.cs b/src/Machine.Specifications.Runner.VisualStudio/Helpers/SpecTestHelper.cs deleted file mode 100644 index 6b571dd8..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Helpers/SpecTestHelper.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Diagnostics; -using Machine.Specifications.Runner.VisualStudio.Discovery; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; - -namespace Machine.Specifications.Runner.VisualStudio.Helpers -{ - public static class SpecTestHelper - { - public static TestCase GetTestCaseFromMspecTestCase(string source, SpecTestCase mspecTestCase, Uri testRunnerUri) - { - var vsTest = mspecTestCase.ToVisualStudioTestIdentifier(); - - var testCase = new TestCase(vsTest.FullyQualifiedName, testRunnerUri, source) - { - DisplayName = $"{mspecTestCase.ContextDisplayName} it {mspecTestCase.SpecificationDisplayName}", - CodeFilePath = mspecTestCase.CodeFilePath, - LineNumber = mspecTestCase.LineNumber - }; - - var classTrait = new Trait("ClassName", mspecTestCase.ClassName); - var subjectTrait = new Trait("Subject", string.IsNullOrEmpty(mspecTestCase.Subject) ? "No Subject" : mspecTestCase.Subject); - - testCase.Traits.Add(classTrait); - testCase.Traits.Add(subjectTrait); - - if (mspecTestCase.Tags != null) - { - foreach (var tag in mspecTestCase.Tags) - { - if (!string.IsNullOrEmpty(tag)) - { - var tagTrait = new Trait("Tag", tag); - testCase.Traits.Add(tagTrait); - } - } - } - - if (!string.IsNullOrEmpty(mspecTestCase.BehaviorFieldName)) - { - testCase.Traits.Add(new Trait("BehaviorField", mspecTestCase.BehaviorFieldName)); - } - - if (!string.IsNullOrEmpty(mspecTestCase.BehaviorFieldType)) - { - testCase.Traits.Add(new Trait("BehaviorType", mspecTestCase.BehaviorFieldType)); - } - - Debug.WriteLine($"TestCase {testCase.FullyQualifiedName}"); - - return testCase; - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Helpers/VisualStudioTestIdentifier.cs b/src/Machine.Specifications.Runner.VisualStudio/Helpers/VisualStudioTestIdentifier.cs deleted file mode 100644 index 39fb4919..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Helpers/VisualStudioTestIdentifier.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Globalization; - -namespace Machine.Specifications.Runner.VisualStudio.Helpers -{ -#if NETFRAMEWORK - [Serializable] -#endif - public class VisualStudioTestIdentifier - { - public VisualStudioTestIdentifier() - { - } - - public VisualStudioTestIdentifier(string containerTypeFullName, string fieldName) - : this(string.Format(CultureInfo.InvariantCulture, "{0}::{1}", containerTypeFullName, fieldName)) - { - } - - public VisualStudioTestIdentifier(string fullyQualifiedName) - { - FullyQualifiedName = fullyQualifiedName; - } - - public string FullyQualifiedName { get; private set; } - - public string FieldName - { - get - { - return FullyQualifiedName.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1]; - } - } - - public string ContainerTypeFullName - { - get - { - return FullyQualifiedName.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0]; - } - } - - public override bool Equals(object obj) - { - if (obj is VisualStudioTestIdentifier test) - { - return FullyQualifiedName.Equals(test.FullyQualifiedName, StringComparison.Ordinal); - } - - return base.Equals(obj); - } - - public override int GetHashCode() - { - return FullyQualifiedName.GetHashCode(); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.csproj b/src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.csproj deleted file mode 100644 index ebe3f257..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.csproj +++ /dev/null @@ -1,47 +0,0 @@ - - - - 0.1.0 - netcoreapp3.1;net472 - Machine.Specifications.Runner.VisualStudio - Machine.Specifications.Runner.VisualStudio.TestAdapter - NU5127,NU5128 - false - - Machine.Specifications test adapter for .NET Framework and .NET Core. - Machine Specifications - mspec;unit;testing;context;specification;bdd;tdd - https://github.com/machine/machine.specifications.runner.visualstudio/releases - Machine.png - https://github.com/machine/machine.specifications.runner.visualstudio - MIT - - - - - - - - - - - - - $(TargetsForTfmSpecificContentInPackage);NetCorePackageItems;NetFrameworkPackageItems - - - - - - - - - - - - - - - - - diff --git a/src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.props b/src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.props deleted file mode 100644 index 425b3009..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Machine.Specifications.Runner.VisualStudio.props +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Machine.Specifications.Runner.VisualStudio.TestAdapter.dll - PreserveNewest - False - - - diff --git a/src/Machine.Specifications.Runner.VisualStudio/MspecTestDiscoverer.cs b/src/Machine.Specifications.Runner.VisualStudio/MspecTestDiscoverer.cs deleted file mode 100644 index 01059e05..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/MspecTestDiscoverer.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Machine.Specifications.Runner.VisualStudio.Discovery; -using Machine.Specifications.Runner.VisualStudio.Helpers; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - -namespace Machine.Specifications.Runner.VisualStudio -{ - public class MspecTestDiscoverer - { - private readonly ISpecificationDiscoverer discoverer; - - public MspecTestDiscoverer(ISpecificationDiscoverer discoverer) - { - this.discoverer = discoverer; - } - - public void DiscoverTests(IEnumerable sources, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) - { - DiscoverTests(sources, logger, discoverySink.SendTestCase); - } - - public void DiscoverTests(IEnumerable sources, IMessageLogger logger, Action discoverySinkAction) - { - logger.SendMessage(TestMessageLevel.Informational, "Machine Specifications Visual Studio Test Adapter - Discovering Specifications."); - - var discoveredSpecCount = 0; - var sourcesWithSpecs = 0; - - var sourcesArray = sources.Distinct().ToArray(); - - foreach (var assemblyPath in sourcesArray) - { - try - { -#if NETFRAMEWORK - if (!File.Exists(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(assemblyPath)), "Machine.Specifications.dll"))) - continue; -#endif - - sourcesWithSpecs++; - - logger.SendMessage(TestMessageLevel.Informational, $"Machine Specifications Visual Studio Test Adapter - Discovering...looking in {assemblyPath}"); - - var specs = discoverer.DiscoverSpecs(assemblyPath) - .Select(spec => SpecTestHelper.GetTestCaseFromMspecTestCase(assemblyPath, spec, MspecTestRunner.Uri)) - .ToList(); - - foreach (var discoveredTest in specs) - { - discoveredSpecCount++; - discoverySinkAction(discoveredTest); - } - } - catch (Exception discoverException) - { - logger.SendMessage(TestMessageLevel.Error, $"Machine Specifications Visual Studio Test Adapter - Error while discovering specifications in assembly {assemblyPath}." + Environment.NewLine + discoverException); - } - } - - logger.SendMessage(TestMessageLevel.Informational, $"Machine Specifications Visual Studio Test Adapter - Discovery Complete - {discoveredSpecCount} specifications in {sourcesWithSpecs} of {sourcesArray.Length} assemblies scanned."); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/MspecTestExecutor.cs b/src/Machine.Specifications.Runner.VisualStudio/MspecTestExecutor.cs deleted file mode 100644 index df400bde..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/MspecTestExecutor.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Machine.Specifications.Runner.VisualStudio.Execution; -using Machine.Specifications.Runner.VisualStudio.Helpers; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - -namespace Machine.Specifications.Runner.VisualStudio -{ - public class MspecTestExecutor - { - private readonly ISpecificationExecutor executor; - - private readonly MspecTestDiscoverer discover; - - private readonly ISpecificationFilterProvider specificationFilterProvider; - - public MspecTestExecutor(ISpecificationExecutor executor, MspecTestDiscoverer discover, ISpecificationFilterProvider specificationFilterProvider) - { - this.executor = executor; - this.discover = discover; - this.specificationFilterProvider = specificationFilterProvider; - } - - public void RunTests(IEnumerable sources, IRunContext runContext, IFrameworkHandle frameworkHandle) - { - frameworkHandle.SendMessage(TestMessageLevel.Informational, "Machine Specifications Visual Studio Test Adapter - Executing Source Specifications."); - - var testsToRun = new List(); - - DiscoverTests(sources, frameworkHandle, testsToRun); - RunTests(testsToRun, runContext, frameworkHandle); - - frameworkHandle.SendMessage(TestMessageLevel.Informational, "Machine Specifications Visual Studio Test Adapter - Executing Source Specifications Complete."); - } - - public void RunTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle) - { - frameworkHandle.SendMessage(TestMessageLevel.Informational, "Machine Specifications Visual Studio Test Adapter - Executing Test Specifications."); - - var totalSpecCount = 0; - var executedSpecCount = 0; - var currentAssembly = string.Empty; - - try - { - var testCases = tests.ToArray(); - - foreach (var grouping in testCases.GroupBy(x => x.Source)) - { - currentAssembly = grouping.Key; - totalSpecCount += grouping.Count(); - - var filteredTests = specificationFilterProvider.FilteredTests(grouping.AsEnumerable(), runContext, frameworkHandle); - - var testsToRun = filteredTests - .Select(test => test.ToVisualStudioTestIdentifier()) - .ToArray(); - - frameworkHandle.SendMessage(TestMessageLevel.Informational, $"Machine Specifications Visual Studio Test Adapter - Executing {testsToRun.Length} tests in '{currentAssembly}'."); - - executor.RunAssemblySpecifications(grouping.Key, testsToRun, MspecTestRunner.Uri, frameworkHandle); - - executedSpecCount += testsToRun.Length; - } - - frameworkHandle.SendMessage(TestMessageLevel.Informational, $"Machine Specifications Visual Studio Test Adapter - Execution Complete - {executedSpecCount} of {totalSpecCount} specifications in {testCases.GroupBy(x => x.Source).Count()} assemblies."); - } - catch (Exception exception) - { - frameworkHandle.SendMessage(TestMessageLevel.Error, $"Machine Specifications Visual Studio Test Adapter - Error while executing specifications in assembly '{currentAssembly}'." + Environment.NewLine + exception); - } - } - - private void DiscoverTests(IEnumerable sources, IMessageLogger logger, List testsToRun) - { - discover.DiscoverTests(sources, logger, testsToRun.Add); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/MspecTestRunner.cs b/src/Machine.Specifications.Runner.VisualStudio/MspecTestRunner.cs deleted file mode 100644 index 844c0b6f..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/MspecTestRunner.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using Machine.Specifications.Runner.VisualStudio.Discovery; -using Machine.Specifications.Runner.VisualStudio.Execution; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - -namespace Machine.Specifications.Runner.VisualStudio -{ - [FileExtension(".exe")] - [FileExtension(".dll")] - [ExtensionUri(ExecutorUri)] - [DefaultExecutorUri(ExecutorUri)] - public class MspecTestRunner : ITestDiscoverer, ITestExecutor - { - private const string ExecutorUri = "executor://machine.vstestadapter"; - - public static readonly Uri Uri = new Uri(ExecutorUri); - - private readonly MspecTestDiscoverer testDiscoverer; - - private readonly MspecTestExecutor testExecutor; - - public MspecTestRunner() - : this(new BuiltInSpecificationDiscoverer(), new SpecificationExecutor(), new SpecificationFilterProvider()) - { - } - - public MspecTestRunner(ISpecificationDiscoverer discoverer, ISpecificationExecutor executor, ISpecificationFilterProvider specificationFilterProvider) - { - testDiscoverer = new MspecTestDiscoverer(discoverer); - testExecutor = new MspecTestExecutor(executor, testDiscoverer, specificationFilterProvider); - } - - public void DiscoverTests(IEnumerable sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) - { - testDiscoverer.DiscoverTests(sources, logger, discoverySink); - } - - public void RunTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle) - { - testExecutor.RunTests(tests, runContext, frameworkHandle); - } - - public void RunTests(IEnumerable sources, IRunContext runContext, IFrameworkHandle frameworkHandle) - { - testExecutor.RunTests(sources, runContext, frameworkHandle); - } - - public void Cancel() - { - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Navigation/INavigationSession.cs b/src/Machine.Specifications.Runner.VisualStudio/Navigation/INavigationSession.cs deleted file mode 100644 index c7297541..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Navigation/INavigationSession.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Machine.Specifications.Runner.VisualStudio.Navigation -{ - public interface INavigationSession : IDisposable - { - NavigationData GetNavigationData(string typeName, string fieldName); - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Navigation/NavigationData.cs b/src/Machine.Specifications.Runner.VisualStudio/Navigation/NavigationData.cs deleted file mode 100644 index bf61fbe8..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Navigation/NavigationData.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Machine.Specifications.Runner.VisualStudio.Navigation -{ - public class NavigationData - { - public static NavigationData Unknown { get; } = new NavigationData(null, 0); - - public NavigationData(string codeFile, int lineNumber) - { - CodeFile = codeFile; - LineNumber = lineNumber; - } - - public string CodeFile { get; } - - public int LineNumber { get; } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Navigation/NavigationSession.cs b/src/Machine.Specifications.Runner.VisualStudio/Navigation/NavigationSession.cs deleted file mode 100644 index 4fe24c69..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Navigation/NavigationSession.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Linq; -using System.Reflection.Emit; -using Machine.Specifications.Runner.VisualStudio.Reflection; - -namespace Machine.Specifications.Runner.VisualStudio.Navigation -{ - public class NavigationSession : INavigationSession - { - private readonly AssemblyData assembly; - - public NavigationSession(string assemblyPath) - { - assembly = AssemblyData.Read(assemblyPath); - } - - public NavigationData GetNavigationData(string typeName, string fieldName) - { - var type = assembly.Types.FirstOrDefault(x => x.TypeName == typeName); - var method = type?.Constructors.FirstOrDefault(); - - if (method == null) - { - return NavigationData.Unknown; - } - - var instruction = method.Instructions - .Where(x => x.OperandType == OperandType.InlineField) - .FirstOrDefault(x => x.Name == fieldName); - - while (instruction != null) - { - var sequencePoint = method.GetSequencePoint(instruction); - - if (sequencePoint != null && !sequencePoint.IsHidden) - { - return new NavigationData(sequencePoint.FileName, sequencePoint.StartLine); - } - - instruction = instruction.Previous; - } - - return NavigationData.Unknown; - } - - public void Dispose() - { - assembly.Dispose(); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/AssemblyData.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/AssemblyData.cs deleted file mode 100644 index 7aadc489..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/AssemblyData.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; - -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class AssemblyData : IDisposable - { - private readonly PEReader reader; - - private readonly MetadataReader metadata; - - private readonly SymbolReader symbolReader; - - private readonly object sync = new object(); - - private ReadOnlyCollection types; - - private AssemblyData(string assembly) - { - reader = new PEReader(File.OpenRead(assembly)); - metadata = reader.GetMetadataReader(); - symbolReader = new SymbolReader(assembly); - } - - public static AssemblyData Read(string assembly) - { - return new AssemblyData(assembly); - } - - public IReadOnlyCollection Types - { - get - { - if (types != null) - { - return types; - } - - lock (sync) - { - types = ReadTypes().AsReadOnly(); - } - - return types; - } - } - - public void Dispose() - { - reader.Dispose(); - } - - private List ReadTypes() - { - var values = new List(); - - foreach (var typeHandle in metadata.TypeDefinitions) - { - ReadType(values, typeHandle); - } - - return values; - } - - private void ReadType(List values, TypeDefinitionHandle typeHandle, string namespaceName = null) - { - var typeDefinition = metadata.GetTypeDefinition(typeHandle); - - var typeNamespace = string.IsNullOrEmpty(namespaceName) - ? metadata.GetString(typeDefinition.Namespace) - : namespaceName; - - var typeName = string.IsNullOrEmpty(namespaceName) - ? $"{typeNamespace}.{metadata.GetString(typeDefinition.Name)}" - : $"{typeNamespace}+{metadata.GetString(typeDefinition.Name)}"; - - values.Add(new TypeData(typeName, reader, metadata, symbolReader, typeDefinition)); - - foreach (var nestedTypeHandle in typeDefinition.GetNestedTypes()) - { - ReadType(values, nestedTypeHandle, typeName); - } - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/CodeReader.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/CodeReader.cs deleted file mode 100644 index 0fc28f8f..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/CodeReader.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Reflection.Emit; -using System.Reflection.Metadata; -using System.Reflection.Metadata.Ecma335; - -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class CodeReader - { - private static readonly OperandType[] OperandTypes = Enumerable.Repeat((OperandType) 0xff, 0x11f).ToArray(); - - private static readonly string[] OperandNames = new string[0x11f]; - - static CodeReader() - { - foreach (var field in typeof(OpCodes).GetFields()) - { - var opCode = (OpCode) field.GetValue(null); - var index = (ushort) (((opCode.Value & 0x200) >> 1) | opCode.Value & 0xff); - - OperandTypes[index] = opCode.OperandType; - OperandNames[index] = opCode.Name; - } - } - - public IEnumerable GetInstructions(MetadataReader reader, ref BlobReader blob) - { - var instructions = new List(); - - InstructionData previous = null; - - while (blob.RemainingBytes > 0) - { - var offset = blob.Offset; - - var opCode = ReadOpCode(ref blob); - var opCodeName = GetDisplayName(opCode); - var operandType = GetOperandType(opCode); - - var name = operandType != OperandType.InlineNone - ? ReadOperand(reader, ref blob, operandType) - : null; - - previous = new InstructionData(opCode, opCodeName, operandType, offset, previous, name); - - instructions.Add(previous); - } - - return instructions; - } - - private string ReadOperand(MetadataReader reader, ref BlobReader blob, OperandType operandType) - { - var name = string.Empty; - - switch (operandType) - { - case OperandType.InlineI8: - case OperandType.InlineR: - blob.Offset += 8; - break; - - case OperandType.InlineBrTarget: - case OperandType.InlineI: - case OperandType.InlineSig: - case OperandType.InlineString: - case OperandType.InlineTok: - case OperandType.InlineType: - case OperandType.ShortInlineR: - blob.Offset += 4; - break; - - case OperandType.InlineField: - case OperandType.InlineMethod: - var handle = MetadataTokens.EntityHandle(blob.ReadInt32()); - - name = LookupToken(reader, handle); - break; - - case OperandType.InlineSwitch: - var length = blob.ReadInt32(); - blob.Offset += length * 4; - break; - - case OperandType.InlineVar: - blob.Offset += 2; - break; - - case OperandType.ShortInlineVar: - case OperandType.ShortInlineBrTarget: - case OperandType.ShortInlineI: - blob.Offset++; - break; - } - - return name; - } - - private string LookupToken(MetadataReader reader, EntityHandle handle) - { - if (handle.Kind == HandleKind.FieldDefinition) - { - var field = reader.GetFieldDefinition((FieldDefinitionHandle) handle); - - return reader.GetString(field.Name); - } - - if (handle.Kind == HandleKind.MethodDefinition) - { - var method = reader.GetMethodDefinition((MethodDefinitionHandle) handle); - - return reader.GetString(method.Name); - } - - return string.Empty; - } - - private ILOpCode ReadOpCode(ref BlobReader blob) - { - var opCodeByte = blob.ReadByte(); - - var value = opCodeByte == 0xfe - ? 0xfe00 + blob.ReadByte() - : opCodeByte; - - return (ILOpCode) value; - } - - private OperandType GetOperandType(ILOpCode opCode) - { - var index = (ushort) ((((int) opCode & 0x200) >> 1) | ((int) opCode & 0xff)); - - if (index >= OperandTypes.Length) - { - return (OperandType) 0xff; - } - - return OperandTypes[index]; - } - - private string GetDisplayName(ILOpCode opCode) - { - var index = (ushort) ((((int) opCode & 0x200) >> 1) | ((int) opCode & 0xff)); - - if (index >= OperandNames.Length) - { - return string.Empty; - } - - return OperandNames[index]; - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/InstructionData.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/InstructionData.cs deleted file mode 100644 index 6acc2727..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/InstructionData.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Reflection.Emit; -using System.Reflection.Metadata; -using System.Text; - -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class InstructionData - { - public InstructionData(ILOpCode opCode, string opCodeName, OperandType operandType, int offset, InstructionData previous, string name = null) - { - OpCode = opCode; - OpCodeName = opCodeName; - OperandType = operandType; - Offset = offset; - Previous = previous; - Name = name; - } - - public ILOpCode OpCode { get; } - - public string OpCodeName { get; } - - public OperandType OperandType { get; } - - public string Name { get; } - - public int Offset { get; } - - public InstructionData Previous { get; } - - public override string ToString() - { - var value = new StringBuilder(); - - AppendLabel(value); - - value.Append(": "); - value.Append(OpCode); - - if (!string.IsNullOrEmpty(Name)) - { - value.Append(" "); - - if (OperandType == OperandType.InlineString) - { - value.Append("\""); - value.Append(Name); - value.Append("\""); - } - else - { - value.Append(Name); - } - } - - return value.ToString(); - } - - private void AppendLabel(StringBuilder value) - { - value.Append("IL_"); - value.Append(Offset.ToString("x4")); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/MethodData.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/MethodData.cs deleted file mode 100644 index bcabc13a..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/MethodData.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; - -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class MethodData - { - private readonly PEReader reader; - - private readonly MetadataReader metadata; - - private readonly SymbolReader symbolReader; - - private readonly MethodDefinition definition; - - private readonly MethodDefinitionHandle handle; - - private readonly object sync = new object(); - - private ReadOnlyCollection instructions; - - private List sequencePoints; - - public MethodData(string name, PEReader reader, MetadataReader metadata, SymbolReader symbolReader, MethodDefinition definition, MethodDefinitionHandle handle) - { - this.reader = reader; - this.metadata = metadata; - this.symbolReader = symbolReader; - this.definition = definition; - this.handle = handle; - - Name = name; - } - - public string Name { get; } - - public IReadOnlyCollection Instructions - { - get - { - if (instructions != null) - { - return instructions; - } - - lock (sync) - { - instructions = GetInstructions().AsReadOnly(); - } - - return instructions; - } - } - - public SequencePointData GetSequencePoint(InstructionData instruction) - { - if (sequencePoints == null) - { - lock (sync) - { - sequencePoints = GetSequencePoints().ToList(); - } - } - - return sequencePoints.FirstOrDefault(x => x.Offset == instruction.Offset); - } - - public override string ToString() - { - return Name; - } - - private List GetInstructions() - { - var blob = reader - .GetMethodBody(definition.RelativeVirtualAddress) - .GetILReader(); - - var codeReader = new CodeReader(); - - return codeReader.GetInstructions(metadata, ref blob).ToList(); - } - - private IEnumerable GetSequencePoints() - { - return symbolReader.ReadSequencePoints(handle); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/SequencePointData.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/SequencePointData.cs deleted file mode 100644 index 719c2fad..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/SequencePointData.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class SequencePointData - { - public SequencePointData(string fileName, int startLine, int endLine, int offset, bool isHidden) - { - FileName = fileName; - StartLine = startLine; - EndLine = endLine; - Offset = offset; - IsHidden = isHidden; - } - - public string FileName { get; } - - public int StartLine { get; } - - public int EndLine { get; } - - public int Offset { get; } - - public bool IsHidden { get; } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/SymbolReader.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/SymbolReader.cs deleted file mode 100644 index 5d65532a..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/SymbolReader.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection.Metadata; - -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class SymbolReader - { - private readonly MetadataReader reader; - - public SymbolReader(string assembly) - { - var symbols = Path.ChangeExtension(assembly, "pdb"); - - if (File.Exists(symbols)) - { - reader = MetadataReaderProvider - .FromPortablePdbStream(File.OpenRead(symbols)) - .GetMetadataReader(); - } - } - - public IEnumerable ReadSequencePoints(MethodDefinitionHandle method) - { - if (reader == null) - { - return Enumerable.Empty(); - } - - return reader - .GetMethodDebugInformation(method) - .GetSequencePoints() - .Select(x => - { - var document = reader.GetDocument(x.Document); - var fileName = reader.GetString(document.Name); - - return new SequencePointData(fileName, x.StartLine, x.EndLine, x.Offset, x.IsHidden); - }); - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Reflection/TypeData.cs b/src/Machine.Specifications.Runner.VisualStudio/Reflection/TypeData.cs deleted file mode 100644 index 36ceaae9..00000000 --- a/src/Machine.Specifications.Runner.VisualStudio/Reflection/TypeData.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Reflection; -using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; - -namespace Machine.Specifications.Runner.VisualStudio.Reflection -{ - public class TypeData - { - private readonly PEReader reader; - - private readonly MetadataReader metadata; - - private readonly SymbolReader symbolReader; - - private readonly TypeDefinition definition; - - private readonly object sync = new object(); - - private ReadOnlyCollection methods; - - public TypeData(string typeName, PEReader reader, MetadataReader metadata, SymbolReader symbolReader, TypeDefinition definition) - { - this.reader = reader; - this.metadata = metadata; - this.symbolReader = symbolReader; - this.definition = definition; - - TypeName = typeName; - } - - public string TypeName { get; } - - public IReadOnlyCollection Constructors - { - get - { - if (methods != null) - { - return methods; - } - - lock (sync) - { - methods = GetConstructors().AsReadOnly(); - } - - return methods; - } - } - - public override string ToString() - { - return TypeName; - } - - private List GetConstructors() - { - var values = new List(); - - foreach (var methodHandle in definition.GetMethods()) - { - var methodDefinition = metadata.GetMethodDefinition(methodHandle); - var parameters = methodDefinition.GetParameters(); - - var methodName = metadata.GetString(methodDefinition.Name); - - if (IsConstructor(methodDefinition, methodName) && parameters.Count == 0) - { - values.Add(new MethodData(methodName, reader, metadata, symbolReader, methodDefinition, methodHandle)); - } - } - - return values; - } - - private bool IsConstructor(MethodDefinition method, string name) - { - return method.Attributes.HasFlag(MethodAttributes.RTSpecialName) && - method.Attributes.HasFlag(MethodAttributes.SpecialName) && - name == ".ctor"; - } - } -} diff --git a/src/Machine.Specifications.Runner.VisualStudio/Resources/Machine.png b/src/Machine.Specifications.Runner.VisualStudio/Resources/Machine.png deleted file mode 100644 index 20b80d34..00000000 Binary files a/src/Machine.Specifications.Runner.VisualStudio/Resources/Machine.png and /dev/null differ