Skip to content

Commit

Permalink
Added more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gubpalma committed Apr 8, 2024
1 parent b404253 commit 27c0ab5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Mono.Cecil;
using Mono.Cecil.Cil;
using SpecFlowToMarkdown.Domain.TestAssembly;
Expand All @@ -14,15 +15,22 @@ public class FeatureExtractor : IFeatureExtractor
private const string FeatureInfoTypeName = "TechTalk.SpecFlow.FeatureInfo";

private readonly IScenarioExtractionHandler _scenarioExtractionHandler;
private readonly ILogger<FeatureExtractor> _logger;

public FeatureExtractor(IScenarioExtractionHandler scenarioExtractionHandler)
public FeatureExtractor(
IScenarioExtractionHandler scenarioExtractionHandler,
ILogger<FeatureExtractor> logger)
{
_scenarioExtractionHandler = scenarioExtractionHandler;
_logger = logger;
}

public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly)
{
var assemblyName = assembly.Name.Name;

_logger
.LogInformation($"Assembly name: [{assemblyName}]");

var result = new SpecFlowAssembly
{
Expand All @@ -46,6 +54,9 @@ public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly)
)
))
{
_logger
.LogInformation($"Found {type.Methods.Count} feature methods in assembly [{assemblyName}]");

foreach (var method in type.Methods)
{
if (method.Name == FeatureSetupMethodName)
Expand Down Expand Up @@ -86,6 +97,9 @@ public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly)
currInstr
.Operand
.ToString();

_logger
.LogInformation($"Extracted feature: [{title}]");

currInstr =
currInstr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Mono.Cecil;
using Mono.Cecil.Cil;
using SpecFlowToMarkdown.Domain.TestAssembly;
Expand All @@ -19,6 +20,13 @@ public bool IsApplicable(string attributeName) =>
attributeName.Equals(Constants.NUnitTestAttribute) ||
attributeName.Equals(Constants.XUnitFactAttribute) ||
attributeName.Equals(Constants.XUnitTheoryAttribute);

private readonly ILogger<FeatureExtractor> _logger;

public UnitScenarioExtractor(ILogger<FeatureExtractor> logger)
{
_logger = logger;
}

public SpecFlowScenario ExtractScenario(MethodDefinition method)
{
Expand All @@ -31,10 +39,10 @@ public SpecFlowScenario ExtractScenario(MethodDefinition method)
var scenarioArgumentNames = new Dictionary<string, string>();
var scenarioArgumentValues = new List<IEnumerable<object>>();

var hasCases =
var testCases =
method
.CustomAttributes
.Any(o => _testCaseAttributes.Contains(o.AttributeType.FullName));
.Count(o => _testCaseAttributes.Contains(o.AttributeType.FullName));

foreach (var instruction in
method
Expand Down Expand Up @@ -68,11 +76,17 @@ public SpecFlowScenario ExtractScenario(MethodDefinition method)
currInstr
.Operand
.ToString();

_logger
.LogInformation($"Extracted scenario: [{title}]");
}

// Extract test cases
if (hasCases)
if (testCases > 0)
{
_logger
.LogInformation($"Scenario [{title}]; found {testCases} test cases");

// Get test case argument names
currInstr =
currInstr
Expand Down Expand Up @@ -209,6 +223,9 @@ public SpecFlowScenario ExtractScenario(MethodDefinition method)
{
Arguments = argumentList
};

_logger
.LogInformation($"Extracted test case: {{{string.Join(", ", scenarioCase.Arguments.Select(o => $"\"{o.ArgumentName}\":\"{o.ArgumentValue}\""))}}}");

scenarioCases
.Add(scenarioCase);
Expand Down Expand Up @@ -360,6 +377,9 @@ out var argumentName
Keyword = keyword,
Text = text
};

_logger
.LogInformation($"Extracted test step [{executionStep.Keyword} {executionStep.Text}]");

scenarioSteps
.Add(executionStep);
Expand Down

0 comments on commit 27c0ab5

Please sign in to comment.