I think this is a bug.

Yann, the bug is on line 124 of VerifyContractAttribute.cs:

FieldInfo fieldInfo = field.Resolve(true);
IContract contract = fieldInfo.GetValue(fieldInfo.IsStatic ? null :
state.FixtureInstance) as IContract;

The problem is that 'field' is going to be a reference to a field of a
generic type definition.  We can't use that reference to get the value of a
field defined on a specialization of that generic type.

We should use the FixtureMemberInvoker here like we do in FactoryAttribute.

It might be good to check DynamicTestFactoryAttribute too.

Jeff.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Mark Kharitonov
Sent: Saturday, August 29, 2009 4:19 AM
To: MbUnit.User
Subject: MbUnit Do contract verifiers work inside generic test fixtures?


Hi, examine the following trivial sample:
=========================================================
namespace ListContractTest
{
  internal static class TypeFactory
  {
    internal static IEnumerable<Type> GetTypes()
    {
      yield return typeof(int);
    }
  }

  [TestFixture]
  public class ListContractTest<[Factory(typeof(TypeFactory),
"GetTypes")] T>
  {
    [VerifyContract]
    public readonly IContract CollectionTests = new
ListContract<ReadOnlyCollection<int>, int>
    {
      IsReadOnly = true,
      DefaultInstance = () => new ReadOnlyCollection<int>(new[] { 0, 5, 7, 2
}),
      DistinctInstances = new DistinctInstanceCollection<int>(new[]
{ 5, 10 }),
    };
  }
}
=========================================================

Trying to run the fixture yields the following error message:
System.InvalidOperationException: Late bound operations cannot be performed
on fields with types for which Type.ContainsGenericParameters is true.
   at System.Reflection.RtFieldInfo.GetValue(Object obj)

Is it by design?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/mbunituser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to