Suppose I have an abstract class that I need to mock to use in the test of another class:
public abstract class MyAbstractClass
{
/...
}
In the particular case of this test, I need the class to be serializable. It would be nice to have something like this:
RecordManager.CreateMockObject<MyAbstractClass>(Constructor.Mocked, StrictFlags.AllMethods, new Attribute[] { new SerializableAttribute() }, ...);
Since the number of parameters for CreateMockObject is starting to grow, a settings class could be introduced:
public class CreateMockObjectSettings
{
Constructor Constructor { get; set; }
StrictFlags StrictFlags { get; set; }
object[] Parameters { get; set; }
Attribute[] CustomAttributes { get; set; }
// ...
}
With the new C# 3.0 object creation syntax, the legibility is good:
RecordManager.CreateMockObject<MyAbstractClass>(new CreateMockObjectSettings { Constructor = Constructor.Mocked, StrictFlags = StrictFlags.AllMethods, CustomAttributes = new Attribute[] { new SerializableAttribute() } });