是否有任何工具来填充随机数据类属性? [英] Are there any tools to populate class properties with random data?

查看:95
本文介绍了是否有任何工具来填充随机数据类属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是创建对不同性质的某些属性的类,这个类传递到另一个,将设置适当的随机数据的属性......在这里伪代码:

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.

推荐答案

好吧......所以我从来没有发现的....所以我决定开始我自己。退房:
对象保湿

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆