Skip to content

Commit a7528ac

Browse files
add coverage collector
remove all the build warnings
1 parent e0f794a commit a7528ac

File tree

66 files changed

+312
-597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+312
-597
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ tools/GitReleaseNotes/
2929
tools/gitversion.commandline/
3030
artifacts/
3131
*.code-workspace
32+
**/coverage

src/.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# Default severity for analyzer diagnostics with category 'Style'
4+
dotnet_analyzer_diagnostic.category-Style.severity = none

src/Samples/TestStack.BDDfy.Samples/AssemblySetupFixture.cs

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,36 @@ public AssemblySetupFixture()
3333
}
3434

3535
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
36-
public class AssemblyFixtureAttribute : Attribute
36+
public class AssemblyFixtureAttribute(Type fixtureType): Attribute
3737
{
38-
public AssemblyFixtureAttribute(Type fixtureType)
39-
{
40-
FixtureType = fixtureType;
41-
}
42-
43-
public Type FixtureType { get; private set; }
38+
public Type FixtureType { get; private set; } = fixtureType;
4439
}
4540

46-
public class XunitTestFrameworkWithAssemblyFixture : XunitTestFramework
41+
public class XunitTestFrameworkWithAssemblyFixture(IMessageSink messageSink): XunitTestFramework(messageSink)
4742
{
48-
public XunitTestFrameworkWithAssemblyFixture(IMessageSink messageSink)
49-
: base(messageSink)
50-
{ }
51-
5243
protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
5344
=> new XunitTestFrameworkExecutorWithAssemblyFixture(assemblyName, SourceInformationProvider, DiagnosticMessageSink);
5445
}
5546

56-
public class XunitTestFrameworkExecutorWithAssemblyFixture : XunitTestFrameworkExecutor
47+
public class XunitTestFrameworkExecutorWithAssemblyFixture(AssemblyName assemblyName,
48+
ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink): XunitTestFrameworkExecutor(assemblyName, sourceInformationProvider, diagnosticMessageSink)
5749
{
58-
public XunitTestFrameworkExecutorWithAssemblyFixture(AssemblyName assemblyName,
59-
ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink)
60-
: base(assemblyName, sourceInformationProvider, diagnosticMessageSink)
61-
{
62-
}
63-
6450
protected override async void RunTestCases(IEnumerable<IXunitTestCase> testCases,
6551
IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions)
6652
{
67-
using (
68-
var assemblyRunner = new XunitTestAssemblyRunnerWithAssemblyFixture(TestAssembly, testCases,
69-
DiagnosticMessageSink, executionMessageSink, executionOptions))
70-
await assemblyRunner.RunAsync();
53+
using var assemblyRunner = new XunitTestAssemblyRunnerWithAssemblyFixture(TestAssembly, testCases,
54+
DiagnosticMessageSink, executionMessageSink, executionOptions);
55+
await assemblyRunner.RunAsync();
7156
}
7257
}
7358

74-
public class XunitTestAssemblyRunnerWithAssemblyFixture : XunitTestAssemblyRunner
59+
public class XunitTestAssemblyRunnerWithAssemblyFixture(ITestAssembly testAssembly,
60+
IEnumerable<IXunitTestCase> testCases,
61+
IMessageSink diagnosticMessageSink,
62+
IMessageSink executionMessageSink,
63+
ITestFrameworkExecutionOptions executionOptions): XunitTestAssemblyRunner(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions)
7564
{
76-
readonly Dictionary<Type, object> assemblyFixtureMappings = new Dictionary<Type, object>();
77-
78-
public XunitTestAssemblyRunnerWithAssemblyFixture(ITestAssembly testAssembly,
79-
IEnumerable<IXunitTestCase> testCases,
80-
IMessageSink diagnosticMessageSink,
81-
IMessageSink executionMessageSink,
82-
ITestFrameworkExecutionOptions executionOptions)
83-
: base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions)
84-
{ }
65+
readonly Dictionary<Type, object> assemblyFixtureMappings = new();
8566

8667
protected override async Task AfterTestAssemblyStartingAsync()
8768
{
@@ -118,24 +99,17 @@ protected override Task<RunSummary> RunTestCollectionAsync(IMessageBus messageBu
11899
=> new XunitTestCollectionRunnerWithAssemblyFixture(assemblyFixtureMappings, testCollection, testCases, DiagnosticMessageSink, messageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), cancellationTokenSource).RunAsync();
119100
}
120101

121-
public class XunitTestCollectionRunnerWithAssemblyFixture : XunitTestCollectionRunner
102+
public class XunitTestCollectionRunnerWithAssemblyFixture(Dictionary<Type, object> assemblyFixtureMappings,
103+
ITestCollection testCollection,
104+
IEnumerable<IXunitTestCase> testCases,
105+
IMessageSink diagnosticMessageSink,
106+
IMessageBus messageBus,
107+
ITestCaseOrderer testCaseOrderer,
108+
ExceptionAggregator aggregator,
109+
CancellationTokenSource cancellationTokenSource): XunitTestCollectionRunner(testCollection, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource)
122110
{
123-
readonly Dictionary<Type, object> assemblyFixtureMappings;
124-
readonly IMessageSink diagnosticMessageSink;
125-
126-
public XunitTestCollectionRunnerWithAssemblyFixture(Dictionary<Type, object> assemblyFixtureMappings,
127-
ITestCollection testCollection,
128-
IEnumerable<IXunitTestCase> testCases,
129-
IMessageSink diagnosticMessageSink,
130-
IMessageBus messageBus,
131-
ITestCaseOrderer testCaseOrderer,
132-
ExceptionAggregator aggregator,
133-
CancellationTokenSource cancellationTokenSource)
134-
: base(testCollection, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource)
135-
{
136-
this.assemblyFixtureMappings = assemblyFixtureMappings;
137-
this.diagnosticMessageSink = diagnosticMessageSink;
138-
}
111+
readonly Dictionary<Type, object> assemblyFixtureMappings = assemblyFixtureMappings;
112+
readonly IMessageSink diagnosticMessageSink = diagnosticMessageSink;
139113

140114
protected override Task<RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable<IXunitTestCase> testCases)
141115
{

src/Samples/TestStack.BDDfy.Samples/Atm/AccountHolderWithdrawsCash.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,47 @@ public class AccountHolderWithdrawsCash
1919
private Card _card;
2020
private Atm _atm;
2121

22-
public void Given_the_Account_Balance_is(int balance)
22+
internal void Given_the_Account_Balance_is(int balance)
2323
{
2424
_card = new Card(true, balance);
2525
}
2626

27-
public void Given_the_Card_is_disabled()
27+
internal void Given_the_Card_is_disabled()
2828
{
2929
_card = new Card(false, 100);
3030
_atm = new Atm(100);
3131
}
3232

33-
public void And_the_Card_is_valid()
33+
internal void And_the_Card_is_valid()
3434
{
3535
}
3636

37-
public void And_the_machine_contains(int atmBalance)
37+
internal void And_the_machine_contains(int atmBalance)
3838
{
3939
_atm = new Atm(atmBalance);
4040
}
4141

42-
public void When_the_Account_Holder_requests(int moneyRequest)
42+
internal void When_the_Account_Holder_requests(int moneyRequest)
4343
{
4444
_atm.RequestMoney(_card, moneyRequest);
4545
}
4646

47-
public void The_ATM_should_dispense(int dispensedMoney)
47+
internal void The_ATM_should_dispense(int dispensedMoney)
4848
{
4949
_atm.DispenseValue.ShouldBe(dispensedMoney);
5050
}
5151

52-
public void And_the_Account_Balance_should_be(int balance)
52+
internal void And_the_Account_Balance_should_be(int balance)
5353
{
5454
_card.AccountBalance.ShouldBe(balance);
5555
}
5656

57-
public void Then_Card_is_retained(bool cardIsRetained)
57+
internal void Then_Card_is_retained(bool cardIsRetained)
5858
{
5959
_atm.CardIsRetained.ShouldBe(cardIsRetained);
6060
}
6161

62-
void And_the_ATM_should_say_the_Card_has_been_retained()
62+
internal void And_the_ATM_should_say_the_Card_has_been_retained()
6363
{
6464
_atm.Message.ShouldBe(DisplayMessage.CardIsRetained);
6565
}

src/Samples/TestStack.BDDfy.Samples/Atm/Atm.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
namespace TestStack.BDDfy.Samples.Atm
22
{
3-
public class Atm
3+
public class Atm(int existingCash)
44
{
5-
public int ExistingCash { get; private set; }
6-
7-
public Atm(int existingCash)
8-
{
9-
ExistingCash = existingCash;
10-
}
5+
public int ExistingCash { get; private set; } = existingCash;
116

127
public void RequestMoney(Card card, int request)
138
{
@@ -35,16 +30,10 @@ public void RequestMoney(Card card, int request)
3530
public DisplayMessage Message { get; private set; }
3631
}
3732

38-
public class Card
33+
public class Card(bool enabled, int accountBalance)
3934
{
40-
public int AccountBalance { get; set; }
41-
private readonly bool _enabled;
42-
43-
public Card(bool enabled, int accountBalance)
44-
{
45-
AccountBalance = accountBalance;
46-
_enabled = enabled;
47-
}
35+
public int AccountBalance { get; set; } = accountBalance;
36+
private readonly bool _enabled = enabled;
4837

4938
public bool Enabled
5039
{

src/Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Money.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
namespace TestStack.BDDfy.Samples.BuyingTrainFares
44
{
5-
class Money
5+
class Money(decimal amount)
66
{
7-
public Money(decimal amount)
8-
{
9-
Amount = amount;
10-
}
11-
12-
public decimal Amount { get; set; }
7+
public decimal Amount { get; set; } = amount;
138

149
protected bool Equals(Money other)
1510
{

src/Samples/TestStack.BDDfy.Samples/CanRunAsyncSteps.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public class CanRunAsyncSteps
99
{
1010
private Sut _sut;
1111

12-
public async void GivenSomeAsyncSetup()
12+
internal async void GivenSomeAsyncSetup()
1313
{
1414
_sut = await CreateSut();
1515
}
1616

17-
public void ThenBddfyHasWaitedForThatSetupToCompleteBeforeContinuing()
17+
internal void ThenBddfyHasWaitedForThatSetupToCompleteBeforeContinuing()
1818
{
1919
_sut.ShouldNotBe(null);
2020
}
2121

22-
public async Task AndThenBddfyShouldCaptureExceptionsThrownInAsyncMethod()
22+
internal async Task AndThenBddfyShouldCaptureExceptionsThrownInAsyncMethod()
2323
{
2424
await Task.Yield();
2525
throw new Exception("Exception in async void method!!");

src/Samples/TestStack.BDDfy.Samples/CanWorkWithoutAStory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ namespace TestStack.BDDfy.Samples
44
{
55
public class CanWorkWithoutAStory
66
{
7-
public void Given_no_story_is_provided()
7+
internal void Given_no_story_is_provided()
88
{
99
}
1010

11-
public void When_we_BDDfy_the_class()
11+
internal void When_we_BDDfy_the_class()
1212
{
1313
}
1414

15-
public void Then_the_namespace_is_used_in_the_report()
15+
internal void Then_the_namespace_is_used_in_the_report()
1616
{
1717
}
1818

src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ private static string OutputDirectory
1818
{
1919
get
2020
{
21-
string codeBase = typeof(CustomTextReporter).GetTypeInfo().Assembly.CodeBase;
22-
var uri = new UriBuilder(codeBase);
23-
string path = Uri.UnescapeDataString(uri.Path);
24-
return System.IO.Path.GetDirectoryName(path);
21+
string codeBase = typeof(CustomTextReporter).GetTypeInfo().Assembly.Location;
22+
return System.IO.Path.GetDirectoryName(codeBase);
2523
}
2624
}
2725

src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<PackageReference Include="coverlet.collector" Version="6.0.4">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
</PackageReference>
1822
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
1923
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
2024
<PackageReference Include="shouldly" Version="4.3.0" />

0 commit comments

Comments
 (0)