Ok, sorry for the wordy title, but it seemed like the only way to summarise my issue.
So I have an interface defined like so:
public interface ITaskGenerator<T> where T : ITaskRequest
{
int CreateTask(T request);
}
and an implementer:
public class OrderTaskGenerator : ITaskGenerator<OrderTaskRequest>
{
public int CreateTask(OrderTaskRequest request)
{
..
}
}
What I want to do is make a generic test fixture using NUnit, that I can just specify all of the implementers of the ITaskGenerator<ITaskRequest> interface, to run the contract tests for all of them.
Luckily, NUnit has the ability to do that, with the Generic Test Fixture specified here . I've written the following (the [TestFixture(typeof(OrderTaskGenerator))] attribute is what's important for NUnit to pass through the correct type):
[TestFixture(typeof(OrderTaskGenerator))]
public class ITaskGeneratorContract<T> where T : ITaskGenerator<ITaskRequest>, new()
{
[Test]
public void CreateTask_Returns_InvalidException_If_Task_ID_Is_Empty()
{
// Test goes here
}
}
However, this doesn't show up in Test explorer. If I make the interface non-generic it does.
So does anyone know a work around to this, or is there something else that I'm missing. I think it's because ITaskGenerator is a generic interface, but I could be wrong.
Aucun commentaire:
Enregistrer un commentaire