Completed
Last Updated: 07 Oct 2013 11:05 by Micah
Micah
Created on: 21 Aug 2013 22:03
Type: Feature Request
1
Improve exception message for Mock.Create.
Given:
public abstract class Foo
{
}

[Test]
public void test_foo()
{
    Mock.Create<Foo>(Behavior.Strict, Constructor.Mocked);
}

An exception is thrown at runtime saying "Abstract Type is not Accessible for Inheritance".  This doesn't lead you to the actual problem which is that I accidentally swapped the Behavior and the Constructor in the parameter order.  The same problem can occur if you attempt to call a constructor on an abstract object with the wrong number of parameters like so:
public abstract class Foo
{
    public Foo(int a, string b)
    {
    }
}

[Test]
public void test_foo()
{
    Mock.Create<Foo>(1, "foo", null);
}

This seems to be a problem with the compiler choosing the wrong overload to call and unfortunately there aren't a lot of solutions without changing the Create API.  Perhaps having an alternative to Mock.Create that is more explicit that we can use to avoid typos leading to exceptions that are difficult to make sense of or a hint in the exception message that suggests what the root cause might be?
0 comments