public class Customer
{
public int CustomerID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
}
所有 int 属性 = 1111、所有 string 属性 = XXXX、所有 DateTime 属性将为 DateTime.Now 等等。我认为我不需要 DI/IoC 容器,因为在准备好模型实体之后,我必须显式地将所有这些实体传递给方法(参数 List
规格:
ASP.NET C# (.NET 3.5)
DotNetNuke (5.XX)
MS SQL Server 2005
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 LastName { 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
var customer = DefaultValuesHelper.SetDefaults<Customer>(new Customer());
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());
发布评论
评论(1)
如果您有一个创建每个对象的工厂,您可以在工厂内部调用一个帮助器方法,通过反射设置默认值。迭代对象属性并为众所周知的类型设置默认值。
否则,每次创建新实例时都必须调用辅助方法:
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.
else, you must call the helper method everytime you create a new instance: