Visual Studio Unit Testing Extensions v1.2.0.0
Version 1.2.0.0 of these Unit Testing Extensions are available on CodePlex today. The original post that talks about the project can be found here. An updated NuGet package is also available.
This release contains additional assertions on IEnumerable<T>, String, and Type. Additionally, a helper method was added, AssertHelper.AssertFailed(), to allow consumers to create their own custom assertions.
Here are some examples of the new assertions in action:
// IEnumerable<T>
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>();
source.ShouldBeEmpty();
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1 };
source.ShouldNotBeEmpty();
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5 };
source.ShouldContain(2);
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5 };
source.ShouldNotContain(6);
source = new List<int>();
source.ShouldNotContain(1);
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5 };
source.ShouldHaveCountOf(5);
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5 };
source.ShouldNotHaveCountOf(4);
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5 };
source.ShouldHaveCountOfAtLeast(4);
}
[TestMethod]
public void Test()
{
IEnumerable<int> source = new List<int>() { 1, 2, 3, 4, 5 };
source.ShouldHaveCountOfAtMost(6);
}
// String
[TestMethod]
public void Test()
{
"test".ShouldHaveLengthOf(4);
String.Empty.ShouldHaveLengthOf(0);
}
[TestMethod]
public void Test()
{
"test".ShouldNotHaveLengthOf(3);
String.Empty.ShouldNotHaveLengthOf(1);
}
[TestMethod]
public void Test()
{
"test".ShouldHaveLengthOfAtLeast(3);
String.Empty.ShouldHaveLengthOfAtLeast(0);
}
[TestMethod]
public void Test()
{
"test".ShouldHaveLengthOfAtMost(5);
String.Empty.ShouldHaveLengthOfAtMost(2);
}
// Type
[TestMethod]
public void Test()
{
(typeof(ICollection)).ShouldBeAssignableFrom(typeof(IEnumerable));
}
[TestMethod]
public void Test()
{
(typeof(IList)).ShouldBeAssignableFrom<IEnumerable>();
}
Comments
- Anonymous
February 11, 2012
Fluent Assertions does this same thing... fluentassertions.codeplex.com