Skip to content

Commit 1b3cdd4

Browse files
committed
docs: mstest support for AreSame, AreNotSame
1 parent 2d7b3b4 commit 1b3cdd4

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

docs/MsTestAnalyzer.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
2323
- [AssertFloatAreNotEqual](#scenario-assertfloatarenotequal) - `number1.Should().NotBeApproximately(number2, delta);`
2424
- [AssertStringAreNotEqual_CaseSensitive](#scenario-assertstringarenotequal_casesensitive) - `str1.Should().NotBe(str2);`
2525
- [AssertStringAreNotEqual_IgnoreCase](#scenario-assertstringarenotequal_ignorecase) - `str1.Should().NotBeEquivalentTo(str2);`
26+
- [AssertAreSame](#scenario-assertaresame) - `obj1.Should().BeSameAs(obj2);`
27+
- [AssertAreNotSame](#scenario-assertarenotsame) - `obj1.Should().NotBeSameAs(obj2);`
2628

2729

2830
## Scenarios
@@ -552,4 +554,58 @@ Assert.AreNotEqual(str2, str1, ignoreCase: true, culture: CultureInfo.CurrentCul
552554
str1.Should().NotBeEquivalentTo(str2); // fail message: Expected str1 not to be equivalent to "FoO", but they are.
553555
```
554556

557+
### scenario: AssertAreSame
558+
559+
```cs
560+
// arrange
561+
var obj1 = new object();
562+
var obj2 = obj1;
563+
564+
// old assertion:
565+
Assert.AreSame(obj2, obj1);
566+
567+
// new assertion:
568+
obj1.Should().BeSameAs(obj2);
569+
```
570+
571+
#### Failure messages
572+
573+
```cs
574+
object obj1 = 6;
575+
object obj2 = "foo";
576+
577+
// old assertion:
578+
Assert.AreSame(obj2, obj1); // fail message: Assert.AreSame failed.
579+
580+
// new assertion:
581+
obj1.Should().BeSameAs(obj2); // fail message: Expected obj1 to refer to "foo", but found 6.
582+
```
583+
584+
### scenario: AssertAreNotSame
585+
586+
```cs
587+
// arrange
588+
object obj1 = 6;
589+
object obj2 = "foo";
590+
591+
// old assertion:
592+
Assert.AreNotSame(obj2, obj1);
593+
594+
// new assertion:
595+
obj1.Should().NotBeSameAs(obj2);
596+
```
597+
598+
#### Failure messages
599+
600+
```cs
601+
object obj1 = "foo";
602+
object obj2 = "foo";
603+
604+
// old assertion:
605+
Assert.AreNotSame(obj2, obj1); // fail message: Assert.AreNotSame failed.
606+
607+
// new assertion:
608+
obj1.Should().NotBeSameAs(obj2); // fail message: Did not expect obj1 to refer to "foo".
609+
```
610+
555611

src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs/MsTestAnalyzerTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,4 +787,76 @@ public void AssertStringAreNotEqual_IgnoreCase_Failure_NewAssertion()
787787
// new assertion:
788788
str1.Should().NotBeEquivalentTo(str2);
789789
}
790+
791+
[TestMethod]
792+
public void AssertAreSame()
793+
{
794+
// arrange
795+
var obj1 = new object();
796+
var obj2 = obj1;
797+
798+
// old assertion:
799+
Assert.AreSame(obj2, obj1);
800+
801+
// new assertion:
802+
obj1.Should().BeSameAs(obj2);
803+
}
804+
805+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
806+
public void AssertAreSame_Failure_OldAssertion()
807+
{
808+
// arrange
809+
object obj1 = 6;
810+
object obj2 = "foo";
811+
812+
// old assertion:
813+
Assert.AreSame(obj2, obj1);
814+
}
815+
816+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
817+
public void AssertAreSame_Failure_NewAssertion()
818+
{
819+
// arrange
820+
object obj1 = 6;
821+
object obj2 = "foo";
822+
823+
// new assertion:
824+
obj1.Should().BeSameAs(obj2);
825+
}
826+
827+
[TestMethod]
828+
public void AssertAreNotSame()
829+
{
830+
// arrange
831+
object obj1 = 6;
832+
object obj2 = "foo";
833+
834+
// old assertion:
835+
Assert.AreNotSame(obj2, obj1);
836+
837+
// new assertion:
838+
obj1.Should().NotBeSameAs(obj2);
839+
}
840+
841+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
842+
public void AssertAreNotSame_Failure_OldAssertion()
843+
{
844+
// arrange
845+
object obj1 = "foo";
846+
object obj2 = "foo";
847+
848+
// old assertion:
849+
Assert.AreNotSame(obj2, obj1);
850+
}
851+
852+
[TestMethod, ExpectedException(typeof(AssertFailedException))]
853+
public void AssertAreNotSame_Failure_NewAssertion()
854+
{
855+
// arrange
856+
object obj1 = "foo";
857+
object obj2 = "foo";
858+
859+
// new assertion:
860+
obj1.Should().NotBeSameAs(obj2);
861+
}
790862
}

0 commit comments

Comments
 (0)