Skip to content

Commit 01b72d8

Browse files
Burgynclaude
andcommitted
Inject TpFileParser via DI into BaseStructureExplorer instead of using new
Replace explicit `new TpFileParser()` in BaseStructureExplorer.ExploreTpFile with constructor-injected instance. The parser is already registered as a singleton in TestCases/Setup.cs. This aligns with the project's DI conventions and makes the registration no longer dead code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1f071de commit 01b72d8

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/TeaPie/StructureExploration/BaseStructureExplorer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
namespace TeaPie.StructureExploration;
77

8-
internal abstract class BaseStructureExplorer(IPathProvider pathProvider, ILogger logger) : IStructureExplorer
8+
internal abstract class BaseStructureExplorer(IPathProvider pathProvider, ILogger logger, TpFileParser tpFileParser) : IStructureExplorer
99
{
1010
public const string RemoteFolderName = "~Remote";
1111
protected string _remoteFolderPath = string.Empty;
1212

1313
protected readonly ILogger _logger = logger;
14+
protected readonly TpFileParser _tpFileParser = tpFileParser;
1415
protected string? _environmentFileName;
1516
protected string? _initializationScriptName;
1617
protected IPathProvider _pathProvider = pathProvider;
@@ -86,16 +87,15 @@ protected static void ExploreTestCase(
8687
}
8788
}
8889

89-
protected static void ExploreTpFile(
90+
protected void ExploreTpFile(
9091
string tpFilePath,
9192
CollectionStructure collectionStructure,
9293
Folder currentFolder)
9394
{
9495
var content = System.IO.File.ReadAllText(tpFilePath);
9596
var fallbackName = Path.GetFileNameWithoutExtension(tpFilePath);
9697

97-
var parser = new TpFileParser();
98-
var definitions = parser.Parse(content, fallbackName);
98+
var definitions = _tpFileParser.Parse(content, fallbackName);
9999

100100
var relativePath = GetRelativePath(currentFolder, Path.GetFileName(tpFilePath));
101101

src/TeaPie/StructureExploration/CollectionStructureExplorer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using Microsoft.Extensions.Logging;
22
using TeaPie.StructureExploration.Paths;
3+
using TeaPie.TestCases;
34

45
namespace TeaPie.StructureExploration;
56

6-
internal partial class CollectionStructureExplorer(IPathProvider pathProvider, ILogger<CollectionStructureExplorer> logger)
7-
: BaseStructureExplorer(pathProvider, logger)
7+
internal partial class CollectionStructureExplorer(
8+
IPathProvider pathProvider, ILogger<CollectionStructureExplorer> logger, TpFileParser tpFileParser)
9+
: BaseStructureExplorer(pathProvider, logger, tpFileParser)
810
{
911
protected override CollectionStructure ExploreStructure(ApplicationContext applicationContext)
1012
{
@@ -60,7 +62,7 @@ private void ExploreFolder(Folder currentFolder, CollectionStructure collectionS
6062
ExploreTestCases(collectionStructure, currentFolder, files);
6163
}
6264

63-
private static void ExploreTestCases(
65+
private void ExploreTestCases(
6466
CollectionStructure collectionStructure,
6567
Folder currentFolder,
6668
IList<string> files)

src/TeaPie/StructureExploration/TestCaseStructureExplorer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using Microsoft.Extensions.Logging;
22
using TeaPie.StructureExploration.Paths;
3+
using TeaPie.TestCases;
34

45
namespace TeaPie.StructureExploration;
56

6-
internal partial class TestCaseStructureExplorer(IPathProvider pathProvider, ILogger<TestCaseStructureExplorer> logger)
7-
: BaseStructureExplorer(pathProvider, logger)
7+
internal partial class TestCaseStructureExplorer(
8+
IPathProvider pathProvider, ILogger<TestCaseStructureExplorer> logger, TpFileParser tpFileParser)
9+
: BaseStructureExplorer(pathProvider, logger, tpFileParser)
810
{
911
protected override CollectionStructure ExploreStructure(ApplicationContext applicationContext)
1012
{

tests/TeaPie.Tests/StructureExploration/CollectionStructureExplorerShould.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NSubstitute;
33
using TeaPie.StructureExploration;
44
using TeaPie.StructureExploration.Paths;
5+
using TeaPie.TestCases;
56
using static Xunit.Assert;
67

78
namespace TeaPie.Tests.StructureExploration;
@@ -222,5 +223,5 @@ public void PopulateTpDefinitionWithCorrectContent()
222223
}
223224

224225
private static CollectionStructureExplorer GetStructureExplorer(IPathProvider? pathProvider = null)
225-
=> new(pathProvider ?? Substitute.For<IPathProvider>(), Substitute.For<ILogger<CollectionStructureExplorer>>());
226+
=> new(pathProvider ?? Substitute.For<IPathProvider>(), Substitute.For<ILogger<CollectionStructureExplorer>>(), new TpFileParser());
226227
}

tests/TeaPie.Tests/StructureExploration/TestCaseStructureExplorerShould.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NSubstitute;
33
using TeaPie.StructureExploration;
44
using TeaPie.StructureExploration.Paths;
5+
using TeaPie.TestCases;
56
using static Xunit.Assert;
67

78
namespace TeaPie.Tests.StructureExploration;
@@ -153,5 +154,5 @@ public void CreateMultipleTestCasesFromTpFileWithMultipleTestCaseBlocks()
153154
}
154155

155156
private static TestCaseStructureExplorer GetStructureExplorer(IPathProvider? pathProvider = null)
156-
=> new(pathProvider ?? Substitute.For<IPathProvider>(), Substitute.For<ILogger<TestCaseStructureExplorer>>());
157+
=> new(pathProvider ?? Substitute.For<IPathProvider>(), Substitute.For<ILogger<TestCaseStructureExplorer>>(), new TpFileParser());
157158
}

0 commit comments

Comments
 (0)