Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
run: echo "${{ steps.release_notes.outputs.changelog }}" > release-notes.md

- name: Upload Release Notes as artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: release-notes
path: release-notes.md
Expand Down Expand Up @@ -185,6 +185,7 @@ jobs:

- name: Create Bddfy package
working-directory: src

if: steps.changes.outputs.BddfyUpdated == 'true' || github.event_name == 'release'
run: >-
dotnet pack ./TestStack.BDDfy/*.csproj
Expand All @@ -194,13 +195,13 @@ jobs:
--output ../packages

- name: Upload NuGet package as artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: nuget-package
path: packages/*.nupkg

- name: Publish coverage report as artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage-report/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace TestStack.BDDfy.Samples.Atm
{
public class AccountHasInsufficientFund
{
private Card _card;
private Atm _atm;
private Card _card = null!;
private Atm _atm = null!;

// You can override step text using executable attributes
[Given("Given the Account Balance is $10")]
Expand Down Expand Up @@ -63,5 +63,12 @@ public void VerifyLazy()
var engine = this.LazyBDDfy<AccountHolderWithdrawsCash>();
engine.Run();
}

[Fact]
public void VerifyLazyWithAllArguments()
{
var engine = this.LazyBDDfy<AccountHolderWithdrawsCash>("lazy scenario", nameof(AccountHasInsufficientFund));
engine.Run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class AccountHolderWithdrawsCash
private const string WhenTheAccountHolderRequestsTitleTemplate = "When the account holder requests ${0}";
private const string AndTheCardShouldBeReturnedTitleTemplate = "And the card should be returned";

private Card _card;
private Atm _atm;
private Card _card = null!;
private Atm _atm = null!;

internal void Given_the_Account_Balance_is(int balance)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

namespace TestStack.BDDfy.Samples
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
public class BuyingTrainFareWithExamples
{
#pragma warning disable 649
// ReSharper disable once InconsistentNaming
private readonly Fare fare;
private readonly BuyerCategory _buyerCategory;
#pragma warning restore 649
Money Price { get; set; }
private readonly Fare fare = null!;
private readonly BuyerCategory _buyerCategory = default!;
Money Price { get; set; } = null!;

[Fact]
public void SuccessfulRailCardPurchases()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ protected bool Equals(Money other)
return Amount == other.Amount;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((Money)obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Samples
{
public class CanRunAsyncVoidSteps
{
private object _sut;
private object _sut = null!;

internal async void GivenSomeAsyncSetup()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CustomTextReporter : IProcessor
{
private static readonly string Path;

private static string OutputDirectory
private static string? OutputDirectory
{
get
{
Expand All @@ -25,7 +25,7 @@ private static string OutputDirectory

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

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

scenarioReport.AppendLine();
Expand Down
8 changes: 8 additions & 0 deletions src/Samples/TestStack.BDDfy.Samples/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Test step methods cannot be static", Scope = "namespaceanddescendants", Target = "~N:TestStack.BDDfy.Samples")]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.7.0" />
<PackageReference Include="Microsoft.Testing.Platform" Version="2.2.3" />
<PackageReference Include="shouldly" Version="4.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 3 additions & 7 deletions src/Samples/TestStack.BDDfy.Samples/TicTacToe/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Game(string[] firstRow, string[] secondRow, string[] thirdRow)
_board[2] = (string[])thirdRow.Clone();
}

public string Winner
public string? Winner
{
get
{
Expand Down Expand Up @@ -62,15 +62,11 @@ public void PlayAt(int row, int column)
_board[row][column] = player;
}

public override bool Equals(object obj)
{
var game = obj as Game;
return game != null && base.Equals(game);
}
public override bool Equals(object? obj) => obj is Game game && Equals(game);

public bool Equals(Game other)
{
if (ReferenceEquals(null, other)) return false;
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;

for (int i = 0; i < 3; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/TestStack.BDDfy.Samples/TicTacToe/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GameUnderTest
protected const string O = Game.O;
protected const string N = Game.N;

protected Game Game { get; set; }
protected Game Game { get; set; } = null!;
}

public abstract class NewGame : GameUnderTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public string Results
get { return _builder.ToString(); }
}

public override object Execute(Step step, object testObject)
public override object? Execute(Step step, object testObject)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TestStack.BDDfy.Tests.Exceptions
private bool _givenShouldThrow;
private bool _whenShouldThrow;
private bool _thenShouldThrow;
Scenario _scenario;
Scenario _scenario = null!;

void Given()
{
Expand Down Expand Up @@ -130,7 +130,7 @@ Scenario Scenario
}
}

Story Story { get; set; }
Story Story { get; set; } = null!;

public void AssertTearDownMethodIsExecuted()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public void CorrectlyReportsErrorWhenAllStepsNotRun()
{"foo", "bar"}
};

string arg1 = null;
string arg2 = null;
var arg3 = default(string);
string arg1 = null!;
string arg2 = null!;
var arg3 = default(string)!;
this.Given(_ => AFailingStep(arg1), "Given a failing step")
.Then(_ => NonExecutedStep(arg2), "Then multiple assertions")
.And(_ => NonExecutedStep(arg3), "The second one blows up")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class WhenGivenThrowsNotImplementedException : NotImplementedExceptionBas
private void ExecuteUsingFluentScanner()
{
var ex = Should.Throw<Exception>(() => Sut.Execute(ThrowingMethods.Given, true));
ex.GetType().FullName.ShouldContain("Inconclusive");
ex.GetType().FullName!.ShouldContain("Inconclusive");
}

private void ExecuteUsingReflectingScanners()
{
var ex = Should.Throw<Exception>(() => Sut.Execute(ThrowingMethods.Given, false));
ex.GetType().FullName.ShouldContain("Inconclusive");
ex.GetType().FullName!.ShouldContain("Inconclusive");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class WhenThenThrowsNotImplementedException : NotImplementedExceptionBase
private void ExecuteUsingReflectingScanners()
{
var ex = Should.Throw<Exception>(() => Sut.Execute(ThrowingMethods.Then, false));
ex.GetType().FullName.ShouldContain("Inconclusive");
ex.GetType().FullName!.ShouldContain("Inconclusive");
}

private void ExecuteUsingFluentScanner()
{
var ex = Should.Throw<Exception>(() => Sut.Execute(ThrowingMethods.Then, true));
ex.GetType().FullName.ShouldContain("Inconclusive");
ex.GetType().FullName!.ShouldContain("Inconclusive");
}

[Fact]
Expand All @@ -33,7 +33,7 @@ public void WhenIsReportedAsSuccessfulWhenUsingReflectingScanners()
}

[Fact]
public void ThenIsReportedAsNotImplemenetedWhenUsingReflectingScanners()
public void ThenIsReportedAsNotImplementedWhenUsingReflectingScanners()
{
ExecuteUsingReflectingScanners();
Sut.AssertThenStepResult(Result.NotImplemented);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class WhenWhenThrowsNotImplementedException : NotImplementedExceptionBase
private void ExecuteUsingReflectingScanners()
{
var ex = Should.Throw<Exception>(() => Sut.Execute(ThrowingMethods.When, false));
ex.GetType().FullName.ShouldContain("Inconclusive");
ex.GetType().FullName!.ShouldContain("Inconclusive");
}

private void ExecuteUsingFluentScanner()
{
var ex = Should.Throw<Exception>(() => Sut.Execute(ThrowingMethods.When, true));
ex.GetType().FullName.ShouldContain("Inconclusive");
ex.GetType().FullName!.ShouldContain("Inconclusive");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Tests.Exceptions.OtherExceptions
{
public class WhenResolvingExceptionsFromDifferentScanners
{
private ExceptionThrowingTest<OuterException> _sut;
private ExceptionThrowingTest<OuterException> _sut = null!;

/// <summary>
/// Test to resolve issue where fluent scanner was returning the inner exception rather than the outer one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void EachFailedAssertionExampleRunsTeardown()

engine.Story.Result.ShouldBe(Result.Failed);
var titles = engine.Story.Scenarios.Select(s => s.Steps.Single(step => step.Result == Result.Failed).Title).ToArray();
titles.ShouldAllBe(t => t.StartsWith("Then", StringComparison.OrdinalIgnoreCase));
titles.ShouldAllBe(t => t!.StartsWith("Then", StringComparison.OrdinalIgnoreCase));
}

[Fact]
Expand All @@ -51,7 +51,7 @@ public void EachFailedGivenExampleRunsTeardown()

engine.Story.Result.ShouldBe(Result.Failed);
var titles = engine.Story.Scenarios.Select(s=>s.Steps.Single(step=>step.Result == Result.Failed).Title).ToArray();
titles.ShouldAllBe(t=> t.StartsWith("Given", StringComparison.OrdinalIgnoreCase));
titles.ShouldAllBe(t=> t!.StartsWith("Given", StringComparison.OrdinalIgnoreCase));
}

[Fact]
Expand All @@ -73,7 +73,7 @@ public void EachFailedWhenExampleRunsTeardown()

engine.Story.Result.ShouldBe(Result.Failed);
var titles = engine.Story.Scenarios.Select(s => s.Steps.Single(step => step.Result == Result.Failed).Title).ToArray();
titles.ShouldAllBe(t => t.StartsWith("When", StringComparison.OrdinalIgnoreCase));
titles.ShouldAllBe(t => t!.StartsWith("When", StringComparison.OrdinalIgnoreCase));
}
}
}
2 changes: 1 addition & 1 deletion src/TestStack.BDDfy.Tests/FileWriterShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class FileWriterShould
[InlineData("report.txt", "TestDirectory")]
[InlineData("./reports/report.txt", "TestDirectory")]
[InlineData("./reports/report.txt", "TestDirectory/Reports")]
public void CreatePathIfItDoesNotExist(string reportName, string outputDirectory)
public void CreatePathIfItDoesNotExist(string reportName, string? outputDirectory)
{
var fileWriter = new FileWriter();
outputDirectory = outputDirectory is null ? null : System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString(), $"{outputDirectory}");
Expand Down
9 changes: 9 additions & 0 deletions src/TestStack.BDDfy.Tests/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Test step methods cannot be static", Scope = "namespaceanddescendants", Target = "~N:TestStack.BDDfy.Tests")]

2 changes: 1 addition & 1 deletion src/TestStack.BDDfy.Tests/HumanizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void ReportsIllegalExampleStepNames(string stepName, string expectedStepT
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
internal void HumanizeWithNullOrEmptyInput_ReturnsTheSame(string providedInput)
internal void HumanizeWithNullOrEmptyInput_ReturnsTheSame(string? providedInput)
{
Humanizer.Humanize(providedInput).ShouldBe(providedInput);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using NSubstitute;
using TestStack.BDDfy.Reporters;
using TestStack.BDDfy.Reporters.Diagnostics;
Expand All @@ -10,16 +9,16 @@ namespace TestStack.BDDfy.Tests.Reporters.Diagnostics
{
public class DiagnosticsReporterTests
{
private IReportBuilder _builder;
private IReportWriter _writer;
private IReportBuilder _builder = null!;
private IReportWriter _writer = null!;

[Fact]
public void ShouldCreateReportIfProcessingSucceeds()
{
var sut = CreateSut();
_builder.CreateReport(Arg.Any<FileReportModel>()).Returns("Report Data");

sut.Process(new List<Story>());
sut.Process([]);

_writer.Received().OutputReport("Report Data", Arg.Any<string>(), Arg.Any<string>());
}
Expand All @@ -30,7 +29,7 @@ public void ShouldPrintErrorInReportIfProcessingFails()
var sut = CreateSut();
_builder.CreateReport(Arg.Any<FileReportModel>()).Returns(x => { throw new Exception("Error occurred."); });

sut.Process(new List<Story>());
sut.Process([]);

_writer.Received().OutputReport(
Arg.Is<string>(s => s.StartsWith("Error occurred.")),
Expand Down
Loading
Loading