有什么工具用随机数据填充类属性? [英] Are there any tools to populate class properties with random data?
问题描述
我想要做的是创建一个具有不同属性上的一些属性的类,将该类传递给另一个将使用适当的随机数据设置属性...这里的伪代码:
What I'd like to do is create a class with some attributes on different properties, pass that class to another that will set the properties with appropriate random data... here in pseudo code:
public class Customer
{
[Attribute("FirstName")]
private string CustomerFirstName;
public {get;set} //etc
[Attribute("LastName")]
private string CustomerLastName;
public {get;set;} //etc
[Attribute("DateTime")]
private DateTime CustomerSignUpDate;
public DateTime {get;set;} //yadda
[Attribute("Phone")]
private string CustomerPhone;
public string {get;set;} //yadda
}
然后像这样
IList<Customer> CustomerList=ClassFillerOutClass(new Customer(),5);
结果将是一个5个客户列表,在其属性中有适当的随机数据。
And the result would be a List of 5 Customers that have appropriate 'random' data in their properties.
如果这不存在...我想我可以自己开始一个项目...我只是不想重塑轮,如果不是必要。
If this doesn't exist...I guess I could start a project myself to do...I just don't want to reinvent the wheel if it's not necessary.
编辑:我忘了一块。我正在寻找使用它作为一个测试工具。所以在上面的例子中,我可以快速创建一个包含随机但合适的值的5个客户的列表。然后说,传递给我的持久化方法,并有我可以检查的东西。我试图避免每次为我的TDD目的手动创建一个填充的对象。
I forgot a piece. I'm looking to use this as a test tool. So in the example above I could quickly create a list of 5 customers with random but appropriate values. And then say pass that to my persistence method, and have something I can check against. I'm trying to avoid manually creating a populated object everytime for my TDD purposes.
编辑2:好,所以我开始滚动我自己...我会发布在Codeplex这个周末,并链接到这里...我显然不会做,但它将是一个开始,如果任何人想要工作。
EDIT 2: Ok so I started rolling my own...I'll post it on Codeplex this weekend and link it here...I clearly won't be done but it'll be a start if anyone else wants to work on it.
推荐答案
确定...所以我从来没有找到一个....所以我决定开始自己的。签出:
对象Hydrator 。
Ok...so I never found one....so I decided to start my own. Check out: Object Hydrator.
该项目目前是一个快速尖峰...但我认为它有潜力...让我知道如果你有想法如何使它更好。
The project is presently a quick spike...but I think it has potential...let me know if you have ideas how to make it better.
这篇关于有什么工具用随机数据填充类属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!