Conventional Testing for .NET

  • master
  • dev
  • Join the chat at https://gitter.im/fixie/fixie
using Should;

public class CalculatorTests
{
    public void ShouldAdd()
    {
        var calculator = new Calculator();
        calculator.Add(2, 3).ShouldEqual(5);
    }

    public void ShouldSubtract()
    {
        var calculator = new Calculator();
        calculator.Subtract(5, 3).ShouldEqual(2);
    }
}

//CustomConvention.cs
using System;
using Fixie;

public class CustomConvention : Convention
{
    public CustomConvention()
    {
        Classes
            .NameEndsWith("Tests");

        Methods
            .HasOrInherits<TestAttribute>();
    }
}

[AttributeUsage(AttributeTargets.Method)]
public class TestAttribute : Attribute { }
//CalculatorTests.cs
using Should;

public class CalculatorTests
{
    [Test]
    public void ShouldAdd()
    {
        var calculator = new Calculator();
        calculator.Add(2, 3).ShouldEqual(5);
    }

    [Test]
    public void ShouldSubtract()
    {
        var calculator = new Calculator();
        calculator.Subtract(5, 3).ShouldEqual(2);
    }
}

using Fixie;

public class CustomConvention : Convention
{
    public CustomConvention()
    {
        Classes
            .NameEndsWith("Tests");

        ClassExecution
            .CreateInstancePerClass()
            .UsingFactory(YourFavoriteIoCContainer.Get);
    }
}

using Fixie;

public class CustomConvention : Convention
{
    public CustomConvention()
    {
        Classes
            .NameEndsWith("Tests");

        Methods
            .Where(method => method.IsVoid());

        Parameters
            .Add<FromAutoFixture>();
    }

    class FromAutoFixture : ParameterSource
    {
        public IEnumerable<object[]> GetParameters(MethodInfo method)
        {
            //Use AutoFixture to resolve each argument found on the MethodInfo
        }
    }
}

using Fixie;

public class CustomConvention : Convention
{
    public CustomConvention()
    {
        Classes
            .NameEndsWith("Tests");

        Methods
            .Where(method => method.IsVoid());

        CaseExecution
            .Wrap<Transaction>();
    }

    class Transaction : CaseBehavior
    {
        public void Execute(Case context, Action next)
        {
            using (new TransactionScope())
                next();
        }
    }
}