Faker てのを見つけた
Faker is a .NET library used to generate fake data - names, addresses, e-mails, dates etc.
Faker v1.0.0 - CodePlex
ダミーデータ吐いてくれる。いつか使えそう。
MonoDevelop から使ってみた。
コード
住所をくっつけるときに空白を挿入するところがかっこよくない。特に何ともないコード。もっと変なコードが書きたい。
// Main.cs created with MonoDevelop // User: inohiro at 22:28 10/29/2008 using System; using System.Collections.Generic; using Faker; using FakerTests; using System.Text; using System.Linq; namespace FakerDemo { internal class Person { public Person( string name, string location, string company ) { this.Name = name; this.Location = location; this.Company = company; } internal string Name { get; set; } internal string Company { get; set; } internal string Location { get; set; } } class MainClass { public static void Main(string[] args) { List<Person> people = new List<Person>(); for( int i = 0; i < 100000; i++ ) { StringBuilder address = new StringBuilder(); address.Append( Faker.LocationFaker.Country() ); address.Append( " " ); // かっこよくない... address.Append( Faker.LocationFaker.ZipCode() ); address.Append( " " ); address.Append( Faker.LocationFaker.City() ); address.Append( " " ); address.Append( Faker.LocationFaker.Street() ); address.Append( " " ); address.Append( Faker.LocationFaker.StreetName() ); people.Add( new Person( Faker.NameFaker.Name(), address.ToString(), Faker.CompanyFaker.Name() ) ); } // for( int i = 0; i < 100; i++ ) // Console.WriteLine( people[i].Name ); var query = from a in people where a.Name == "Lucy Abel" select a; foreach( var person in query ) Console.WriteLine( person.Name + ", " + person.Location ); Console.ReadKey(); } } }
結果
Lucy Abel, Comoros 12760 Polokwane 18 Jackson Woodland Laurel Highland Lucy Abel, Paraguay 47940 Bela 29 Lincoln Sunset Wilson Virginia Lucy Abel, Zambia 29849 Polokwane 17 Beech Woodland Wilson Sunset Lucy Abel, Bahrain 35063 Musina 44 Birch Woodland Birch Woodland Lucy Abel, Switzerland 01910 Ogies 4 Adams Hill Jefferson Highland Lucy Abel, Trinidad and Tobago 95019 Tswane 31 Pine Park Cedar Sunset Lucy Abel, St. Kitts and Nevis 01366 Bultfontein 42 Wilson Woodland Elm Virginia Lucy Abel, Djibouti 36261 Tswane 14 Linden Sunset Adams Highland Lucy Abel, Samoa 35890 Grove 49 Madison Park Jackson Sunset Lucy Abel, Eritrea 85255 Prieska 35 Cedar Virginia Cherry Park Lucy Abel, Congo, Rep. 43439 Tauranga 30 Jefferson Sunset Lincoln Park Lucy Abel, St. Lucia 14595 Salem 17 Cherry Woodland Adams Hill Lucy Abel, Chile 78185 Bothaville 2 Jackson Virginia Madison Hill Lucy Abel, Greenland 82147 Tswane 8 Birch Woodland Washington Highland Lucy Abel, Serbia 38924 Bela 41 Linden Park Franklin Highland Lucy Abel, Trinidad and Tobago 41773 Nababeep 49 Cedar Park Maple Park Lucy Abel, Bhutan 01680 Wanganui 40 Birch Hill Beech Virginia Lucy Abel, Yemen, Rep. 18335 Musina 2 Walnut Woodland Birch Highland Lucy Abel, Bulgaria 48757 Pleasant 12 Franklin Highland Laurel Woodland Lucy Abel, Libya 26552 Trompsburg 29 Walnut Sunset Oak Virginia Lucy Abel, Iraq 59014 Oak 48 Jackson Highland Linden Virginia Lucy Abel, Netherlands 70498 Wanganui 7 Maple Highland Cedar Highland
気になったこと
VSからLinqなコード書くとき、System.Coreの参照を追加する必要はありませんでしたが、MonoDevelopからだと自分で追加しないと使えない。