Skip to content

feat: add nunit collection Assert.That All InstanceOf #362

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 29, 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
30 changes: 30 additions & 0 deletions docs/Nunit3Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ var collection = new object[] { 1, 2, 3 };

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
Assert.That(collection, Is.All.InstanceOf(typeof(int)));
Assert.That(collection, Is.All.InstanceOf<int>());
Assert.That(collection, Has.All.InstanceOf(typeof(int)));
Assert.That(collection, Has.All.InstanceOf<int>());

// new assertion:
collection.Should().AllBeOfType<int>();
Expand All @@ -734,6 +738,22 @@ CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int)); /* fail me
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Is.All.InstanceOf(typeof(int))); /* fail message: Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Is.All.InstanceOf<int>()); /* fail message: Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Has.All.InstanceOf(typeof(int))); /* fail message: Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Has.All.InstanceOf<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]". */
Expand All @@ -748,6 +768,8 @@ var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
Assert.That(collection, Is.All.InstanceOf(type));
Assert.That(collection, Has.All.InstanceOf(type));

// new assertion:
collection.Should().AllBeOfType(type);
Expand All @@ -764,6 +786,14 @@ CollectionAssert.AllItemsAreInstancesOfType(collection, type); /* fail message:
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Is.All.InstanceOf(type)); /* fail message: Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Has.All.InstanceOf(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]". */
Expand Down
36 changes: 36 additions & 0 deletions docs/Nunit4Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ var collection = new object[] { 1, 2, 3 };

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
Assert.That(collection, Is.All.InstanceOf(typeof(int)));
Assert.That(collection, Is.All.InstanceOf<int>());
Assert.That(collection, Has.All.InstanceOf(typeof(int)));
Assert.That(collection, Has.All.InstanceOf<int>());

// new assertion:
collection.Should().AllBeOfType<int>();
Expand All @@ -812,6 +816,26 @@ CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int)); /* fail me
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Is.All.InstanceOf(typeof(int))); /* fail message: Assert.That(collection, Is.All.InstanceOf(typeof(int)))
Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Is.All.InstanceOf<int>()); /* fail message: Assert.That(collection, Is.All.InstanceOf<int>())
Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Has.All.InstanceOf(typeof(int))); /* fail message: Assert.That(collection, Has.All.InstanceOf(typeof(int)))
Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Has.All.InstanceOf<int>()); /* fail message: Assert.That(collection, Has.All.InstanceOf<int>())
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]". */
Expand All @@ -826,6 +850,8 @@ var type = typeof(int);

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
Assert.That(collection, Is.All.InstanceOf(type));
Assert.That(collection, Has.All.InstanceOf(type));

// new assertion:
collection.Should().AllBeOfType(type);
Expand All @@ -843,6 +869,16 @@ CollectionAssert.AllItemsAreInstancesOfType(collection, type); /* fail message:
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Is.All.InstanceOf(type)); /* fail message: Assert.That(collection, Is.All.InstanceOf(type))
Expected: all items instance of <System.Int32>
But was: < 1, 2, "3" >
First non-matching item at index [2]: "3"
*/
Assert.That(collection, Has.All.InstanceOf(type)); /* fail message: Assert.That(collection, Has.All.InstanceOf(type))
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]". */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
var obj2 = obj1;

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

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

// new assertion:
obj1.Should().BeSameAs(obj2);
Expand All @@ -524,7 +524,7 @@
object obj2 = "foo";

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

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)
}

[Test, ExpectedAssertionException]
Expand All @@ -546,7 +546,7 @@
object obj2 = "foo";

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

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

// new assertion:
obj1.Should().NotBeSameAs(obj2);
Expand All @@ -560,7 +560,7 @@
var obj2 = "foo";

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

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)
}

[Test, ExpectedAssertionException]
Expand Down Expand Up @@ -1087,13 +1087,17 @@

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
Assert.That(collection, Is.All.InstanceOf(typeof(int)));
Assert.That(collection, Is.All.InstanceOf<int>());
Assert.That(collection, Has.All.InstanceOf(typeof(int)));
Assert.That(collection, Has.All.InstanceOf<int>());

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

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_Failure_OldAssertion()
public void CollectionAssertAllItemsAreInstancesOfType_Failure_OldAssertion_0()
{
// arrange
var collection = new object[] { 1, 2, "3" };
Expand All @@ -1102,6 +1106,46 @@
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
}

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

// old assertion:
Assert.That(collection, Is.All.InstanceOf(typeof(int)));
}

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

// old assertion:
Assert.That(collection, Is.All.InstanceOf<int>());
}

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

// old assertion:
Assert.That(collection, Has.All.InstanceOf(typeof(int)));
}

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

// old assertion:
Assert.That(collection, Has.All.InstanceOf<int>());
}

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_Failure_NewAssertion()
{
Expand All @@ -1121,13 +1165,15 @@

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
Assert.That(collection, Is.All.InstanceOf(type));
Assert.That(collection, Has.All.InstanceOf(type));

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

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_OldAssertion()
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_OldAssertion_0()
{
// arrange
var collection = new object[] { 1, 2, "3" };
Expand All @@ -1137,6 +1183,28 @@
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
}

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

// old assertion:
Assert.That(collection, Is.All.InstanceOf(type));
}

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

// old assertion:
Assert.That(collection, Has.All.InstanceOf(type));
}

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_NewAssertion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ public void CollectionAssertDoesNotContain_WithCasting_Failure_NewAssertion()
collection.Should().NotContain((int)item);
}


[Test]
public void CollectionAssertAllItemsAreInstancesOfType()
{
Expand All @@ -1107,13 +1108,17 @@ public void CollectionAssertAllItemsAreInstancesOfType()

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
Assert.That(collection, Is.All.InstanceOf(typeof(int)));
Assert.That(collection, Is.All.InstanceOf<int>());
Assert.That(collection, Has.All.InstanceOf(typeof(int)));
Assert.That(collection, Has.All.InstanceOf<int>());

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

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_Failure_OldAssertion()
public void CollectionAssertAllItemsAreInstancesOfType_Failure_OldAssertion_0()
{
// arrange
var collection = new object[] { 1, 2, "3" };
Expand All @@ -1122,6 +1127,46 @@ public void CollectionAssertAllItemsAreInstancesOfType_Failure_OldAssertion()
CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(int));
}

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

// old assertion:
Assert.That(collection, Is.All.InstanceOf(typeof(int)));
}

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

// old assertion:
Assert.That(collection, Is.All.InstanceOf<int>());
}

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

// old assertion:
Assert.That(collection, Has.All.InstanceOf(typeof(int)));
}

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

// old assertion:
Assert.That(collection, Has.All.InstanceOf<int>());
}

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_Failure_NewAssertion()
{
Expand All @@ -1141,13 +1186,15 @@ public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument()

// old assertion:
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
Assert.That(collection, Is.All.InstanceOf(type));
Assert.That(collection, Has.All.InstanceOf(type));

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

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_OldAssertion()
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_OldAssertion_0()
{
// arrange
var collection = new object[] { 1, 2, "3" };
Expand All @@ -1157,6 +1204,28 @@ public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_
CollectionAssert.AllItemsAreInstancesOfType(collection, type);
}

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

// old assertion:
Assert.That(collection, Is.All.InstanceOf(type));
}

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

// old assertion:
Assert.That(collection, Has.All.InstanceOf(type));
}

[Test, ExpectedAssertionException]
public void CollectionAssertAllItemsAreInstancesOfType_WithTypeArgument_Failure_NewAssertion()
{
Expand Down
Loading
Loading