Skip to content

Files

Latest commit

 

History

History
1250 lines (900 loc) · 41.6 KB

FluentAssertionsAnalyzer.md

File metadata and controls

1250 lines (900 loc) · 41.6 KB

FluentAssertions Analyzer Docs

Scenarios

scenario: StringShouldStartWith

// arrange
var actual = "actual";
var expected = "act";

// old assertion:
actual.StartsWith(expected).Should().BeTrue();

// new assertion:
actual.Should().StartWith(expected);

Failure messages

// arrange
var actual = "actual";
var expected = "wrong";

// old assertion:
actual.StartsWith(expected).Should().BeTrue(); 	// fail message: Expected actual.StartsWith(expected) to be True, but found False.

// new assertion:
actual.Should().StartWith(expected); 	// fail message: Expected actual to start with "wrong", but "actual" differs near "act" (index 0).

scenario: StringShouldEndWith

// arrange
var actual = "actual";
var expected = "ual";

// old assertion:
actual.EndsWith(expected).Should().BeTrue();

// new assertion:
actual.Should().EndWith(expected);

Failure messages

// arrange
var actual = "actual";
var expected = "wrong";

// old assertion:
actual.EndsWith(expected).Should().BeTrue(); 	// fail message: Expected actual.EndsWith(expected) to be True, but found False.

// new assertion:
actual.Should().EndWith(expected); 	// fail message: Expected actual "actual" to end with "wrong".

scenario: StringShouldNotBeNullOrEmpty

// arrange
var actual = "actual";

// old assertion:
string.IsNullOrEmpty(actual).Should().BeFalse();
actual.Should().NotBeNull().And.NotBeEmpty();
actual.Should().NotBeEmpty().And.NotBeNull();

// new assertion:
actual.Should().NotBeNullOrEmpty();

Failure messages

// arrange
var actual = string.Empty;

// old assertion:
string.IsNullOrEmpty(actual).Should().BeFalse(); 	// fail message: Expected string.IsNullOrEmpty(actual) to be False, but found True.
actual.Should().NotBeNull().And.NotBeEmpty(); 	// fail message: Did not expect actual to be empty.
actual.Should().NotBeEmpty().And.NotBeNull(); 	// fail message: Did not expect actual to be empty.

// new assertion:
actual.Should().NotBeNullOrEmpty(); 	// fail message: Expected actual not to be <null> or empty, but found "".

scenario: StringShouldBeNullOrEmpty

// arrange
var actual = string.Empty;

// old assertion:
string.IsNullOrEmpty(actual).Should().BeTrue();

// new assertion:
actual.Should().BeNullOrEmpty();

Failure messages

// arrange
var actual = "actual";

// old assertion:
string.IsNullOrEmpty(actual).Should().BeTrue(); 	// fail message: Expected string.IsNullOrEmpty(actual) to be True, but found False.

// new assertion:
actual.Should().BeNullOrEmpty(); 	// fail message: Expected actual to be <null> or empty, but found "actual".

scenario: StringShouldBeNullOrWhiteSpace

// arrange
var actual = string.Empty;

// old assertion:
string.IsNullOrWhiteSpace(actual).Should().BeTrue();

// new assertion:
actual.Should().BeNullOrWhiteSpace();

Failure messages

// arrange
var actual = "actual";

// old assertion:
string.IsNullOrWhiteSpace(actual).Should().BeTrue(); 	// fail message: Expected string.IsNullOrWhiteSpace(actual) to be True, but found False.

// new assertion:
actual.Should().BeNullOrWhiteSpace(); 	// fail message: Expected actual to be <null> or whitespace, but found "actual".

scenario: StringShouldNotBeNullOrWhiteSpace

// arrange
var actual = "actual";

// old assertion:
string.IsNullOrWhiteSpace(actual).Should().BeFalse();

// new assertion:
actual.Should().NotBeNullOrWhiteSpace();

Failure messages

// arrange
var actual = string.Empty;

// old assertion:
string.IsNullOrWhiteSpace(actual).Should().BeFalse(); 	// fail message: Expected string.IsNullOrWhiteSpace(actual) to be False, but found True.

// new assertion:
actual.Should().NotBeNullOrWhiteSpace(); 	// fail message: Expected actual not to be <null> or whitespace, but found "".

scenario: StringShouldHaveLength

// arrange
var actual = "actual";
var expected = 6;

// old assertion:
actual.Length.Should().Be(expected);

// new assertion:
actual.Should().HaveLength(expected);

Failure messages

// arrange
var actual = "actual";
var expected = 5;

// old assertion:
actual.Length.Should().Be(expected); 	// fail message: Expected actual.Length to be 5, but found 6.

// new assertion:
actual.Should().HaveLength(expected); 	// fail message: Expected actual with length 5, but found string "actual" with length 6.

scenario: CollectionShouldNotBeEmpty

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Any().Should().BeTrue();

// new assertion:
collection.Should().NotBeEmpty();

Failure messages

// arrange
var collection = new List<int> { };

// old assertion:
collection.Any().Should().BeTrue(); 	// fail message: Expected collection.Any() to be True, but found False.

// new assertion:
collection.Should().NotBeEmpty(); 	// fail message: Expected collection not to be empty.

scenario: CollectionShouldBeEmpty

// arrange
var collection = new List<int>();

// old assertion:
collection.Any().Should().BeFalse();
collection.Count().Should().Be(0);
collection.Count.Should().Be(0);
collection.Should().HaveCount(0);

// new assertion:
collection.Should().BeEmpty();

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Any().Should().BeFalse(); 	// fail message: Expected collection.Any() to be False, but found True.
collection.Count().Should().Be(0); 	// fail message: Expected collection.Count() to be 0, but found 3 (difference of 3).
collection.Count.Should().Be(0); 	// fail message: Expected collection.Count to be 0, but found 3 (difference of 3).
collection.Should().HaveCount(0); 	// fail message: Expected collection to contain 0 item(s), but found 3: {1, 2, 3}.

// new assertion:
collection.Should().BeEmpty(); 	// fail message: Expected collection to be empty, but found at least one item {1}.

scenario: CollectionShouldNotContainCondition

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Any(i => i == 4).Should().BeFalse();
collection.Where(i => i == 4).Should().BeEmpty();

// new assertion:
collection.Should().NotContain(i => i == 4);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 4, 5 };

// old assertion:
collection.Any(i => i == 4).Should().BeFalse(); 	// fail message: Expected collection.Any(i => i == 4) to be False, but found True.
collection.Where(i => i == 4).Should().BeEmpty(); 	// fail message: Expected collection.Where(i => i == 4) to be empty, but found at least one item {4}.

// new assertion:
collection.Should().NotContain(i => i == 4); 	// fail message: Expected collection {1, 2, 3, 4, 5} to not have any items matching (i == 4), but found {4}.

scenario: CollectionShouldNotContainItem

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Contains(4).Should().BeFalse();

// new assertion:
collection.Should().NotContain(4);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 4, 5 };

// old assertion:
collection.Contains(4).Should().BeFalse(); 	// fail message: Expected collection.Contains(4) to be False, but found True.

// new assertion:
collection.Should().NotContain(4); 	// fail message: Expected collection {1, 2, 3, 4, 5} to not contain 4.

scenario: CollectionShouldOnlyContainProperty

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.All(x => x > 0).Should().BeTrue();

// new assertion:
collection.Should().OnlyContain(x => x > 0);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, -1 };

// old assertion:
collection.All(x => x > 0).Should().BeTrue(); 	// fail message: Expected collection.All(x => x > 0) to be True, but found False.

// new assertion:
collection.Should().OnlyContain(x => x > 0); 	// fail message: Expected collection to contain only items matching (x > 0), but {-1} do(es) not match.

scenario: CollectionShouldContainItem

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Contains(2).Should().BeTrue();

// new assertion:
collection.Should().Contain(2);

Failure messages

// arrange
var collection = new List<int> { 1, 3, 4, 5 };

// old assertion:
collection.Contains(2).Should().BeTrue(); 	// fail message: Expected collection.Contains(2) to be True, but found False.

// new assertion:
collection.Should().Contain(2); 	// fail message: Expected collection {1, 3, 4, 5} to contain 2.

scenario: CollectionShouldContainCondition

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Any(i => i == 2).Should().BeTrue();
collection.Where(i => i == 2).Should().NotBeEmpty();

// new assertion:
collection.Should().Contain(i => i == 2);

Failure messages

// arrange
var collection = new List<int> { 3, 4, 5 };

// old assertion:
collection.Any(i => i == 2).Should().BeTrue(); 	// fail message: Expected collection.Any(i => i == 2) to be True, but found False.
collection.Where(i => i == 2).Should().NotBeEmpty(); 	// fail message: Expected collection.Where(i => i == 2) not to be empty.

// new assertion:
collection.Should().Contain(i => i == 2); 	// fail message: Expected collection {3, 4, 5} to have an item matching (i == 2).

scenario: CollectionShouldHaveCount_Count

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().Be(3);
collection.Count.Should().Be(3);

// new assertion:
collection.Should().HaveCount(3);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 4, 5 };

// old assertion:
collection.Count().Should().Be(3); 	// fail message: Expected collection.Count() to be 3, but found 5.
collection.Count.Should().Be(3); 	// fail message: Expected collection.Count to be 3, but found 5.

// new assertion:
collection.Should().HaveCount(3); 	// fail message: Expected collection to contain 3 item(s), but found 5: {1, 2, 3, 4, 5}.

scenario: CollectionShouldHaveCount_Length

// arrange
var collection = new int[] { 1, 2, 3 };

// old assertion:
collection.Length.Should().Be(3);

// new assertion:
collection.Should().HaveCount(3);

Failure messages

// arrange
var collection = new int[] { 1, 2, 3, 4, 5 };

// old assertion:
collection.Length.Should().Be(3); 	// fail message: Expected collection.Length to be 3, but found 5.

// new assertion:
collection.Should().HaveCount(3); 	// fail message: Expected collection to contain 3 item(s), but found 5: {1, 2, 3, 4, 5}.

scenario: CollectionShouldNotHaveCount_Count

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().NotBe(4);

// new assertion:
collection.Should().NotHaveCount(4);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 4 };

// old assertion:
collection.Count().Should().NotBe(4); 	// fail message: Did not expect collection.Count() to be 4.

// new assertion:
collection.Should().NotHaveCount(4); 	// fail message: Expected collection to not contain 4 item(s), but found 4.

scenario: CollectionShouldContainSingle

// arrange
var collection = new List<int> { 1 };

// old assertion:
collection.Count().Should().Be(1);
collection.Count.Should().Be(1);
collection.Should().HaveCount(1);

// new assertion:
collection.Should().ContainSingle();

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().Be(1); 	// fail message: Expected collection.Count() to be 1, but found 3.
collection.Count.Should().Be(1); 	// fail message: Expected collection.Count to be 1, but found 3.
collection.Should().HaveCount(1); 	// fail message: Expected collection to contain 1 item(s), but found 3: {1, 2, 3}.

// new assertion:
collection.Should().ContainSingle(); 	// fail message: Expected collection to contain a single item, but found {1, 2, 3}.

scenario: CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().BeGreaterThan(2);

// new assertion:
collection.Should().HaveCountGreaterThan(2);

Failure messages

// arrange
var collection = new List<int> { 1 };

// old assertion:
collection.Count().Should().BeGreaterThan(2); 	// fail message: Expected collection.Count() to be greater than 2, but found 1.

// new assertion:
collection.Should().HaveCountGreaterThan(2); 	// fail message: Expected collection to contain more than 2 item(s), but found 1: {1}.

scenario: CollectionShouldHaveCountGreaterOrEqualTo_CountShouldBeGreaterOrEqualTo

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().BeGreaterOrEqualTo(3);

// new assertion:
collection.Should().HaveCountGreaterOrEqualTo(3);

Failure messages

// arrange
var collection = new List<int> { 1, 2 };

// old assertion:
collection.Count().Should().BeGreaterOrEqualTo(3); 	// fail message: Expected collection.Count() to be greater than or equal to 3, but found 2.

// new assertion:
collection.Should().HaveCountGreaterOrEqualTo(3); 	// fail message: Expected collection to contain at least 3 item(s), but found 2: {1, 2}.

scenario: CollectionShouldHaveCountLessThan_CountShouldBeLessThan

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().BeLessThan(4);

// new assertion:
collection.Should().HaveCountLessThan(4);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 4, 5 };

// old assertion:
collection.Count().Should().BeLessThan(4); 	// fail message: Expected collection.Count() to be less than 4, but found 5.

// new assertion:
collection.Should().HaveCountLessThan(4); 	// fail message: Expected collection to contain fewer than 4 item(s), but found 5: {1, 2, 3, 4, 5}.

scenario: CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Count().Should().BeLessOrEqualTo(3);

// new assertion:
collection.Should().HaveCountLessOrEqualTo(3);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 4 };

// old assertion:
collection.Count().Should().BeLessOrEqualTo(3); 	// fail message: Expected collection.Count() to be less than or equal to 3, but found 4.

// new assertion:
collection.Should().HaveCountLessOrEqualTo(3); 	// fail message: Expected collection to contain at most 3 item(s), but found 4: {1, 2, 3, 4}.

scenario: CollectionShouldHaveSameCount_ShouldHaveCountOtherCollectionCount

// arrange
var collection = new List<int> { 1, 2, 3 };
var otherCollection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Should().HaveCount(otherCollection.Count());

// new assertion:
collection.Should().HaveSameCount(otherCollection);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3 };
var otherCollection = new List<int> { 2, 3, 4, 5 };

// old assertion:
collection.Should().HaveCount(otherCollection.Count()); 	// fail message: Expected collection to contain 4 item(s), but found 3: {1, 2, 3}.

// new assertion:
collection.Should().HaveSameCount(otherCollection); 	// fail message: Expected collection to have 4 item(s), but found 3.

scenario: CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount

// arrange
var collection = new List<int> { 1, 2, 3 };
var otherCollection = new List<int> { 1, 2, 3, 4 };

// old assertion:
collection.Count().Should().NotBe(otherCollection.Count());

// new assertion:
collection.Should().NotHaveSameCount(otherCollection);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3 };
var otherCollection = new List<int> { 4, 5, 6 };

// old assertion:
collection.Count().Should().NotBe(otherCollection.Count()); 	// fail message: Did not expect collection.Count() to be 3.

// new assertion:
collection.Should().NotHaveSameCount(otherCollection); 	// fail message: Expected collection to not have 3 item(s), but found 3.

scenario: CollectionShouldContainSingle_WhereShouldHaveCount1

// arrange
var collection = new List<int> { 1 };

// old assertion:
collection.Where(i => i == 1).Should().HaveCount(1);

// new assertion:
collection.Should().ContainSingle(i => i == 1);

Failure messages

// arrange
var collection = new List<int> { 1, 2, 3, 1 };

// old assertion:
collection.Where(i => i == 1).Should().HaveCount(1); 	// fail message: Expected collection.Where(i => i == 1) to contain 1 item(s), but found 2: {1, 1}.

// new assertion:
collection.Should().ContainSingle(i => i == 1); 	// fail message: Expected collection to contain a single item matching (i == 1), but 2 such items were found.

scenario: CollectionShouldNotBeNullOrEmpty

// arrange
var collection = new List<int> { 1, 2, 3 };

// old assertion:
collection.Should().NotBeEmpty().And.NotBeNull();
collection.Should().NotBeNull().And.NotBeEmpty();

// new assertion:
collection.Should().NotBeNullOrEmpty();

Failure messages

// arrange
var collection = new List<int>();

// old assertion:
collection.Should().NotBeEmpty().And.NotBeNull(); 	// fail message: Expected collection not to be empty.
collection.Should().NotBeNull().And.NotBeEmpty(); 	// fail message: Expected collection not to be empty.

// new assertion:
collection.Should().NotBeNullOrEmpty(); 	// fail message: Expected collection not to be empty.

scenario: DictionaryShouldContainKey

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.ContainsKey("two").Should().BeTrue();

// new assertion:
dictionary.Should().ContainKey("two");

Failure messages

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["three"] = 3 };

// old assertion:
dictionary.ContainsKey("two").Should().BeTrue(); 	// fail message: Expected dictionary.ContainsKey("two") to be True, but found False.

// new assertion:
dictionary.Should().ContainKey("two"); 	// fail message: Expected dictionary {["one"] = 1, ["three"] = 3} to contain key "two".

scenario: DictionaryShouldNotContainKey

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.ContainsKey("four").Should().BeFalse();

// new assertion:
dictionary.Should().NotContainKey("four");

Failure messages

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3, ["four"] = 4 };

// old assertion:
dictionary.ContainsKey("four").Should().BeFalse(); 	// fail message: Expected dictionary.ContainsKey("four") to be False, but found True.

// new assertion:
dictionary.Should().NotContainKey("four"); 	// fail message: Expected dictionary {["one"] = 1, ["two"] = 2, ["three"] = 3, ["four"] = 4} not to contain key "four", but found it anyhow.

scenario: DictionaryShouldContainValue

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.ContainsValue(2).Should().BeTrue();

// new assertion:
dictionary.Should().ContainValue(2);

Failure messages

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.ContainsValue(4).Should().BeTrue(); 	// fail message: Expected dictionary.ContainsValue(4) to be True, but found False.

// new assertion:
dictionary.Should().ContainValue(4); 	// fail message: Expected dictionary {["one"] = 1, ["two"] = 2, ["three"] = 3} to contain value 4.

scenario: DictionaryShouldNotContainValue

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.ContainsValue(4).Should().BeFalse();

// new assertion:
dictionary.Should().NotContainValue(4);

Failure messages

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3, ["four"] = 4 };

// old assertion:
dictionary.ContainsValue(4).Should().BeFalse(); 	// fail message: Expected dictionary.ContainsValue(4) to be False, but found True.

// new assertion:
dictionary.Should().NotContainValue(4); 	// fail message: Expected dictionary {["one"] = 1, ["two"] = 2, ["three"] = 3, ["four"] = 4} not to contain value 4, but found it anyhow.

scenario: DictionaryShouldContainKeyAndValue

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.Should().ContainKey("two").And.ContainValue(2);

// new assertion:
dictionary.Should().Contain("two", 2);

Failure messages

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };

// old assertion:
dictionary.Should().ContainKey("two").And.ContainValue(4); 	// fail message: Expected dictionary {["one"] = 1, ["two"] = 2, ["three"] = 3} to contain value 4.

// new assertion:
dictionary.Should().Contain("two", 4); 	// fail message: Expected dictionary to contain value 4 at key "two", but found 2.

scenario: DictionaryShouldContainPair

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };
var pair = new KeyValuePair<string, int>("two", 2);

// old assertion:
dictionary.Should().ContainKey(pair.Key).And.ContainValue(pair.Value);

// new assertion:
dictionary.Should().Contain(pair);

Failure messages

// arrange
var dictionary = new Dictionary<string, int> { ["one"] = 1, ["two"] = 2, ["three"] = 3 };
var pair = new KeyValuePair<string, int>("two", 4);

// old assertion:
dictionary.Should().ContainKey(pair.Key).And.ContainValue(pair.Value); 	// fail message: Expected dictionary {["one"] = 1, ["two"] = 2, ["three"] = 3} to contain value 4.

// new assertion:
dictionary.Should().Contain(pair); 	// fail message: Expected dictionary to contain value 4 at key "two", but found 2.

scenario: ExceptionShouldThrowWithMessage_Be

// arrange
static void ThrowException() => throw new Exception("message");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().Be("message");
action.Should().Throw<Exception>().Which.Message.Should().Be("message");

// new assertion:
action.Should().Throw<Exception>().WithMessage("message");

Failure messages

// arrange
static void ThrowException() => throw new Exception("wrong");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().Be("message"); 	// fail message: Expected action to be "message" with a length of 7, but "wrong" has a length of 5, differs near "wro" (index 0).
action.Should().Throw<Exception>().Which.Message.Should().Be("message"); 	// fail message: Expected action to be "message" with a length of 7, but "wrong" has a length of 5, differs near "wro" (index 0).

// new assertion:
action.Should().Throw<Exception>().WithMessage("message"); 	// fail message: Expected exception message to match the equivalent of "message", but "wrong" does not.

scenario: ExceptionShouldThrowWithMessage_Contain

// arrange
static void ThrowException() => throw new Exception("message");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().Contain("mess");
action.Should().Throw<Exception>().Which.Message.Should().Contain("mess");

// new assertion:
action.Should().Throw<Exception>().WithMessage("*mess*");

Failure messages

// arrange
static void ThrowException() => throw new Exception("wrong");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().Contain("mess"); 	// fail message: Expected action "wrong" to contain "mess".
action.Should().Throw<Exception>().Which.Message.Should().Contain("mess"); 	// fail message: Expected action "wrong" to contain "mess".

// new assertion:
action.Should().Throw<Exception>().WithMessage("*mess*"); 	// fail message: Expected exception message to match the equivalent of "*mess*", but "wrong" does not.

scenario: ExceptionShouldThrowWithMessage_EndWith

// arrange
static void ThrowException() => throw new Exception("message");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().EndWith("age");
action.Should().Throw<Exception>().Which.Message.Should().EndWith("age");

// new assertion:
action.Should().Throw<Exception>().WithMessage("*age");

Failure messages

// arrange
static void ThrowException() => throw new Exception("wrong");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().EndWith("age"); 	// fail message: Expected action "wrong" to end with "age".
action.Should().Throw<Exception>().Which.Message.Should().EndWith("age"); 	// fail message: Expected action "wrong" to end with "age".

// new assertion:
action.Should().Throw<Exception>().WithMessage("*age"); 	// fail message: Expected exception message to match the equivalent of "*age", but "wrong" does not.

scenario: ExceptionShouldThrowWithMessage_StartWith

// arrange
static void ThrowException() => throw new Exception("message");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().StartWith("mes");
action.Should().Throw<Exception>().Which.Message.Should().StartWith("mes");

// new assertion:
action.Should().Throw<Exception>().WithMessage("mes*");

Failure messages

// arrange
static void ThrowException() => throw new Exception("wrong");
Action action = ThrowException;

// old assertion:
action.Should().Throw<Exception>().And.Message.Should().StartWith("mes"); 	// fail message: Expected action to start with "mes", but "wrong" differs near "wro" (index 0).
action.Should().Throw<Exception>().Which.Message.Should().StartWith("mes"); 	// fail message: Expected action to start with "mes", but "wrong" differs near "wro" (index 0).

// new assertion:
action.Should().Throw<Exception>().WithMessage("mes*"); 	// fail message: Expected exception message to match the equivalent of "mes*", but "wrong" does not.

scenario: ExceptionShouldThrowExactlyWithMessage_Be

// arrange
static void ThrowException() => throw new ArgumentException("message");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().Be("message");
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().Be("message");

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("message");

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("wrong");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().Be("message"); 	// fail message: Expected action to be "message" with a length of 7, but "wrong" has a length of 5, differs near "wro" (index 0).
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().Be("message"); 	// fail message: Expected action to be "message" with a length of 7, but "wrong" has a length of 5, differs near "wro" (index 0).

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("message"); 	// fail message: Expected exception message to match the equivalent of "message", but "wrong" does not.

scenario: ExceptionShouldThrowExactlyWithMessage_Contain

// arrange
static void ThrowException() => throw new ArgumentException("message");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().Contain("mess");
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().Contain("mess");

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("*mess*");

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("wrong");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().Contain("mess"); 	// fail message: Expected action "wrong" to contain "mess".
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().Contain("mess"); 	// fail message: Expected action "wrong" to contain "mess".

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("*mess*"); 	// fail message: Expected exception message to match the equivalent of "*mess*", but "wrong" does not.

scenario: ExceptionShouldThrowExactlyWithMessage_EndWith

// arrange
static void ThrowException() => throw new ArgumentException("message");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().EndWith("age");
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().EndWith("age");

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("*age");

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("wrong");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().EndWith("age"); 	// fail message: Expected action "wrong" to end with "age".
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().EndWith("age"); 	// fail message: Expected action "wrong" to end with "age".

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("*age"); 	// fail message: Expected exception message to match the equivalent of "*age", but "wrong" does not.

scenario: ExceptionShouldThrowExactlyWithMessage_StartWith

// arrange
static void ThrowException() => throw new ArgumentException("message");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().StartWith("mes");
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().StartWith("mes");

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("mes*");

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("wrong");
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.Message.Should().StartWith("mes"); 	// fail message: Expected action to start with "mes", but "wrong" differs near "wro" (index 0).
action.Should().ThrowExactly<ArgumentException>().Which.Message.Should().StartWith("mes"); 	// fail message: Expected action to start with "mes", but "wrong" differs near "wro" (index 0).

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithMessage("mes*"); 	// fail message: Expected exception message to match the equivalent of "mes*", but "wrong" does not.

scenario: ExceptionShouldThrowExactlyWithInnerExceptionExactly_BeOfType

// arrange
static void ThrowException() => throw new ArgumentException("message", new InvalidOperationException());
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.InnerException.Should().BeOfType<InvalidOperationException>();
action.Should().ThrowExactly<ArgumentException>().Which.InnerException.Should().BeOfType<InvalidOperationException>();

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithInnerExceptionExactly<InvalidOperationException>();

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("message", new InvalidOperationException());
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.InnerException.Should().BeOfType<ArgumentException>(); 	// fail message: Expected type to be System.ArgumentException, but found System.InvalidOperationException.
action.Should().ThrowExactly<ArgumentException>().Which.InnerException.Should().BeOfType<ArgumentException>(); 	// fail message: Expected type to be System.ArgumentException, but found System.InvalidOperationException.

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithInnerExceptionExactly<ArgumentException>(); 	// fail message: Expected inner System.ArgumentException, but found System.InvalidOperationException: Operation is not valid due to the current state of the object..

scenario: ExceptionShouldThrowWithInnerExceptionExactly_BeOfType

// arrange
static void ThrowException() => throw new ArgumentException("message", new InvalidOperationException());
Action action = ThrowException;

// old assertion:
action.Should().Throw<ArgumentException>().And.InnerException.Should().BeOfType<InvalidOperationException>();
action.Should().Throw<ArgumentException>().Which.InnerException.Should().BeOfType<InvalidOperationException>();

// new assertion:
action.Should().Throw<ArgumentException>().WithInnerExceptionExactly<InvalidOperationException>();

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("message", new InvalidOperationException());
Action action = ThrowException;

// old assertion:
action.Should().Throw<ArgumentException>().And.InnerException.Should().BeOfType<ArgumentException>(); 	// fail message: Expected type to be System.ArgumentException, but found System.InvalidOperationException.
action.Should().Throw<ArgumentException>().Which.InnerException.Should().BeOfType<ArgumentException>(); 	// fail message: Expected type to be System.ArgumentException, but found System.InvalidOperationException.

// new assertion:
action.Should().Throw<ArgumentException>().WithInnerExceptionExactly<ArgumentException>(); 	// fail message: Expected inner System.ArgumentException, but found System.InvalidOperationException: Operation is not valid due to the current state of the object..

scenario: ExceptionShouldThrowExactlyWithInnerException_BeAssignableTo

// arrange
static void ThrowException() => throw new ArgumentException("message", new InvalidOperationException());
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.InnerException.Should().BeAssignableTo<InvalidOperationException>();
action.Should().ThrowExactly<ArgumentException>().Which.InnerException.Should().BeAssignableTo<InvalidOperationException>();

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithInnerException<InvalidOperationException>();

Failure messages

// arrange
static void ThrowException() => throw new ArgumentException("message", new InvalidOperationException());
Action action = ThrowException;

// old assertion:
action.Should().ThrowExactly<ArgumentException>().And.InnerException.Should().BeAssignableTo<ArgumentException>(); 	// fail message: Expected action to be assignable to System.ArgumentException, but System.InvalidOperationException is not.
action.Should().ThrowExactly<ArgumentException>().Which.InnerException.Should().BeAssignableTo<ArgumentException>(); 	// fail message: Expected action to be assignable to System.ArgumentException, but System.InvalidOperationException is not.

// new assertion:
action.Should().ThrowExactly<ArgumentException>().WithInnerException<ArgumentException>(); 	// fail message: Expected inner System.ArgumentException, but found System.InvalidOperationException: Operation is not valid due to the current state of the object..