MbUnit comes with several CodeSmith templates.The AssertWrapper template creates an strongly-typed assertion wrapper using Reflection. This enables the tester to quickly build "specialized" assertion wrapper for his classes.
The template generates an assertion method for each public property of the class. It adapts the name of the way assertion are handled depending on the type of the property. Below, is the wrapper generated for System.Collections.ICollection:
using MbUnit.Core.Framework; using System.Collections; namespace MbUnit.Core.Framework { /// <summary> /// Assertion helper for the see <cref="ICollection"/> class. /// </summary> /// <remarks> /// <para> /// This class contains static helper methods to verify assertions on the /// <see cref="ICollection"/> class. /// </para> /// <para> /// This class was automatically generated. Do not edit (or edit the template). /// </para> /// </remarks> public sealed class ICollectionAssert { #region Private constructor private ICollectionAssert {} #endregion /// <summary> /// Verifies that the property value <see cref="ICollection.Count"/> /// of <paramref name="expected"/> and <paramref="actual"/> are equal. /// </summary> /// <param name="expected"/> /// Instance containing the expected value. /// </param> /// <param name="actual"/> /// Instance containing the tested value. /// </param> public static void AreCountEqual( ICollection expected, ICollection actual ) { Assert.IsNotNull(expected); Assert.IsNotNull(actual); AreCountEqual(expected.Count,actual); } ... /// <summary> /// Verifies that the property value <see cref="ICollection.IsSynchronized"/> /// is true. /// </summary> /// <param name="actual"/> /// Instance containing the expected value. /// </param> public static void IsSynchronized( ICollection actual ) { Assert.IsNotNull(actual); Assert.IsTrue(actual.IsSynchronized, "Property IsSynchronized is false"); } ... }
Page rendered at Thursday, December 04, 2008 6:15:17 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.