diff --git a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/FeatureExtractor.cs b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/FeatureExtractor.cs index 87f1a15..0fa8c6f 100644 --- a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/FeatureExtractor.cs +++ b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/FeatureExtractor.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Microsoft.Extensions.Logging; using Mono.Cecil; @@ -13,6 +15,7 @@ public class FeatureExtractor : IFeatureExtractor private const string CustomFeatureAttributeValue = "TechTalk.SpecFlow"; private const string FeatureSetupMethodName = "FeatureSetup"; private const string FeatureInfoTypeName = "TechTalk.SpecFlow.FeatureInfo"; + private const string DebuggingModeAttributeName = "System.Diagnostics.DebuggableAttribute/DebuggingModes"; private readonly IScenarioExtractionHandler _scenarioExtractionHandler; private readonly ILogger _logger; @@ -24,13 +27,18 @@ public FeatureExtractor( _scenarioExtractionHandler = scenarioExtractionHandler; _logger = logger; } - + public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly) { var assemblyName = assembly.Name.Name; + + var isDebug = IsDebugBuild(assembly); _logger .LogInformation($"Assembly name: [{assemblyName}]"); + + _logger + .LogInformation($"Debug build: [{isDebug}]"); var result = new SpecFlowAssembly { @@ -123,7 +131,7 @@ public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly) var scenarios = _scenarioExtractionHandler - .ExtractScenarios(type); + .ExtractScenarios(type, isDebug); feature.Scenarios = scenarios; @@ -142,5 +150,38 @@ public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly) return result; } + + private static bool IsDebugBuild(AssemblyDefinition assembly) + { + var customAttributes = + assembly + .CustomAttributes; + + var debuggableAttribute = + customAttributes + .FirstOrDefault(o => o.AttributeType.FullName == typeof(DebuggableAttribute).FullName); + + if (debuggableAttribute != null) + { + var debuggingMode = + debuggableAttribute + .ConstructorArguments + .FirstOrDefault(o => o.Type.FullName == DebuggingModeAttributeName); + + if (debuggingMode.Value != null) + { + var attributes = + (DebuggableAttribute.DebuggingModes)Enum.Parse( + typeof(DebuggableAttribute.DebuggingModes), + debuggingMode.Value?.ToString() + ); + return + attributes + .HasFlag(DebuggableAttribute.DebuggingModes.Default); + } + } + + return false; + } } } \ No newline at end of file diff --git a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractionHandler.cs b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractionHandler.cs index 85f87d3..e2ae0bb 100644 --- a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractionHandler.cs +++ b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractionHandler.cs @@ -6,6 +6,6 @@ namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors { public interface IScenarioExtractionHandler { - public IEnumerable ExtractScenarios(TypeDefinition type); + public IEnumerable ExtractScenarios(TypeDefinition type, bool isDebug); } } \ No newline at end of file diff --git a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractor.cs b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractor.cs index 4a6912d..0c1227c 100644 --- a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractor.cs +++ b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/IScenarioExtractor.cs @@ -6,7 +6,7 @@ namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors public interface IScenarioExtractor { public bool IsApplicable(string attributeName); - - public SpecFlowScenario ExtractScenario(MethodDefinition method); + + public SpecFlowScenario ExtractScenario(MethodDefinition method, bool isDebug); } } \ No newline at end of file diff --git a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/Providers/UnitScenarioExtractor.cs b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/Providers/UnitScenarioExtractor.cs index 5692f39..3cbbc75 100644 --- a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/Providers/UnitScenarioExtractor.cs +++ b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/Providers/UnitScenarioExtractor.cs @@ -28,7 +28,7 @@ public UnitScenarioExtractor(ILogger logger) _logger = logger; } - public SpecFlowScenario ExtractScenario(MethodDefinition method) + public SpecFlowScenario ExtractScenario(MethodDefinition method, bool isDebug) { // Extract Scenario var title = string.Empty; @@ -90,7 +90,7 @@ public SpecFlowScenario ExtractScenario(MethodDefinition method) // Get test case argument names currInstr = currInstr - .StepPrevious(3); + .StepPrevious(isDebug ? 3 : 2); while (true) { @@ -135,7 +135,7 @@ public SpecFlowScenario ExtractScenario(MethodDefinition method) currInstr = currInstr - .StepPrevious(5); + .StepPrevious(isDebug ? 5 : 4); } else break; diff --git a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/ScenarioExtractionHandler.cs b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/ScenarioExtractionHandler.cs index c49b48a..0c84619 100644 --- a/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/ScenarioExtractionHandler.cs +++ b/src/6.0/SpecFlowToMarkdown.Infrastructure.AssemblyLoad/Extractors/ScenarioExtractionHandler.cs @@ -22,7 +22,7 @@ public ScenarioExtractionHandler(IEnumerable extractors) _extractors = extractors; } - public IEnumerable ExtractScenarios(TypeDefinition type) + public IEnumerable ExtractScenarios(TypeDefinition type, bool isDebug) { var results = new List(); @@ -59,7 +59,7 @@ public IEnumerable ExtractScenarios(TypeDefinition type) var scenario = applicableExtractor - .ExtractScenario(method); + .ExtractScenario(method, isDebug); results .Add(scenario);