diff --git a/docs/FluentAssertionsAnalyzer.md b/docs/FluentAssertionsAnalyzer.md index 5a22da6..bb36c80 100644 --- a/docs/FluentAssertionsAnalyzer.md +++ b/docs/FluentAssertionsAnalyzer.md @@ -4,6 +4,13 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser # FluentAssertions Analyzer Docs +- [StringShouldStartWith](#scenario-stringshouldstartwith) - `actual.Should().StartWith(expected);` +- [StringShouldEndWith](#scenario-stringshouldendwith) - `actual.Should().EndWith(expected);` +- [StringShouldNotBeNullOrEmpty](#scenario-stringshouldnotbenullorempty) - `actual.Should().NotBeNullOrEmpty();` +- [StringShouldBeNullOrEmpty](#scenario-stringshouldbenullorempty) - `actual.Should().BeNullOrEmpty();` +- [StringShouldBeNullOrWhiteSpace](#scenario-stringshouldbenullorwhitespace) - `actual.Should().BeNullOrWhiteSpace();` +- [StringShouldNotBeNullOrWhiteSpace](#scenario-stringshouldnotbenullorwhitespace) - `actual.Should().NotBeNullOrWhiteSpace();` +- [StringShouldHaveLength](#scenario-stringshouldhavelength) - `actual.Should().HaveLength(expected);` - [CollectionShouldNotBeEmpty](#scenario-collectionshouldnotbeempty) - `collection.Should().NotBeEmpty();` - [CollectionShouldBeEmpty](#scenario-collectionshouldbeempty) - `collection.Should().BeEmpty();` - [CollectionShouldNotContainCondition](#scenario-collectionshouldnotcontaincondition) - `collection.Should().NotContain(i => i == 4);` @@ -44,6 +51,198 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser ## Scenarios +### scenario: StringShouldStartWith + +```cs +// arrange +var actual = "actual"; +var expected = "act"; + +// old assertion: +actual.StartsWith(expected).Should().BeTrue(); + +// new assertion: +actual.Should().StartWith(expected); +``` + +#### Failure messages + +```cs +// 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 + +```cs +// arrange +var actual = "actual"; +var expected = "ual"; + +// old assertion: +actual.EndsWith(expected).Should().BeTrue(); + +// new assertion: +actual.Should().EndWith(expected); +``` + +#### Failure messages + +```cs +// 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 + +```cs +// 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 + +```cs +// 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 or empty, but found "". +``` + +### scenario: StringShouldBeNullOrEmpty + +```cs +// arrange +var actual = string.Empty; + +// old assertion: +string.IsNullOrEmpty(actual).Should().BeTrue(); + +// new assertion: +actual.Should().BeNullOrEmpty(); +``` + +#### Failure messages + +```cs +// 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 or empty, but found "actual". +``` + +### scenario: StringShouldBeNullOrWhiteSpace + +```cs +// arrange +var actual = string.Empty; + +// old assertion: +string.IsNullOrWhiteSpace(actual).Should().BeTrue(); + +// new assertion: +actual.Should().BeNullOrWhiteSpace(); +``` + +#### Failure messages + +```cs +// 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 or whitespace, but found "actual". +``` + +### scenario: StringShouldNotBeNullOrWhiteSpace + +```cs +// arrange +var actual = "actual"; + +// old assertion: +string.IsNullOrWhiteSpace(actual).Should().BeFalse(); + +// new assertion: +actual.Should().NotBeNullOrWhiteSpace(); +``` + +#### Failure messages + +```cs +// 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 or whitespace, but found "". +``` + +### scenario: StringShouldHaveLength + +```cs +// arrange +var actual = "actual"; +var expected = 6; + +// old assertion: +actual.Length.Should().Be(expected); + +// new assertion: +actual.Should().HaveLength(expected); +``` + +#### Failure messages + +```cs +// 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 ```cs @@ -64,7 +263,7 @@ collection.Should().NotBeEmpty(); var collection = new List { }; // old assertion: -collection.Any().Should().BeTrue(); // fail message: Expected collection.Any() to be true, but found False. +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. @@ -93,13 +292,13 @@ collection.Should().BeEmpty(); var collection = new List { 1, 2, 3 }; // old assertion: -collection.Any().Should().BeFalse(); // fail message: Expected collection.Any() to be false, but found True. +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 {1, 2, 3}. +collection.Should().BeEmpty(); // fail message: Expected collection to be empty, but found at least one item {1}. ``` ### scenario: CollectionShouldNotContainCondition @@ -123,8 +322,8 @@ collection.Should().NotContain(i => i == 4); var collection = new List { 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 {4}. +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}. @@ -150,7 +349,7 @@ collection.Should().NotContain(4); var collection = new List { 1, 2, 3, 4, 5 }; // old assertion: -collection.Contains(4).Should().BeFalse(); // fail message: Expected collection.Contains(4) to be false, but found True. +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. @@ -176,7 +375,7 @@ collection.Should().OnlyContain(x => x > 0); var collection = new List { 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. +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. @@ -202,7 +401,7 @@ collection.Should().Contain(2); var collection = new List { 1, 3, 4, 5 }; // old assertion: -collection.Contains(2).Should().BeTrue(); // fail message: Expected collection.Contains(2) to be true, but found False. +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. @@ -229,7 +428,7 @@ collection.Should().Contain(i => i == 2); var collection = new List { 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.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: @@ -580,7 +779,7 @@ dictionary.Should().ContainKey("two"); var dictionary = new Dictionary { ["one"] = 1, ["three"] = 3 }; // old assertion: -dictionary.ContainsKey("two").Should().BeTrue(); // fail message: Expected dictionary.ContainsKey("two") to be true, but found False. +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". @@ -606,7 +805,7 @@ dictionary.Should().NotContainKey("four"); var dictionary = new Dictionary { ["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. +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. @@ -632,7 +831,7 @@ dictionary.Should().ContainValue(2); var dictionary = new Dictionary { ["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. +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. @@ -658,7 +857,7 @@ dictionary.Should().NotContainValue(4); var dictionary = new Dictionary { ["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. +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. diff --git a/docs/MsTestAnalyzer.md b/docs/MsTestAnalyzer.md index d32c4b7..2b7410f 100644 --- a/docs/MsTestAnalyzer.md +++ b/docs/MsTestAnalyzer.md @@ -70,7 +70,7 @@ var flag = false; Assert.IsTrue(flag); /* fail message: Assert.IsTrue failed. */ // new assertion: -flag.Should().BeTrue(); /* fail message: Expected flag to be true, but found False. */ +flag.Should().BeTrue(); /* fail message: Expected flag to be True, but found False. */ ``` ### scenario: AssertIsFalse @@ -95,7 +95,7 @@ var flag = true; Assert.IsFalse(flag); /* fail message: Assert.IsFalse failed. */ // new assertion: -flag.Should().BeFalse(); /* fail message: Expected flag to be false, but found True. */ +flag.Should().BeFalse(); /* fail message: Expected flag to be False, but found True. */ ``` ### scenario: AssertIsNull @@ -974,10 +974,7 @@ static void ThrowException() => throw new InvalidOperationException(); Action action = ThrowException; // old assertion: -Assert.ThrowsException(action); /* fail message: Assert.ThrowsException failed. Threw exception InvalidOperationException, but exception ArgumentException was expected. -Exception Message: Operation is not valid due to the current state of the object. -Stack Trace: at FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.MsTestAnalyzerTests.g__ThrowException|109_0() in /Users/runner/work/fluentassertions.analyzers/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/MsTestAnalyzerTests.cs:line 1298 - at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) */ +Assert.ThrowsException(action); /* fail message: Assert.ThrowsException failed. Expected exception type:. Actual exception type:. */ // new assertion: action.Should().ThrowExactly(); /* fail message: Expected type to be System.ArgumentException, but found System.InvalidOperationException. */ @@ -1004,10 +1001,7 @@ static Task ThrowExceptionAsync() => throw new InvalidOperationException(); Func action = ThrowExceptionAsync; // old assertion: -await Assert.ThrowsExceptionAsync(action); /* fail message: Assert.ThrowsException failed. Threw exception InvalidOperationException, but exception ArgumentException was expected. -Exception Message: Operation is not valid due to the current state of the object. -Stack Trace: at FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.MsTestAnalyzerTests.g__ThrowExceptionAsync|112_0() in /Users/runner/work/fluentassertions.analyzers/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/MsTestAnalyzerTests.cs:line 1334 - at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExceptionAsync[T](Func`1 action, String message, Object[] parameters) */ +await Assert.ThrowsExceptionAsync(action); /* fail message: Assert.ThrowsException failed. Expected exception type:. Actual exception type:. */ // new assertion: await action.Should().ThrowExactlyAsync(); /* fail message: Expected type to be System.ArgumentException, but found System.InvalidOperationException. */ diff --git a/docs/Nunit3Analyzer.md b/docs/Nunit3Analyzer.md index 40c94cb..c27769c 100644 --- a/docs/Nunit3Analyzer.md +++ b/docs/Nunit3Analyzer.md @@ -72,7 +72,7 @@ Assert.That(flag, Is.Not.False); /* fail message: Expected: not False */ // new assertion: -flag.Should().BeTrue(); /* fail message: Expected flag to be true, but found False. */ +flag.Should().BeTrue(); /* fail message: Expected flag to be True, but found False. */ ``` ### scenario: AssertIsFalse @@ -111,7 +111,7 @@ Assert.That(flag, Is.Not.True); /* fail message: Expected: not True */ // new assertion: -flag.Should().BeFalse(); /* fail message: Expected flag to be false, but found True. */ +flag.Should().BeFalse(); /* fail message: Expected flag to be False, but found True. */ ``` ### scenario: AssertNull @@ -224,7 +224,7 @@ CollectionAssert.IsEmpty(collection); /* fail message: Expected: */ // new assertion: -collection.Should().BeEmpty(); /* fail message: Expected collection to be empty, but found {1, 2, 3}. */ +collection.Should().BeEmpty(); /* fail message: Expected collection to be empty, but found at least one item {1}. */ ``` ### scenario: AssertIsNotEmpty diff --git a/docs/Nunit4Analyzer.md b/docs/Nunit4Analyzer.md index 101f196..1f4cbbd 100644 --- a/docs/Nunit4Analyzer.md +++ b/docs/Nunit4Analyzer.md @@ -77,7 +77,7 @@ Assert.That(flag, Is.Not.False); /* fail message: Assert.That(flag, Is.Not.Fal */ // new assertion: -flag.Should().BeTrue(); /* fail message: Expected flag to be true, but found False. */ +flag.Should().BeTrue(); /* fail message: Expected flag to be True, but found False. */ ``` ### scenario: AssertIsFalse @@ -120,7 +120,7 @@ Assert.That(flag, Is.Not.True); /* fail message: Assert.That(flag, Is.Not.True */ // new assertion: -flag.Should().BeFalse(); /* fail message: Expected flag to be false, but found True. */ +flag.Should().BeFalse(); /* fail message: Expected flag to be False, but found True. */ ``` ### scenario: AssertNull @@ -244,7 +244,7 @@ CollectionAssert.IsEmpty(collection); /* fail message: Assert.That(collection, */ // new assertion: -collection.Should().BeEmpty(); /* fail message: Expected collection to be empty, but found {1, 2, 3}. */ +collection.Should().BeEmpty(); /* fail message: Expected collection to be empty, but found at least one item {1}. */ ``` ### scenario: AssertIsNotEmpty diff --git a/docs/XunitAnalyzer.md b/docs/XunitAnalyzer.md index 8c44ad9..6a62c73 100644 --- a/docs/XunitAnalyzer.md +++ b/docs/XunitAnalyzer.md @@ -44,7 +44,7 @@ Expected: True Actual: False */ // new assertion: -flag.Should().BeTrue(); /* fail message: Expected flag to be true, but found False. */ +flag.Should().BeTrue(); /* fail message: Expected flag to be True, but found False. */ ``` ### scenario: AssertFalse @@ -71,7 +71,7 @@ Expected: False Actual: True */ // new assertion: -flag.Should().BeFalse(); /* fail message: Expected flag to be false, but found True. */ +flag.Should().BeFalse(); /* fail message: Expected flag to be False, but found True. */ ``` ### scenario: AssertSame @@ -95,9 +95,9 @@ object obj1 = 6; object obj2 = "foo"; // old assertion: -Assert.Same(obj1, obj2); /* fail message: Assert.Same() Failure +Assert.Same(obj1, obj2); /* fail message: Assert.Same() Failure: Values are not the same instance Expected: 6 -Actual: foo */ +Actual: "foo" */ // new assertion: obj1.Should().BeSameAs(obj2); /* fail message: Expected obj1 to refer to "foo", but found 6. */ @@ -124,7 +124,7 @@ object obj1 = "foo"; object obj2 = "foo"; // old assertion: -Assert.NotSame(obj1, obj2); /* fail message: Assert.NotSame() Failure */ +Assert.NotSame(obj1, obj2); /* fail message: Assert.NotSame() Failure: Values are the same instance */ // new assertion: obj1.Should().NotBeSameAs(obj2); /* fail message: Did not expect obj1 to refer to "foo". */ @@ -153,7 +153,7 @@ double expected = 4.2; double tolerance = 0.0001; // old assertion: -Assert.Equal(expected, actual, tolerance); /* fail message: Assert.Equal() Failure +Assert.Equal(expected, actual, tolerance); /* fail message: Assert.Equal() Failure: Values are not within tolerance 0.0001 Expected: 4.2000000000000002 Actual: 3.1400000000000001 */ @@ -182,9 +182,9 @@ var actual = new DateTime(2021, 1, 1); var expected = new DateTime(2021, 1, 2); // old assertion: -Assert.Equal(expected, actual, TimeSpan.FromHours(3)); /* fail message: Assert.Equal() Failure -Expected: 1/2/2021 12:00:00 AM -Actual: 1/1/2021 12:00:00 AM difference 1.00:00:00 is larger than 03:00:00 */ +Assert.Equal(expected, actual, TimeSpan.FromHours(3)); /* fail message: Assert.Equal() Failure: Values differ +Expected: 2021-01-02T00:00:00.0000000 +Actual: 2021-01-01T00:00:00.0000000 (difference 1.00:00:00 is larger than 03:00:00) */ // new assertion: actual.Should().BeCloseTo(expected, TimeSpan.FromHours(3)); /* fail message: Expected actual to be within 3h from <2021-01-02>, but <2021-01-01> was off by 1d. */ @@ -211,7 +211,7 @@ object actual = "foo"; object expected = 6; // old assertion: -Assert.Equal(expected, actual); /* fail message: Assert.Equal() Failure +Assert.Equal(expected, actual); /* fail message: Assert.Equal() Failure: Values differ Expected: 6 Actual: foo */ @@ -240,7 +240,7 @@ object actual = "foo"; object expected = 6; // old assertion: -Assert.Equal(expected, actual, EqualityComparer.Default); /* fail message: Assert.Equal() Failure +Assert.Equal(expected, actual, EqualityComparer.Default); /* fail message: Assert.Equal() Failure: Values differ Expected: 6 Actual: foo */ @@ -282,9 +282,9 @@ object actual = "foo"; object expected = "foo"; // old assertion: -Assert.NotEqual(expected, actual); /* fail message: Assert.NotEqual() Failure +Assert.NotEqual(expected, actual); /* fail message: Assert.NotEqual() Failure: Strings are equal Expected: Not "foo" -Actual: "foo" */ +Actual: "foo" */ // new assertion: actual.Should().NotBe(expected); /* fail message: Did not expect actual to be equal to "foo". */ @@ -311,9 +311,9 @@ object actual = "foo"; object expected = "foo"; // old assertion: -Assert.NotEqual(expected, actual, EqualityComparer.Default); /* fail message: Assert.NotEqual() Failure +Assert.NotEqual(expected, actual, EqualityComparer.Default); /* fail message: Assert.NotEqual() Failure: Strings are equal Expected: Not "foo" -Actual: "foo" */ +Actual: "foo" */ // new assertion: actual.Should().NotBeEquivalentTo(expected, options => options.Using(EqualityComparer.Default)); /* fail message: Expected actual not to be equivalent to "foo", but they are. */ @@ -340,9 +340,9 @@ object actual = "foo"; object expected = 6; // old assertion: -Assert.StrictEqual(expected, actual); /* fail message: Assert.Equal() Failure +Assert.StrictEqual(expected, actual); /* fail message: Assert.StrictEqual() Failure: Values differ Expected: 6 -Actual: foo */ +Actual: "foo" */ // new assertion: actual.Should().Be(expected); /* fail message: Expected actual to be 6, but found "foo". */ @@ -369,9 +369,9 @@ object actual = "foo"; object expected = "foo"; // old assertion: -Assert.NotStrictEqual(expected, actual); /* fail message: Assert.NotEqual() Failure +Assert.NotStrictEqual(expected, actual); /* fail message: Assert.NotStrictEqual() Failure: Values are equal Expected: Not "foo" -Actual: "foo" */ +Actual: "foo" */ // new assertion: actual.Should().NotBe(expected); /* fail message: Did not expect actual to be equal to "foo". */ diff --git a/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/FluentAssertionsAnalyzerTests.cs b/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/FluentAssertionsAnalyzerTests.cs index fa8244b..3f08b09 100644 --- a/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/FluentAssertionsAnalyzerTests.cs +++ b/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/FluentAssertionsAnalyzerTests.cs @@ -9,6 +9,205 @@ namespace FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs; [TestClass] public class FluentAssertionsAnalyzerTests { + [TestMethod] + public void StringShouldStartWith() + { + // arrange + var actual = "actual"; + var expected = "act"; + + // old assertion: + actual.StartsWith(expected).Should().BeTrue(); + + // new assertion: + actual.Should().StartWith(expected); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldStartWith_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = "actual"; + var expected = "wrong"; + + // old assertion: + actual.StartsWith(expected).Should().BeTrue(); + + // new assertion: + actual.Should().StartWith(expected); + } + + [TestMethod] + public void StringShouldEndWith() + { + // arrange + var actual = "actual"; + var expected = "ual"; + + // old assertion: + actual.EndsWith(expected).Should().BeTrue(); + + // new assertion: + actual.Should().EndWith(expected); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldEndWith_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = "actual"; + var expected = "wrong"; + + // old assertion: + actual.EndsWith(expected).Should().BeTrue(); + + // new assertion: + actual.Should().EndWith(expected); + } + + [TestMethod] + public void 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(); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldNotBeNullOrEmpty_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = string.Empty; + + // old assertion: + string.IsNullOrEmpty(actual).Should().BeFalse(); + actual.Should().NotBeNull().And.NotBeEmpty(); + actual.Should().NotBeEmpty().And.NotBeNull(); + + // new assertion: + actual.Should().NotBeNullOrEmpty(); + } + + [TestMethod] + public void StringShouldBeNullOrEmpty() + { + // arrange + var actual = string.Empty; + + // old assertion: + string.IsNullOrEmpty(actual).Should().BeTrue(); + + // new assertion: + actual.Should().BeNullOrEmpty(); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldBeNullOrEmpty_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = "actual"; + + // old assertion: + string.IsNullOrEmpty(actual).Should().BeTrue(); + + // new assertion: + actual.Should().BeNullOrEmpty(); + } + + [TestMethod] + public void StringShouldBeNullOrWhiteSpace() + { + // arrange + var actual = string.Empty; + + // old assertion: + string.IsNullOrWhiteSpace(actual).Should().BeTrue(); + + // new assertion: + actual.Should().BeNullOrWhiteSpace(); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldBeNullOrWhiteSpace_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = "actual"; + + // old assertion: + string.IsNullOrWhiteSpace(actual).Should().BeTrue(); + + // new assertion: + actual.Should().BeNullOrWhiteSpace(); + } + + [TestMethod] + public void StringShouldNotBeNullOrWhiteSpace() + { + // arrange + var actual = "actual"; + + // old assertion: + string.IsNullOrWhiteSpace(actual).Should().BeFalse(); + + // new assertion: + actual.Should().NotBeNullOrWhiteSpace(); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldNotBeNullOrWhiteSpace_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = string.Empty; + + // old assertion: + string.IsNullOrWhiteSpace(actual).Should().BeFalse(); + + // new assertion: + actual.Should().NotBeNullOrWhiteSpace(); + } + + [TestMethod] + public void StringShouldHaveLength() + { + // arrange + var actual = "actual"; + var expected = 6; + + // old assertion: + actual.Length.Should().Be(expected); + + // new assertion: + actual.Should().HaveLength(expected); + } + + [TestMethod, ExpectedException(typeof(AssertFailedException))] + public void StringShouldHaveLength_Failure() + { + using var scope = new AssertionScope(); + // arrange + var actual = "actual"; + var expected = 5; + + // old assertion: + actual.Length.Should().Be(expected); + + // new assertion: + actual.Should().HaveLength(expected); + } + [TestMethod] public void CollectionShouldNotBeEmpty() {