Skip to content

feat: add nunit collection assert AllItemsAreInstancesOfType #349

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

Merged
merged 1 commit into from
May 20, 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
60 changes: 60 additions & 0 deletions docs/Nunit3Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
- [CollectionAssertContains_WithCasting](#scenario-collectionassertcontains_withcasting) - `collection.Should().Contain((int)item);`
- [CollectionAssertDoesNotContain](#scenario-collectionassertdoesnotcontain) - `collection.Should().NotContain(4);`
- [CollectionAssertDoesNotContain_WithCasting](#scenario-collectionassertdoesnotcontain_withcasting) - `collection.Should().NotContain((int)item);`
- [CollectionAssertAllItemsAreInstancesOfType](#scenario-collectionassertallitemsareinstancesoftype) - `collection.Should().AllBeOfType<int>();`
- [CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument](#scenario-collectionassertallitemsareinstancesoftype_withtypeargument) - `collection.Should().AllBeOfType(type);`


## Scenarios
Expand Down Expand Up @@ -478,4 +480,62 @@ CollectionAssert.DoesNotContain(collection, item); /* fail message: Expected:
collection.Should().NotContain((int)item); /* fail message: Expected collection {1, 2, 3} to not contain 2. */
```

### scenario: CollectionAssertAllItemsAreInstancesOfType

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));

// new assertion:
collection.Should().AllBeOfType<int>();
```

#### Failure messages

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int)); /* fail message: Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/

// new assertion:
collection.Should().AllBeOfType<int>(); /* fail message: Expected type to be "System.Int32", but found "[System.Int32, System.Int32, System.String]". */
```

### scenario: CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument

```cs
// arrange
var collection = new object[] { 1, 2, 3 };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);

// new assertion:
collection.Should().AllBeOfType(type);
```

#### Failure messages

```cs
var collection = new object[] { 1, 2, "3" };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type); /* fail message: Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/

// new assertion:
collection.Should().AllBeOfType(type); /* fail message: Expected type to be "System.Int32", but found "[System.Int32, System.Int32, System.String]". */
```


62 changes: 62 additions & 0 deletions docs/Nunit4Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This is a generated file, please edit src\FluentAssertions.Analyzers.FluentAsser
- [CollectionAssertContains_WithCasting](#scenario-collectionassertcontains_withcasting) - `collection.Should().Contain((int)item);`
- [CollectionAssertDoesNotContain](#scenario-collectionassertdoesnotcontain) - `collection.Should().NotContain(4);`
- [CollectionAssertDoesNotContain_WithCasting](#scenario-collectionassertdoesnotcontain_withcasting) - `collection.Should().NotContain((int)item);`
- [CollectionAssertAllItemsAreInstancesOfType](#scenario-collectionassertallitemsareinstancesoftype) - `collection.Should().AllBeOfType<int>();`
- [CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument](#scenario-collectionassertallitemsareinstancesoftype_withtypeargument) - `collection.Should().AllBeOfType(type);`


## Scenarios
Expand Down Expand Up @@ -509,4 +511,64 @@ CollectionAssert.DoesNotContain(collection, item); /* fail message: Assert.Tha
collection.Should().NotContain((int)item); /* fail message: Expected collection {1, 2, 3} to not contain 2. */
```

### scenario: CollectionAssertAllItemsAreInstancesOfType

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));

// new assertion:
collection.Should().AllBeOfType<int>();
```

#### Failure messages

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int)); /* fail message: Assert.That(collection, Is.All.InstanceOf(expectedType))
Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/

// new assertion:
collection.Should().AllBeOfType<int>(); /* fail message: Expected type to be "System.Int32", but found "[System.Int32, System.Int32, System.String]". */
```

### scenario: CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument

```cs
// arrange
var collection = new object[] { 1, 2, 3 };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);

// new assertion:
collection.Should().AllBeOfType(type);
```

#### Failure messages

```cs
var collection = new object[] { 1, 2, "3" };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type); /* fail message: Assert.That(collection, Is.All.InstanceOf(expectedType))
Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/

// new assertion:
collection.Should().AllBeOfType(type); /* fail message: Expected type to be "System.Int32", but found "[System.Int32, System.Int32, System.String]". */
```


Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,73 @@ public void CollectionAssertDoesNotContain_WithCasting_Failure_NewAssertion()
// new assertion:
collection.Should().NotContain((int)item);
}

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));

// new assertion:
collection.Should().AllBeOfType<int>();
}

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
}

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

// new assertion:
collection.Should().AllBeOfType<int>();
}

[Test]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument()
{
// arrange
var collection = new object[] { 1, 2, 3 };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);

// new assertion:
collection.Should().AllBeOfType(type);
}

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_OldAssertion()
{
// arrange
var collection = new object[] { 1, 2, "3" };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
}

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_NewAssertion()
{
// arrange
var collection = new object[] { 1, 2, "3" };
var type = typeof(int);

// new assertion:
collection.Should().AllBeOfType(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,73 @@ public void CollectionAssertDoesNotContain_WithCasting_Failure_NewAssertion()
// new assertion:
collection.Should().NotContain((int)item);
}

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));

// new assertion:
collection.Should().AllBeOfType<int>();
}

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

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
}

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

// new assertion:
collection.Should().AllBeOfType<int>();
}

[TestMethod]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument()
{
// arrange
var collection = new object[] { 1, 2, 3 };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);

// new assertion:
collection.Should().AllBeOfType(type);
}

[TestMethod, ExpectedTestFrameworkException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_OldAssertion()
{
// arrange
var collection = new object[] { 1, 2, "3" };
var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
}

[TestMethod, ExpectedTestFrameworkException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_NewAssertion()
{
// arrange
var collection = new object[] { 1, 2, "3" };
var type = typeof(int);

// new assertion:
collection.Should().AllBeOfType(type);
}
}
Loading