Skip to content

Commit

Permalink
feat: add nunit collection assert AreEqual (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meir017 authored May 19, 2024
1 parent d652dfa commit bf7a559
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 0 deletions.
62 changes: 62 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);`
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`


## Scenarios
Expand Down Expand Up @@ -300,4 +302,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: CollectionAssertAreEqual

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

// old assertion:
CollectionAssert.AreEqual(expected, collection);

// new assertion:
collection.Should().Equal(expected);
```

#### Failure messages

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

// old assertion:
CollectionAssert.AreEqual(expected, collection); /* fail message: Expected and actual are both <System.Int32[3]>
Values differ at index [2]
Expected: 4
But was: 3
*/

// new assertion:
collection.Should().Equal(expected); /* fail message: Expected collection to be equal to {1, 2, 4}, but {1, 2, 3} differs at index 2. */
```

### scenario: CollectionAssertAreNotEqual

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection);

// new assertion:
collection.Should().NotEqual(expected);
```

#### Failure messages

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection); /* fail message: Expected: not equal to < 1, 2, 3 >
But was: < 1, 2, 3 >
*/

// new assertion:
collection.Should().NotEqual(expected); /* fail message: Did not expect collections {1, 2, 3} and {1, 2, 3} to be equal. */
```


64 changes: 64 additions & 0 deletions 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);`
- [CollectionAssertAreEqual](#scenario-collectionassertareequal) - `collection.Should().Equal(expected);`
- [CollectionAssertAreNotEqual](#scenario-collectionassertarenotequal) - `collection.Should().NotEqual(expected);`


## Scenarios
Expand Down Expand Up @@ -325,4 +327,66 @@ 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: CollectionAssertAreEqual

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

// old assertion:
CollectionAssert.AreEqual(expected, collection);

// new assertion:
collection.Should().Equal(expected);
```

#### Failure messages

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

// old assertion:
CollectionAssert.AreEqual(expected, collection); /* fail message: Assert.That(actual, Is.EqualTo(expected).AsCollection)
Expected and actual are both <System.Int32[3]>
Values differ at index [2]
Expected: 4
But was: 3
*/

// new assertion:
collection.Should().Equal(expected); /* fail message: Expected collection to be equal to {1, 2, 4}, but {1, 2, 3} differs at index 2. */
```

### scenario: CollectionAssertAreNotEqual

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection);

// new assertion:
collection.Should().NotEqual(expected);
```

#### Failure messages

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection); /* fail message: Assert.That(actual, Is.Not.EqualTo(expected).AsCollection)
Expected: not equal to < 1, 2, 3 >
But was: < 1, 2, 3 >
*/

// new assertion:
collection.Should().NotEqual(expected); /* fail message: Did not expect collections {1, 2, 3} and {1, 2, 3} to be equal. */
```


Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,76 @@ public void AssertNotZero_Failure_NewAssertion()
// new assertion:
number.Should().NotBe(0);
}

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

// old assertion:
CollectionAssert.AreEqual(expected, collection);

// new assertion:
collection.Should().Equal(expected);
}

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

// old assertion:
CollectionAssert.AreEqual(expected, collection);
}

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

// new assertion:
collection.Should().Equal(expected);
}

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection);

// new assertion:
collection.Should().NotEqual(expected);
}

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection);
}

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

// new assertion:
collection.Should().NotEqual(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,76 @@ public void AssertNotZero_Failure_NewAssertion()
// new assertion:
number.Should().NotBe(0);
}

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

// old assertion:
CollectionAssert.AreEqual(expected, collection);

// new assertion:
collection.Should().Equal(expected);
}

[TestMethod, ExpectedTestFrameworkException]
public void CollectionAssertAreEqual_Failure_OldAssertion()
{
// arrange
var collection = new[] { 1, 2, 3 };
var expected = new[] { 1, 2, 4 };

// old assertion:
CollectionAssert.AreEqual(expected, collection);
}

[TestMethod, ExpectedTestFrameworkException]
public void CollectionAssertAreEqual_Failure_NewAssertion()
{
// arrange
var collection = new[] { 1, 2, 3 };
var expected = new[] { 1, 2, 4 };

// new assertion:
collection.Should().Equal(expected);
}

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection);

// new assertion:
collection.Should().NotEqual(expected);
}

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

// old assertion:
CollectionAssert.AreNotEqual(expected, collection);
}

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

// new assertion:
collection.Should().NotEqual(expected);
}
}
Loading

0 comments on commit bf7a559

Please sign in to comment.