Skip to content

Commit 2fc493f

Browse files
remove null reference warnings and anything that turned on after enabling nullable
1 parent 269fa2c commit 2fc493f

66 files changed

Lines changed: 278 additions & 280 deletions

File tree

Some content is hidden

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

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace TestStack.BDDfy.Samples.Atm
55
{
66
public class AccountHasInsufficientFund
77
{
8-
private Card _card;
9-
private Atm _atm;
8+
private Card _card = null!;
9+
private Atm _atm = null!;
1010

1111
// You can override step text using executable attributes
1212
[Given("Given the Account Balance is $10")]
@@ -63,5 +63,12 @@ public void VerifyLazy()
6363
var engine = this.LazyBDDfy<AccountHolderWithdrawsCash>();
6464
engine.Run();
6565
}
66+
67+
[Fact]
68+
public void VerifyLazyWithAllArguments()
69+
{
70+
var engine = this.LazyBDDfy<AccountHolderWithdrawsCash>("lazy scenario", nameof(AccountHasInsufficientFund));
71+
engine.Run();
72+
}
6673
}
6774
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class AccountHolderWithdrawsCash
1616
private const string WhenTheAccountHolderRequestsTitleTemplate = "When the account holder requests ${0}";
1717
private const string AndTheCardShouldBeReturnedTitleTemplate = "And the card should be returned";
1818

19-
private Card _card;
20-
private Atm _atm;
19+
private Card _card = null!;
20+
private Atm _atm = null!;
2121

2222
internal void Given_the_Account_Balance_is(int balance)
2323
{

src/Samples/TestStack.BDDfy.Samples/BuyingTrainFareWithExamples.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
namespace TestStack.BDDfy.Samples
55
{
6+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
67
public class BuyingTrainFareWithExamples
78
{
8-
#pragma warning disable 649
9-
// ReSharper disable once InconsistentNaming
10-
private readonly Fare fare;
11-
private readonly BuyerCategory _buyerCategory;
12-
#pragma warning restore 649
13-
Money Price { get; set; }
9+
private readonly Fare fare = null!;
10+
private readonly BuyerCategory _buyerCategory = default!;
11+
Money Price { get; set; } = null!;
1412

1513
[Fact]
1614
public void SuccessfulRailCardPurchases()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ protected bool Equals(Money other)
1111
return Amount == other.Amount;
1212
}
1313

14-
public override bool Equals(object obj)
14+
public override bool Equals(object? obj)
1515
{
16-
if (ReferenceEquals(null, obj)) return false;
16+
if (obj is null) return false;
1717
if (ReferenceEquals(this, obj)) return true;
1818
if (obj.GetType() != GetType()) return false;
1919
return Equals((Money)obj);

src/Samples/TestStack.BDDfy.Samples/CanRunAsyncVoidSteps.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Samples
77
{
88
public class CanRunAsyncVoidSteps
99
{
10-
private object _sut;
10+
private object _sut = null!;
1111

1212
internal async void GivenSomeAsyncSetup()
1313
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class CustomTextReporter : IProcessor
1414
{
1515
private static readonly string Path;
1616

17-
private static string OutputDirectory
17+
private static string? OutputDirectory
1818
{
1919
get
2020
{
@@ -25,7 +25,7 @@ private static string OutputDirectory
2525

2626
static CustomTextReporter()
2727
{
28-
Path = System.IO.Path.Combine(OutputDirectory, "BDDfy-text-report.txt");
28+
Path = System.IO.Path.Combine(OutputDirectory ?? string.Empty, "BDDfy-text-report.txt");
2929

3030
if(File.Exists(Path))
3131
File.Delete(Path);
@@ -52,7 +52,7 @@ public void Process(Story story)
5252
if (scenario.Result != Result.Passed && scenario.Steps.Any(s => s.Exception != null))
5353
{
5454
scenarioReport.Append(string.Format(" {0} : ", scenario.Result));
55-
scenarioReport.AppendLine(scenario.Steps.First(s => s.Result == scenario.Result).Exception.Message);
55+
scenarioReport.AppendLine(scenario.Steps.First(s => s.Result == scenario.Result).Exception?.Message);
5656
}
5757

5858
scenarioReport.AppendLine();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Test step methods cannot be static", Scope = "namespaceanddescendants", Target = "~N:TestStack.BDDfy.Samples")]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
1717
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
18+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.7.0" />
19+
<PackageReference Include="Microsoft.Testing.Platform" Version="2.2.3" />
1820
<PackageReference Include="shouldly" Version="4.3.0" />
1921
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2022
<PrivateAssets>all</PrivateAssets>

src/Samples/TestStack.BDDfy.Samples/TicTacToe/Game.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Game(string[] firstRow, string[] secondRow, string[] thirdRow)
2525
_board[2] = (string[])thirdRow.Clone();
2626
}
2727

28-
public string Winner
28+
public string? Winner
2929
{
3030
get
3131
{
@@ -62,15 +62,11 @@ public void PlayAt(int row, int column)
6262
_board[row][column] = player;
6363
}
6464

65-
public override bool Equals(object obj)
66-
{
67-
var game = obj as Game;
68-
return game != null && base.Equals(game);
69-
}
65+
public override bool Equals(object? obj) => obj is Game game && Equals(game);
7066

7167
public bool Equals(Game other)
7268
{
73-
if (ReferenceEquals(null, other)) return false;
69+
if (other is null) return false;
7470
if (ReferenceEquals(this, other)) return true;
7571

7672
for (int i = 0; i < 3; i++)

src/Samples/TestStack.BDDfy.Samples/TicTacToe/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class GameUnderTest
1818
protected const string O = Game.O;
1919
protected const string N = Game.N;
2020

21-
protected Game Game { get; set; }
21+
protected Game Game { get; set; } = null!;
2222
}
2323

2424
public abstract class NewGame : GameUnderTest

0 commit comments

Comments
 (0)