Skip to content

Commit

Permalink
Merge pull request #4 from gman-au/3-xunit-support
Browse files Browse the repository at this point in the history
3 xunit support
  • Loading branch information
gubpalma authored Apr 7, 2024
2 parents 32e90b3 + 9287aea commit b404253
Show file tree
Hide file tree
Showing 27 changed files with 1,148 additions and 516 deletions.
2 changes: 2 additions & 0 deletions src/6.0/SpecFlowToMarkdown.Domain/Result/ExecutionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ExecutionResult
public string FeatureTitle { get; set; }

public string ScenarioTitle { get; set; }

public IEnumerable<string> ScenarioArguments { get; set; }

public string Status { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SpecFlowToMarkdown.Domain.TestAssembly
{
public class SpecFlowArgument
{
public string ArgumentName { get; set; }

public object ArgumentValue { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace SpecFlowToMarkdown.Domain.TestAssembly
{
public class SpecFlowCase
{
public IEnumerable<SpecFlowArgument> Arguments { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class SpecFlowScenario
public IEnumerable<string> Tags { get; set; }

public IEnumerable<SpecFlowExecutionStep> Steps { get; set; }

public IEnumerable<SpecFlowCase> Cases { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors
{
internal static class Constants
{
public const string NUnitTestAttribute = "NUnit.Framework.TestAttribute";
public const string XUnitFactAttribute = "Xunit.SkippableFactAttribute";
public const string XUnitTheoryAttribute = "Xunit.SkippableTheoryAttribute";

public const string ScenarioInfoTypeName = "TechTalk.SpecFlow.ScenarioInfo";

public const string NUnitTestCaseAttribute = "NUnit.Framework.TestCaseAttribute";
public const string XUnitInlineDataAttribute = "Xunit.InlineDataAttribute";

public static readonly string[] ScenarioStepFunctions = { "And", "Given", "When", "Then" };

public const string StringFormatFunctionName = "Format";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Mono.Cecil.Cil;

namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors.Extensions
{
internal static class InstructionEx
{
public static Instruction StepPrevious(this Instruction instruction, int times)
{
for (var i = 0; i < times && instruction != null; i++)
{
instruction =
instruction
.Previous;
}

return instruction;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using SpecFlowToMarkdown.Domain.TestAssembly;
using SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors.Extensions;

namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors
{
Expand All @@ -12,11 +13,11 @@ public class FeatureExtractor : IFeatureExtractor
private const string FeatureSetupMethodName = "FeatureSetup";
private const string FeatureInfoTypeName = "TechTalk.SpecFlow.FeatureInfo";

private readonly IScenarioExtractor _scenarioExtractor;
private readonly IScenarioExtractionHandler _scenarioExtractionHandler;

public FeatureExtractor(IScenarioExtractor scenarioExtractor)
public FeatureExtractor(IScenarioExtractionHandler scenarioExtractionHandler)
{
_scenarioExtractor = scenarioExtractor;
_scenarioExtractionHandler = scenarioExtractionHandler;
}

public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly)
Expand Down Expand Up @@ -65,20 +66,30 @@ public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly)

var currInstr =
instruction
.Previous
.Previous
.Previous;
.StepPrevious(3);

if (currInstr.OpCode == OpCodes.Ldstr)
{
description = currInstr.Operand.ToString();
currInstr = currInstr.Previous;
description =
currInstr
.Operand
.ToString();

currInstr =
currInstr
.Previous;
}

if (currInstr.OpCode == OpCodes.Ldstr)
{
title = currInstr.Operand.ToString();
currInstr = currInstr.Previous;
title =
currInstr
.Operand
.ToString();

currInstr =
currInstr
.Previous;
}

if (currInstr.OpCode == OpCodes.Ldstr)
Expand All @@ -97,7 +108,7 @@ public SpecFlowAssembly ExtractFeatures(AssemblyDefinition assembly)
};

var scenarios =
_scenarioExtractor
_scenarioExtractionHandler
.ExtractScenarios(type);

feature.Scenarios = scenarios;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Mono.Cecil;
using SpecFlowToMarkdown.Domain.TestAssembly;

namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors
{
public interface IScenarioExtractionHandler
{
public IEnumerable<SpecFlowScenario> ExtractScenarios(TypeDefinition type);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil;
using SpecFlowToMarkdown.Domain.TestAssembly;

namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors
{
public interface IScenarioExtractor
{
public IEnumerable<SpecFlowScenario> ExtractScenarios(TypeDefinition type);
public bool IsApplicable(string attributeName);

public SpecFlowScenario ExtractScenario(MethodDefinition method);
}
}
Loading

0 comments on commit b404253

Please sign in to comment.