Jolt.Testing : Test Framework Adapters for General-Purpose Assertions

Note: This page describes the assertion adaptors for the general-purpose XML assertions in the Jolt.Testing library. For a description of the general-purpose assertions, please refer to this page.

Table of Contents

  1. NUnit Usage Examples
    1. Using the equality axiom assertions with NUnit
  2. Visual Studio Usage Examples
    1. Using the equality axiom assertions with Visual Studio

NUnit Usage Examples

The assertion adaptors for NUnit are available in the Jolt.Testing.Assertions.NUnit.dll assembly and their usage is demonstrated in the following sections.


The constraint classes EqualityAxiomConstraint<T>, EquatableAxiomConstraint<T>, ComarableAxiomConstraint<T>, and EqualityComparerAxiomConstraint<T> each adapt their similarly-named assertion types for use through the NUnit constraint syntax. The following example demonstrates the usage of these types.

using System;
using System.Collections.Generic;
using Jolt.Testing.Assertions.NUnit;
using NUnit.Framework;

public class IntegerFactory : IArgumentFactory<int>, IEquatableFactory<int>, IComparableFactory<int>
{
    public int Create()
    {
        return 12345;
    }

    public void Modify(ref int instance)
    {
        --instance;
    }
}

[Test]
void EqualityVerification()
{
    IntegerFactory factory = new IntegerFactory();

    Assert.That(typeof(int), new EqualityAxiomConstraint<int>(factory));
    Assert.That(typeof(int), new EquatableAxiomConstraint<int>(factory));
    Assert.That(typeof(int), new ComparableAxiomConstraint<int>(factory));
    Assert.That(typeof(int), new EqualityComparerAxiomConstraint<int>(factory, EqualityComparer<int>.Default));
}

An NUnit-style syntax helper is also available for use, as demonstrated in the following example.

using System.Collections.Generic;
using Jolt.Assertions.NUnit;
using Jolt.Assertions.NUnit.SyntaxHelpers;
using NUnit.Framework;

[Test]
void EqualityVerification()
{
    IArgumentFactory<int> factory = new IntegerFactory();
    IEquatableFactory<int> equatableIntFactory = factory as IEquatableFactory<int>;
    IComparableFactory<int> comparableIntFactory = factory as IComparableFactory<int>;

    Assert.That(typeof(int), Implements.EqualityAxiom(factory));
    Assert.That(typeof(int), Implements.EqualityAxiom(equatableIntFactory));
    Assert.That(typeof(int), Implements.EqualityAxiom(comparableIntFactory));
    Assert.That(typeof(int), Implements.EqualityAxiom(factory, EqualityComparer<int>.Default));
}

Visual Studio Usage Examples

The assertion adaptors for Visual Studio are available in the Jolt.Testing.Assertions.VisualStudio.dll assembly and their usage is demonstrated in the following sections.


The overloaded AxiomAssert.Equality() methods provide a means to invoke the EqualityAxiomConstraint<T>, EquatableAxiomConstraint<T>, ComarableAxiomConstraint<T>, and EqualityComparerAxiomConstraint<T> classes within Visual Studio, as demonstrated in the following example.

using System;
using System.Collections.Generic;
using Jolt.Testing.Assertions.VisualStudio;
using Microsoft.VisualStudio.TestTools.UnitTesting;

public partial class IntegerFactory : IArgumentFactory<int>, IEquatableFactory<int>, IComparableFactory<int>
{
    public int Create()
    {
        return 12345;
    }

    public void Modify(ref int instance)
    {
        --instance;
    }
}

[Test]
void EqualityVerification()
{
    IArgumentFactory<int> factory = new IntegerFactory();
    IEquatableFactory<int> equatableIntFactory = factory as IEquatableFactory<int>;
    IComparableFactory<int> comparableIntFactory = factory as IComparableFactory<int>;

    AxiomAssert.Equality(factory);
    AxiomAssert.Equality(equatableIntFactory);
    AxiomAssert.Equality(comparableIntFactory);
    AxiomAssert.Equality(factory, EqualityComparer<int>.Default);
}

Last edited Sep 3, 2010 at 5:08 AM by SteveGuidi, version 7

Comments

No comments yet.