Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nunit collection assert AreEqual #346

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading