Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Last active November 12, 2021 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayBazuzi/01753887ff3b4a6b39200ad55efe06cf to your computer and use it in GitHub Desktop.
Save JayBazuzi/01753887ff3b4a6b39200ad55efe06cf to your computer and use it in GitHub Desktop.
// requires https://www.nuget.org/packages/FluentAssertions/
using FluentAssertions;
using FluentAssertions.Primitives;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
// create a 11X9 Battleship game
var battleshipGame = new BattleshipGame()
.Should().HaveWidth(11).And.HaveHeight(9).And.Subject;
}
}
public class BattleshipGame
{
public BattleshipGame()
{
// placeholder; Width and Height should be initialized in some way we're not specifying today
Width = 11;
Height = 9;
}
public int Width { get; }
public int Height { get; }
}
public static class BattleshipGameExtensions
{
public static Assertions Should(this BattleshipGame subject)
{
return new Assertions(subject);
}
public class Assertions : ReferenceTypeAssertions<BattleshipGame, Assertions>
{
public Assertions(BattleshipGame subject) : base(subject)
{
}
protected override string Identifier => "Battleship";
public AndConstraint<Assertions> HaveWidth(int i)
{
Subject.Width.Should().Be(i);
return new AndConstraint<Assertions>(this);
}
public AndConstraint<Assertions> HaveHeight(int i)
{
Subject.Height.Should().Be(i);
return new AndConstraint<Assertions>(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment