How did you extend your Assert class

rabashani picture rabashani · Dec 19, 2008 · Viewed 7.7k times · Source

I love to Extend my Assert.AreEqual to many different classes, the known one is the CollectionAssert of course, but I can think of some more such as: ImageAssert, XmlAssert etc..

Did you Create your own Assert classes? and what kind of new would you like to create?

Answer

Omu picture Omu · Aug 3, 2012

That's my solution:

using MyStuff;

using A = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace Mytestproj.Tests
{
    public static class Assert
    {
        public static void AreEqual(object expected, object actual)
        {
            A.AreEqual(expected, actual);
        }

        // my extension
        public static void AreEqual(MyEnum expected, int actual)
        {
            A.AreEqual((int)expected, actual);
        }

        public static void IsTrue(bool o)
        {
            A.IsTrue(o);
        }

        public static void IsFalse(bool o)
        {
            A.IsFalse(o);
        }

        public static void AreNotEqual(object notExpected, object actual)
        {
            A.AreNotEqual(notExpected, actual);
        }

        public static void IsNotNull(object o)
        {
            A.IsNotNull(o);
        }

        public static void IsNull(object o)
        {
            A.IsNull(o);
        }
    }
}