Is there a tool I can use to generate interfaces and wrappers for object mocking in c#
Posted
by fostandy
on Stack Overflow
See other posts from Stack Overflow
or by fostandy
Published on 2010-04-20T02:41:06Z
Indexed on
2010/04/20
2:43 UTC
Read the original article
Hit count: 318
Given a class like System.Timers.Timer, or ANY managed class (whether user defined, from the .net framework, or some 3rd party library) is there some program I can use to (a) generate an interface based on this class and (b) generate a wrapper for the given class?
for example if I have a
public class Foo { public object MyProperty { get { ... } set { ... } } public int SomeMethod(object a) { ... } }
it will create an interface
interface IFoo { object MyProperty { get; set; } int SomeMethod(object a) { ... } }
and maybe even a wrapper
class FooWrap { // something for relay constructor here ...
Foo _me;
public object MyProperty { get { return _me.MyProperty; } set { _me.MyProperty = value; } } public int SomeMethod(object a) { return _me.SomeMethod(); } }
Obviously there's stuff I haven't thought about like events, generics etc. I want a DWIMNWIS-PSICHTO(-Plus-Stuff-I-Clearly-Haven't-Thought-Of).
I'm aware resharper can be used to extract an interface but I've only been able to use this on my own classes.
Aside: Wow, it is amazing how simply becoming accustomed to a previously 'unacceptable' idea eventually gives it legitimacy. A year ago the idea of having to create interfaces for all objects I want to mock and adopting an injection framework would have seemed like the height of madness. It turns out that while it's not quite death and taxes, it is sparta.
I am aware of and have used typemock. It certainly is the work of elvish wizards. One day when $800 does not seem like quite so much money I intend to buy it.
© Stack Overflow or respective owner