Skip to content

Commit

Permalink
feat: add nunit assert AreNotSame (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meir017 authored May 20, 2024
1 parent db3aeac commit 1e6ed50
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 8 deletions.
60 changes: 60 additions & 0 deletions docs/Nunit3Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
- [AssertIsNotEmpty](#scenario-assertisnotempty) - `collection.Should().NotBeEmpty();`
- [AssertZero](#scenario-assertzero) - `number.Should().Be(0);`
- [AssertNotZero](#scenario-assertnotzero) - `number.Should().NotBe(0);`
- [AssertAreSame](#scenario-assertaresame) - `obj1.Should().BeSameAs(obj2);`
- [AssertAreNotSame](#scenario-assertarenotsame) - `obj1.Should().NotBeSameAs(obj2);`
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`
- [CollectionAssertContains](#scenario-collectionassertcontains) - `collection.Should().Contain(2);`
Expand Down Expand Up @@ -308,6 +310,64 @@ Assert.That(number, Is.Not.Zero); /* fail message: Expected: not equal to 0
number.Should().NotBe(0); /* fail message: Did not expect number to be 0. */
```

### scenario: AssertAreSame

```cs
// arrange
var obj1 = new object();
var obj2 = obj1;

// old assertion:
Assert.AreSame(obj1, obj2);

// new assertion:
obj1.Should().BeSameAs(obj2);
```

#### Failure messages

```cs
object obj1 = 6;
object obj2 = "foo";

// old assertion:
Assert.AreSame(obj1, obj2); /* fail message: Expected: same as 6
But was: "foo"
*/

// new assertion:
obj1.Should().BeSameAs(obj2); /* fail message: Expected obj1 to refer to "foo", but found 6. */
```

### scenario: AssertAreNotSame

```cs
// arrange
object obj1 = 6;
object obj2 = "foo";

// old assertion:
Assert.AreNotSame(obj1, obj2);

// new assertion:
obj1.Should().NotBeSameAs(obj2);
```

#### Failure messages

```cs
var obj1 = "foo";
var obj2 = "foo";

// old assertion:
Assert.AreNotSame(obj1, obj2); /* fail message: Expected: not same as "foo"
But was: "foo"
*/

// new assertion:
obj1.Should().NotBeSameAs(obj2); /* fail message: Did not expect obj1 to refer to "foo". */
```

### scenario: CollectionAssertAreEqual

```cs
Expand Down
64 changes: 63 additions & 1 deletion docs/Nunit4Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
- [AssertIsNotEmpty](#scenario-assertisnotempty) - `collection.Should().NotBeEmpty();`
- [AssertZero](#scenario-assertzero) - `number.Should().Be(0);`
- [AssertNotZero](#scenario-assertnotzero) - `number.Should().NotBe(0);`
- [AssertAreSame](#scenario-assertaresame) - `obj1.Should().BeSameAs(obj2);`
- [AssertAreNotSame](#scenario-assertarenotsame) - `obj1.Should().NotBeSameAs(obj2);`
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`
- [CollectionAssertContains](#scenario-collectionassertcontains) - `collection.Should().Contain(2);`
Expand Down Expand Up @@ -333,12 +335,72 @@ Assert.That(number, Is.Not.Zero); /* fail message: Assert.That(number, Is.Not.
number.Should().NotBe(0); /* fail message: Did not expect number to be 0. */
```

### scenario: AssertAreSame

```cs
// arrange
var obj1 = new object();
var obj2 = obj1;

// old assertion:
ClassicAssert.AreSame(obj1, obj2);

// new assertion:
obj1.Should().BeSameAs(obj2);
```

#### Failure messages

```cs
object obj1 = 6;
object obj2 = "foo";

// old assertion:
ClassicAssert.AreSame(obj1, obj2); /* fail message: Assert.That(actual, Is.SameAs(expected))
Expected: same as 6
But was: "foo"
*/

// new assertion:
obj1.Should().BeSameAs(obj2); /* fail message: Expected obj1 to refer to "foo", but found 6. */
```

### scenario: AssertAreNotSame

```cs
// arrange
object obj1 = 6;
object obj2 = "foo";

// old assertion:
ClassicAssert.AreNotSame(obj1, obj2);

// new assertion:
obj1.Should().NotBeSameAs(obj2);
```

#### Failure messages

```cs
var obj1 = new object();
var obj2 = obj1;

// old assertion:
ClassicAssert.AreNotSame(obj1, obj2); /* fail message: Assert.That(actual, Is.Not.SameAs(expected))
Expected: not same as <System.Object>
But was: <System.Object>
*/

// new assertion:
obj1.Should().NotBeSameAs(obj2); /* fail message: Did not expect obj1 to refer to System.Object (HashCode=2766117). */
```

### scenario: CollectionAssertAreEqual

```cs
// arrange
var collection = new[] { 1, 2, 3 };
var expected = new [] { 1, 2, 3 };
var expected = new[] { 1, 2, 3 };

// old assertion:
CollectionAssert.AreEqual(expected, collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void AssertIsNotEmpty_Failure_OldAssertion_2()

// old assertion:
CollectionAssert.IsNotEmpty(collection);
}
}

[Test, ExpectedAssertionException]
public void AssertIsNotEmpty_Failure_NewAssertion()
Expand Down Expand Up @@ -458,12 +458,84 @@ public void AssertNotZero_Failure_NewAssertion()
number.Should().NotBe(0);
}

[Test]
public void AssertAreSame()
{
// arrange
var obj1 = new object();
var obj2 = obj1;

// old assertion:
ClassicAssert.AreSame(obj1, obj2);

// new assertion:
obj1.Should().BeSameAs(obj2);
}

[Test, ExpectedAssertionException]
public void AssertAreSame_Failure_OldAssertion()
{
// arrange
object obj1 = 6;
object obj2 = "foo";

// old assertion:
ClassicAssert.AreSame(obj1, obj2);
}

[Test, ExpectedAssertionException]
public void AssertAreSame_Failure_NewAssertion()
{
// arrange
object obj1 = 6;
object obj2 = "foo";

// new assertion:
obj1.Should().BeSameAs(obj2);
}

[Test]
public void AssertAreNotSame()
{
// arrange
object obj1 = 6;
object obj2 = "foo";

// old assertion:
ClassicAssert.AreNotSame(obj1, obj2);

// new assertion:
obj1.Should().NotBeSameAs(obj2);
}

[Test, ExpectedAssertionException]
public void AssertAreNotSame_Failure_OldAssertion()
{
// arrange
var obj1 = new object();
var obj2 = obj1;

// old assertion:
ClassicAssert.AreNotSame(obj1, obj2);
}

[Test, ExpectedAssertionException]
public void AssertAreNotSame_Failure_NewAssertion()
{
// arrange
var obj1 = new object();
var obj2 = obj1;

// new assertion:
obj1.Should().NotBeSameAs(obj2);
}

[Test]
public void CollectionAssertAreEqual()
{
// arrange
var collection = new[] { 1, 2, 3 };
var expected = new [] { 1, 2, 3 };
var expected = new[] { 1, 2, 3 };

// old assertion:
CollectionAssert.AreEqual(expected, collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void AssertIsNotEmpty_Failure_OldAssertion_2()

// old assertion:
CollectionAssert.IsNotEmpty(collection);
}
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertIsNotEmpty_Failure_NewAssertion()
Expand Down Expand Up @@ -461,6 +461,78 @@ public void AssertNotZero_Failure_NewAssertion()
number.Should().NotBe(0);
}

[TestMethod]
public void AssertAreSame()
{
// arrange
var obj1 = new object();
var obj2 = obj1;

// old assertion:
Assert.AreSame(obj1, obj2);

// new assertion:
obj1.Should().BeSameAs(obj2);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertAreSame_Failure_OldAssertion()
{
// arrange
object obj1 = 6;
object obj2 = "foo";

// old assertion:
Assert.AreSame(obj1, obj2);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertAreSame_Failure_NewAssertion()
{
// arrange
object obj1 = 6;
object obj2 = "foo";

// new assertion:
obj1.Should().BeSameAs(obj2);
}

[TestMethod]
public void AssertAreNotSame()
{
// arrange
object obj1 = 6;
object obj2 = "foo";

// old assertion:
Assert.AreNotSame(obj1, obj2);

// new assertion:
obj1.Should().NotBeSameAs(obj2);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertAreNotSame_Failure_OldAssertion()
{
// arrange
var obj1 = "foo";
var obj2 = "foo";

// old assertion:
Assert.AreNotSame(obj1, obj2);
}

[TestMethod, ExpectedTestFrameworkException]
public void AssertAreNotSame_Failure_NewAssertion()
{
// arrange
var obj1 = "foo";
var obj2 = "foo";

// new assertion:
obj1.Should().NotBeSameAs(obj2);
}

[TestMethod]
public void CollectionAssertAreEqual()
{
Expand Down
Loading

0 comments on commit 1e6ed50

Please sign in to comment.