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

Faker是Ruby 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:
  曹如进:使用Faker.NET仿造数据_第1张图片
It's very simple to use, shown below is the code for the following WP7 apps:
曹如进:使用Faker.NET仿造数据_第2张图片
曹如进:使用Faker.NET仿造数据_第3张图片
It could be used anywhere you need fake data - proof of concept, testing, demo apps...


你可能感兴趣的:(曹如进:使用Faker.NET仿造数据)