曹如进:使用Faker.NET仿造数据

FakerRuby Faker gem的C#开源移植实现,主要用于方便地生成仿造数据(虽然是假数据,但是看起来很像真的),包括姓名、地址、电话号码等等。无论是用于演示,还是用作测试数据,Faker都非常好用。

那么它是如何工作的呢?阅读它的代码你会发现——解决方案包含了一些资源文件,这些文件包含了每个属性(attribute)的一些可能的优质值 (例如,First Name,Last Name等等),之后通过代码随机混合和匹配这些值来生成数据。每个属性预留的值越多,组合就越多,从而结果数据就越丰富。根据你的特定需要,可以修改资 源文件来反映你的数据需求(例如,限定于某一区域的姓名或地址)。Ollie Riches的文章faking data in WP7 and other .Net platforms展示了Faker的快速使用方法。

这个实用程序与.NET Framework 4.0、Silverlight 3-5以及Windows Phone 7.0和7.1兼容。它以NuGet包的形式发放。

GiHub上还有一个同名(Faker.NET)的项目,它的工作方式差不多,除了有几点不同——可能的属性值直接在C#代码中(而不是放在资源文件中);另外,它提供了额外的关于教育(Education)的类(学位(Degree)、专业(Major)、学院(School)等)。

faking data in WP7 and other .Net platforms

I needed to fake some data for a WP7 app yesterday and I was about to write a couple of classes when I thought why not check out what's available out there already...


There were already a couple of NuGet packages out there but I wanted to try out my forking skills on GitHub :) I had a quick conversation with Ben Smith about faker-cs  and producing a NuGet package. 

Introducing Faker.Net on NuGet, with support for .Net 3.5 SP1, .Net 4.0, Silverlight & WP7.

Faker.Net support loads of different ways to fake data - addresses, names, phones numbers and more:
 
It's very simple to use, shown below is the code for the following WP7 apps:


It could be used anywhere you need fake data - proof of concept, testing, demo apps...


转载于:https://my.oschina.net/bairrfhoinn/blog/53126

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值