--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
a) introduce ICreationFactory which simply does Activator.CreateInstance and
in your simple class just verify that ICreationFactory.Create is called. For
other feature tests of SimpleClass just setup factory mock to return another
mock or make it default value mock
- or -
b) Constructor overload which takes Func<Type, IYourObjectToCreate>. Simple
do in your test () => yourMock.Object.
- or -
c) Move Activator.CreateInstance call into over writable method in your
SimpleClass. Either Subclass in your test or use Moqs class mocking feature
to create a mock of your testee with CallBase = true
- or -
d) Manual approach. Move Activator.CreateInstance call into over writable
method in your SimpleClass.
SimpleClass{
protected virtual IYourObjectToCreate Create(Type typeToCreate) {
return Activator.CreateInstance(typeToCreate);
}
}
TestableSimpleClass {
public Type TypeWhichWasRequestedForCreation { get; private set; }
protected override IYourObjectToCreate Create(Type typeToCreate) {
// do not class base here
this.TypeWhichWasRequestedForCreation = typeToCreate;
}
}
use TestableSimpleClass in your test code
Have fun
-----Ursprüngliche Nachricht-----
Von: moq...@googlegroups.com [mailto:moq...@googlegroups.com] Im Auftrag
von Pawel Tarnik
Gesendet: Dienstag, 4. Januar 2011 18:24
An: Moq Discussions
Betreff: [Moq] Re: How to serialize mocked interface
public class SimpleClass { }
Then I get:
System.MethodAccessException:
Castle.DynamicProxy.StandardInterceptor..ctor()
at Castle.Proxies.SimpleClassProxy..ctor()
Any ideas?
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com