-
Notifications
You must be signed in to change notification settings - Fork 1
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
Remaining list of assertion not implemented #4
Comments
IsInstanceOf Are common ones that are missing IsTrue seems to have a bug Assert.IsTrue(actual.Items.Count > 0);
// converts to
actual.Items.Count > 0.ShouldBeTrue(); |
var BoosterPropertyItems = new List<int>();
BoosterPropertyItems.Add(1548);
Assert.NotNull(BoosterPropertyItems.SingleOrDefault(o => o == 1548));
Assert.Null(BoosterPropertyItems.SingleOrDefault(o => o == 6542));
// converts to
BoosterPropertyItems.SingleOrDefault(o => o == 1548).ShouldNotBeNull();
BoosterPropertyItems.SingleOrDefault(o => o == 6542).ShouldBeNull(); |
Assert.Contains(expectedPermission.Id, mappedPermissionIds); This didnt work, both are ints inside a for loop should be mappedPermissionIds.ShouldContain(expectedPermission.Id); |
// NUnit
Assert.Greater(5, 3);
Assert.GreaterOrEqual(5, 5);
// Shouldly
5.ShouldBeGreaterThan(3);
5.ShouldBeGreaterThanOrEqualTo(5);
// NUnit
Assert.Less(3, 5);
Assert.LessOrEqual(5, 5);
// Shouldly
3.ShouldBeLessThan(5);
5.ShouldBeLessThanOrEqualTo(5);
// NUnit
Assert.Positive(5);
Assert.Negative(-5);
// Shouldly
5.ShouldBePositive();
(-5).ShouldBeNegative();
// NUnit
Assert.IsNotAssignableFrom<string>(new object());
// Shouldly
new object().ShouldNotBeAssignableTo<string>();
// NUnit
Assert.Catch<ArgumentException>(() => throw new ArgumentException());
Assert.CatchAsync<ArgumentException>(async () => await ThrowsExceptionAsync());
// Shouldly
Should.Throw<ArgumentException>(() => throw new ArgumentException());
Should.ThrowAsync<ArgumentException>(async () => await ThrowsExceptionAsync());
// NUnit
StringAssert.Contains("expected", "unexpected");
StringAssert.StartsWith("start", "starting");
StringAssert.EndsWith("end", "ending");
// Shouldly
"unexpected".ShouldContain("expected");
"starting".ShouldStartWith("start");
"ending".ShouldEndWith("end");
// NUnit
CollectionAssert.Contains(new[] { 1, 2, 3 }, 2);
CollectionAssert.IsSubsetOf(new[] { 1, 2 }, new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 3 }.ShouldContain(2);
new[] { 1, 2 }.ShouldBeSubsetOf(new[] { 1, 2, 3 });
// NUnit
CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, new[] { 3, 2, 1 });
// Shouldly
new[] { 1, 2, 3 }.ShouldBe(new[] { 3, 2, 1 }, ignoreOrder: true);
// NUnit
Assert.IsNotNull(new object());
// Shouldly
new object().ShouldNotBeNull(); |
// NUnit
CollectionAssert.AllItemsAreInstancesOf(new[] { "a", "b", "c" }, typeof(string));
// Shouldly
new[] { "a", "b", "c" }.ShouldAllBe(item => item.ShouldBeOfType<string>());
// NUnit
CollectionAssert.AllItemsAreNotNull(new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 3 }.ShouldNotContainNull();
// NUnit
CollectionAssert.AllItemsAreUnique(new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 3 }.ShouldBeUnique();
// NUnit
CollectionAssert.AreEqual(new[] { 1, 2, 3 }, new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 3 }.ShouldBe(new[] { 1, 2, 3 });
// NUnit
CollectionAssert.AreNotEqual(new[] { 1, 2, 3 }, new[] { 3, 2, 1 });
// Shouldly
new[] { 1, 2, 3 }.ShouldNotBe(new[] { 3, 2, 1 });
// NUnit
CollectionAssert.Contains(new[] { 1, 2, 3 }, 2);
// Shouldly
new[] { 1, 2, 3 }.ShouldContain(2);
// NUnit
CollectionAssert.DoesNotContain(new[] { 1, 2, 3 }, 4);
// Shouldly
new[] { 1, 2, 3 }.ShouldNotContain(4);
// NUnit
CollectionAssert.IsEmpty(new int[] { });
// Shouldly
new int[] { }.ShouldBeEmpty();
// NUnit
CollectionAssert.IsNotEmpty(new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 3 }.ShouldNotBeEmpty();
// NUnit
CollectionAssert.IsOrdered(new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 3 }.ShouldBeInOrder();
// NUnit
CollectionAssert.IsSubsetOf(new[] { 1, 2 }, new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2 }.ShouldBeSubsetOf(new[] { 1, 2, 3 });
// NUnit
CollectionAssert.IsNotSubsetOf(new[] { 1, 2, 4 }, new[] { 1, 2, 3 });
// Shouldly
new[] { 1, 2, 4 }.ShouldNotBeSubsetOf(new[] { 1, 2, 3 }); |
NUnit Assertions and Shouldly Equivalents with Examples
|
Feature request
Type
Asserts TODO
Remaining list of assertion not implemented in a code fix
The text was updated successfully, but these errors were encountered: