0

I have written a method as suggested in https://stackoverflow.com/a/79903/976896. In short its a method that accepts all kind of Enums as argument and does some basic checking.

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

   this.intValue = Convert.ToInt32(value);
}

Now I want to write a test for this, that validates that when a non Enum type 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?

Edit: Updated code listing

Community
  • 1
  • 1
  • 1
    You could just use an existing non-enum `struct` type which implements `IConvertible` like an `int`: `GetEnumFromString("123")` – Lee May 29 '15 at 15:59
  • I'm not sure what you're trying to do. You need a compile time type in order to call your method. Not an instance of anything (apart from the string argument, which won't even get accessed). So mocking doesn't really come into it. – Rob May 29 '15 at 16:31
  • My fault, I updated the code listing. Sorry for the confusion, hope things are now more clear. – Christophe Lambrechts Jun 01 '15 at 07:43

0 Answers0