曹如進:使用Faker.NET仿造數據

FakerRuby Faker gem的C#開源移植實現,主要用於方便地生成仿造數據(雖然是假數據,可是看起來很像真的),包括姓名、地址、電話號碼等等。不管是用於演示,仍是用做測試數據,Faker都很是好用。git

那麼它是如何工做的呢?閱讀它的代碼你會發現——解決方案包含了一些資源文件,這些文件包含了每一個屬性(attribute)的一些可能的優質值 (例如,First Name,Last Name等等),以後經過代碼隨機混合和匹配這些值來生成數據。每一個屬性預留的值越多,組合就越多,從而結果數據就越豐富。根據你的特定須要,能夠修改資 源文件來反映你的數據需求(例如,限定於某一區域的姓名或地址)。Ollie Riches的文章faking data in WP7 and other .Net platforms展現了Faker的快速使用方法。github

這個實用程序與.NET Framework 4.0、Silverlight 3-5以及Windows Phone 7.0和7.1兼容。它以NuGet包的形式發放。ruby

GiHub上還有一個同名(Faker.NET)的項目,它的工做方式差很少,除了有幾點不一樣——可能的屬性值直接在C#代碼中(而不是放在資源文件中);另外,它提供了額外的關於教育(Education)的類(學位(Degree)、專業(Major)、學院(School)等)。app

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... ui


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...
相關文章
相關標籤/搜索