Skip to content

Commit 0df7625

Browse files
committed
Optimize settings binding
1 parent b72840c commit 0df7625

6 files changed

Lines changed: 137 additions & 106 deletions

File tree

src/Tests/Domain/PoemTest.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77

88
namespace Tests.Domain;
99

10-
public class PoemTest(BasicFixture fixture) : IClassFixture<BasicFixture>
10+
public class PoemTest : IClassFixture<BasicFixture>
1111
{
12+
readonly MetricSettings _metricSettings = new();
13+
14+
public PoemTest(BasicFixture fixture)
15+
{
16+
fixture.Configuration.GetSection(Constants.METRIC_SETTINGS).Bind(_metricSettings);
17+
}
18+
1219
[Fact]
1320
[Trait("UnitTest", "Computation")]
1421
public void ShouldHaveIntegerDetailedVerseLength()
@@ -93,7 +100,7 @@ public void ShouldGenerateExpectedExtraAndMetricTags()
93100
ExtraTags = ["wonderful"],
94101
VerseLength = "12"
95102
};
96-
poem.FileContent(-1, fixture.Configuration.GetSection(Constants.METRIC_SETTINGS).Get<MetricSettings>()!)
103+
poem.FileContent(-1, _metricSettings)
97104
.ShouldContain("tags = [\"wonderful\", \"2025\", \"acrostiche\", \"alexandrin\"]");
98105
}
99106

@@ -107,7 +114,7 @@ public void ShouldGenerateExpectedMultipleMetricTags()
107114
TextDate = "01.01.2025",
108115
VerseLength = "6, 3"
109116
};
110-
poem.FileContent(-1, fixture.Configuration.GetSection(Constants.METRIC_SETTINGS).Get<MetricSettings>()!)
117+
poem.FileContent(-1, _metricSettings)
111118
.ShouldContain("tags = [\"2025\", \"métrique variable\", \"hexasyllabe\", \"trisyllabe\"]");
112119
}
113120

@@ -122,7 +129,7 @@ public void ShouldGenerateExpectedLocations()
122129
VerseLength = "8",
123130
Locations = ["Ici", "Là", "ailleurs"]
124131
};
125-
poem.FileContent(-1, fixture.Configuration.GetSection(Constants.METRIC_SETTINGS).Get<MetricSettings>()!)
132+
poem.FileContent(-1, _metricSettings)
126133
.ShouldContain("locations = [\"Ici\", \"\", \"ailleurs\"]");
127134
}
128135
}

src/Tests/StorageSettingsTest.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55

66
namespace Tests;
77

8-
public class StorageSettingsTest(BasicFixture fixture) : IClassFixture<BasicFixture>
8+
public class StorageSettingsTest : IClassFixture<BasicFixture>
99
{
10+
private readonly BasicFixture _fixture;
11+
private static readonly StorageSettings StorageSettings = new();
12+
13+
public StorageSettingsTest(BasicFixture fixture)
14+
{
15+
_fixture = fixture;
16+
fixture.Configuration.GetSection(Constants.STORAGE_SETTINGS).Bind(StorageSettings);
17+
}
18+
1019
[Fact]
1120
[Trait("UnitTest", "Computation")]
1221
public void ShouldGetCorrectSubcategorieNames()
1322
{
14-
var storageSettings = fixture.Configuration.GetSection(Constants.STORAGE_SETTINGS).Get<StorageSettings>();
15-
storageSettings.ShouldNotBeNull();
16-
storageSettings!.SubcategorieNames.Count.ShouldBe(35);
23+
StorageSettings.SubcategorieNames.Count.ShouldBe(35);
1724
}
1825
}

0 commit comments

Comments
 (0)