开发者

How to auto-mock custom business entities?

I have a requirement to provide auto-mocking for 30 different types of custom business objects. In order to avoid the cost of writing manual mock-up codes for all public properties in each entity, I am looking for a lightweight framework that I can utilize in my project. Actually, this is not for unit testing but for "preview" functionality.

As for the behavior of mocking, I want to go by data type of the underlying entity. For instance,

public class Customer
{
    public int CustomerID { get; set; }
    public string FirstName { get; set; }
    public string La开发者_StackOverflowstName { get; set; }
    public DateTime DateOfBirth { get; set; }
}

All int properties = 1111, All string properties = XXXX, All DateTime properties will be DateTime.Now etc. I don't think I would need DI/IoC container because after preparing the mock-up entities, I have to explicitly pass all of those entities to a method (parameter List<object> entities).

Specifications: ASP.NET C# (.NET 3.5) DotNetNuke (5.X.X) MS SQL Server 2005

Thanks for your comments and suggestion!


If you have a factory that create each object, you can call inside the factory a helper method that set your default values via reflection. Iterate object properties and set defaults for well known types.

var customer = CustomerFactory.Create();

else, you must call the helper method everytime you create a new instance:

var customer = DefaultValuesHelper.SetDefaults<Customer>(new Customer());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜