views:

501

answers:

1

Running this code:

_foo = MockRepository.GenerateStub<IBar>();
_foo.Stub(x => x.Foo()).Return("sdf");

When

public interface IBar
{
   string Foo();
}

public class Bar : IBar
{
   public string Foo()
   {
      throw new NotImplementedException();
   }
}

throws NotSupportedException - "Can't create mocks of sealed classes". I understand why you can't mock a sealed class (although there are solutions in TypeMock), but what's the problem with mocking a class that returns a sealed class (string) ?

+1  A: 

Your code works properly. You likely have some other code not shown which is causing the problem. Post your whole unit test here and we'll diagnose the issue for you.

Judah Himango