We are pleased to announce that a new release of
Gallio/MbUnit is now available. This release contains many new features and improvements for MbUnit. Please see below or read the
release notes for more details.
· Downloads
Please visit the Gallio website
Downloads page to get the binaries, or grab them directly from here:
· Overview
This release mainly focuses on new features for MbUnit.
NHamcrest
NHamcrest is an idiomatic C# port of Hamcrest (java version) made by Graham Hay. It provides a nice fluent syntax for
Assert.That. The library is now part of the Gallio bundle.
[Test]
public void Assert_that()
{
Assert.That(1, Is.Anything());
Assert.That(1 + 1, Is.EqualTo(2));
Assert.That("string", Is.EqualTo("string"));
Assert.That(5.0, Is.EqualTo(5.0));
Assert.That(false, Is.False());
Assert.That(true, Is.True());
Assert.That(null, Is.Null());
Assert.That("", Is.NotNull());
Assert.That(5, Is.LessThan(6));
Assert.That(5, Is.GreaterThan(4));
const string aString = "aString";
Assert.That(aString, Is.SameAs(aString));
Assert.That("the cat sat on the mat", Starts.With("the cat"));
Assert.That("the cat sat on the mat", Contains.String("sat on"));
Assert.That("the cat sat on the mat", Ends.With("the mat"));
Assert.That(1, Is.InstanceOf<int>());
Assert.That(() => { throw new ArgumentException(); }, Throws.An<ArgumentException>());
}
Assert.HasAttribute(s)
2 new assertions to check whether a code element is decorated with a specific attribute. Those assertions are particularly powerful when used in combination with the
Mirror API.
[DisplayName("Item")]
public class Product
{
public int Id { get; set; }
[Required, StringLength(10)]
public string Name { get; set; }
[Required]
public string Description { get; set; }
[Required, Range(0, 1000)]
public decimal Price { get; set; }
}
[TestFixture]
public class ProductTest
{
[Test]
public void Product_has_DisplayNameAttribute()
{
Assert.HasAttribute<DisplayNameAttribute>(typeof(Product));
}
[Test]
public void Description_has_RequiredAttribute()
{
var property = Mirror.ForType<Product>()["Description"];
Assert.HasAttribute<RequiredAttribute>(property);
}
}
[Test]
public void Assert_contains()
{
string actualValue = "Edgar Allan Poe (January 19, 1809 – October 7, 1849)";
string expectedSubstring = "ALLAN POE";
Assert.Contains(actualValue, expectedSubstring, StringComparison.OrdinalIgnoreCase);
}
[Test]
public void Assert_doesNotExist()
{
var data = new[] { "Athos", "Porthos", "Aramis" };
Assert.DoesNotExist(data, x => x.Contains("gnan"));
}
Multiple [Impersonate] instances
Running tests under another identity is a little-known feature of MbUnit. It is now possible to provide several user credentials at once.[Test]
[Impersonate(UserName = "Julius", Password = "Ven1V1d1V1c1")]
[Impersonate(UserName = "Brutus", Password = "F**kD4ddy")]
public void Test()
{
var identity = WindowsIdentity.GetCurrent();
TestLog.Write("User = {0}", identity.Name);
}
And many other things...
Such as improvements to contract verifiers, "Seed" property to the random data sources, easier ways to assert over inner exceptions, etc.
· Credits
This great release was made possible thanks to the hard work of our dedicated fellow contributors:
- Graham Hay
- Artur Zgodziński
- Jonathan Linstead
- Yann Trévin
And a special thank to
Jeff Brown for his invaluable advices and his deep knowledge of the Gallio infrastructure.
Finally, we would like to express our gratitude to our passionate users who help us in building that great piece of software by submitting bug reports, patches, blog posts, and suggestions.
And more than ever,
contributions are gratefully received.