vendredi 29 mai 2015

Mocking Interface as non-nullable instance with RhinoMocks

I have written a method as suggested in http://ift.tt/1AyDsfw. In short its a method that accepts all kind of Enums as argument and does some basic checking.

public T GetEnumFromString<T>(string value) where T : struct, IConvertible
{
   if (!typeof(T).IsEnum) 
   {
      throw new ArgumentException("T must be an enumerated type");
   }
   //...
}

Now I want to write a test for this, that validates that when a non Enum time is feed to it, an exception is thrown. I wanted to generate a dummy object as follow with RhinoMocks.

var mock = MockRepository.GenerateMock<IConvertible>();

But the method doesn't accepts the nullable type.

Is there a way to mock structs/non-nullable instances with RhinoMocks?

Aucun commentaire:

Enregistrer un commentaire