diff --git a/.gitignore b/.gitignore index 9d53519..534cb18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,153 @@ -bin -obj -TestResults -*~ -*.swp +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files *.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +#!packages/*/build/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + /Faker.Net.sln.DotSettings.user diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config new file mode 100644 index 0000000..67f8ea0 --- /dev/null +++ b/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe new file mode 100644 index 0000000..2c93698 Binary files /dev/null and b/.nuget/NuGet.exe differ diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets new file mode 100644 index 0000000..83fe906 --- /dev/null +++ b/.nuget/NuGet.targets @@ -0,0 +1,136 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) + + + + + $(SolutionDir).nuget + packages.config + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 $(NuGetExePath) + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FFaker.Net.1.1.0.0.nupkg b/FFaker.Net.1.1.0.0.nupkg new file mode 100644 index 0000000..e8f9a25 Binary files /dev/null and b/FFaker.Net.1.1.0.0.nupkg differ diff --git a/FFaker.Net.1.1.0.0.symbols.nupkg b/FFaker.Net.1.1.0.0.symbols.nupkg new file mode 100644 index 0000000..8bc1fc6 Binary files /dev/null and b/FFaker.Net.1.1.0.0.symbols.nupkg differ diff --git a/Faker.Net.NUnit.Tests/AddressTests.cs b/Faker.Net.NUnit.Tests/AddressTests.cs index 304222f..19dc4fa 100644 --- a/Faker.Net.NUnit.Tests/AddressTests.cs +++ b/Faker.Net.NUnit.Tests/AddressTests.cs @@ -1,99 +1,106 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; using NUnit.Framework; -namespace Faker.Tests -{ - [TestFixture] - public class AddressTests - { - [Test] - public void TestCity() - { - Assert.IsTrue(Regex.IsMatch(Address.GetCity(), @"[ a-z]+")); - } - - [Test] - public void TestCityPrefix() - { - Assert.IsTrue(Regex.IsMatch(Address.GetCityPrefix(), @"[ a-z]")); - } - - [Test] - public void TestCitySuffix() - { - Assert.IsTrue(Regex.IsMatch(Address.GetCitySuffix(), @"[ a-z]")); - } - - [Test] - public void TestSecondaryAddress() - { - Assert.IsTrue(Regex.IsMatch(Address.GetSecondaryAddress(), @"[ a-z]")); - } - - [Test] - public void TestStreetAddress() - { - Assert.IsTrue(Regex.IsMatch(Address.GetStreetAddress(), @"[ a-z]")); - } - - [Test] - public void TestStreetName() - { - Assert.IsTrue(Regex.IsMatch(Address.GetStreetName(), @"[ a-z]")); - } - - [Test] - public void TestStreetSuffix() - { - Assert.IsTrue(Regex.IsMatch(Address.GetStreetSuffix(), @"[ a-z]")); - } - - [Test] - public void TestUKCountry() - { - Assert.IsTrue(Regex.IsMatch(Address.GetUKCountry(), @"[ a-z]")); - } - - [Test] - public void TestUKCounty() - { - Assert.IsTrue(Regex.IsMatch(Address.GetUKCounty(), @"[ a-z]")); - } - - [Test] - public void TestUKPostcode() - { - Assert.IsTrue(Regex.IsMatch(Address.GetUKPostcode(), @"[ a-z]")); - } - - [Test] - public void TestUSState() - { - Assert.IsTrue(Regex.IsMatch(Address.GetUSState(), @"[ a-z]")); - } - - [Test] - public void TestUSStateAbbr() - { - Assert.IsTrue(Regex.IsMatch(Address.GetUSStateAbbr(), @"[A-Z]")); - } - - [Test] - public void TestUSZipCode() - { - Assert.IsTrue(Regex.IsMatch(Address.GetZipCode(), @"[0-9]")); - } - - [Test] - public void TestNeighborhood() - { - Assert.IsTrue(Regex.IsMatch(Address.GetNeighborhood(), @"[ a-z]+")); +namespace Faker.Tests +{ + [TestFixture] + public class AddressTests + { + [Test] + public void TestCity() + { + Assert.IsTrue(Regex.IsMatch(Address.GetCity(), @"[ a-z]+")); + } + + [Test] + public void TestCityPrefix() + { + Assert.IsTrue(Regex.IsMatch(Address.GetCityPrefix(), @"[ a-z]")); + } + + [Test] + public void TestCitySuffix() + { + Assert.IsTrue(Regex.IsMatch(Address.GetCitySuffix(), @"[ a-z]")); + } + + [Test] + public void TestSecondaryAddress() + { + Assert.IsTrue(Regex.IsMatch(Address.GetSecondaryAddress(), @"[ a-z]")); + } + + [Test] + public void TestUSStreetAddress() + { + var address = Address.GetEUStreetAddress(); + Assert.IsTrue(Regex.IsMatch(address, @"[ a-z]")); + } + [Test] + public void TestEUStreetAddress() + { + var address = Address.GetEUStreetAddress(); + Assert.IsTrue(Regex.IsMatch(address, @"[ a-z]")); + } + + [Test] + public void TestStreetName() + { + Assert.IsTrue(Regex.IsMatch(Address.GetStreetName(), @"[ a-z]")); + } + + [Test] + public void TestStreetSuffix() + { + Assert.IsTrue(Regex.IsMatch(Address.GetStreetSuffix(), @"[ a-z]")); + } + + [Test] + public void TestUKCountry() + { + Assert.IsTrue(Regex.IsMatch(Address.GetUKCountry(), @"[ a-z]")); + } + + [Test] + public void TestUKCounty() + { + Assert.IsTrue(Regex.IsMatch(Address.GetUKCounty(), @"[ a-z]")); + } + + [Test] + public void TestUKPostcode() + { + Assert.IsTrue(Regex.IsMatch(Address.GetUKPostcode(), @"[ a-z]")); + } + + [Test] + public void TestUSState() + { + Assert.IsTrue(Regex.IsMatch(Address.GetUSState(), @"[ a-z]")); + } + + [Test] + public void TestUSStateAbbr() + { + Assert.IsTrue(Regex.IsMatch(Address.GetUSStateAbbr(), @"[A-Z]")); + } + + [Test] + public void TestUSZipCode() + { + Assert.IsTrue(Regex.IsMatch(Address.GetZipCode(), @"[0-9]")); + } + + [Test] + public void TestNeighborhood() + { + Assert.IsTrue(Regex.IsMatch(Address.GetNeighborhood(), @"[ a-z]+")); } [Test] public void TestWorldCountry() { Assert.IsTrue(Regex.IsMatch(Address.GetCountry(), @"[ a-z]")); - } - } + } + } } \ No newline at end of file diff --git a/Faker.Net.sln b/Faker.Net.sln index 4702fc7..c5eea72 100644 --- a/Faker.Net.sln +++ b/Faker.Net.sln @@ -1,10 +1,17 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faker.Net", "Faker.Net\Faker.Net.csproj", "{F4E27022-496C-48E5-8986-F68355C2ECB3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Faker.Net.NUnit.Tests", "Faker.Net.NUnit.Tests\Faker.Net.NUnit.Tests.csproj", "{5535BD16-B1E6-40A9-9ADA-502EE21E14BC}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{21F28937-D619-4BDF-8A71-1D55B9E698D0}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Faker.Net/Address.cs b/Faker.Net/Address.cs index c8a12e5..ab35822 100644 --- a/Faker.Net/Address.cs +++ b/Faker.Net/Address.cs @@ -64,14 +64,23 @@ public static string GetStreetName() } } - public static string GetStreetAddress(bool includeSecondary = false){ - var str = (FakerRandom.Rand.Next(3).Times("#")) + ("### " + GetStreetName()); + public static string GetUSStreetAddress(bool includeSecondary = false){ + var str = (FakerRandom.Rand.Next(3).Times("#").Join("")) + ("### " + GetStreetName()); if (includeSecondary) str += " " + GetSecondaryAddress(); return str.Numerify(); } + public static string GetEUStreetAddress(bool includeSecondary = false) + { + var str = GetStreetName() + " " + (FakerRandom.Rand.Next(3).Times("#").Join("")); + if (includeSecondary) + str += " " + GetSecondaryAddress(); + var res = str.Numerify(); + return res; + } + public static string GetSecondaryAddress() { return SEC_ADDR.Rand().Numerify(); @@ -152,9 +161,15 @@ public static string StreetName() } [Obsolete] - public static string StreetAddress(bool includeSecondary = false) + public static string EUStreetAddress(bool includeSecondary = false) { - return GetStreetAddress(includeSecondary); + return GetEUStreetAddress(includeSecondary); + } + + [Obsolete] + public static string USStreetAddress(bool includeSecondary = false) + { + return GetUSStreetAddress(includeSecondary); } [Obsolete] diff --git a/Faker.Net/Extensions/EnumerableExtensions.cs b/Faker.Net/Extensions/EnumerableExtensions.cs index e4090d1..ee6c566 100644 --- a/Faker.Net/Extensions/EnumerableExtensions.cs +++ b/Faker.Net/Extensions/EnumerableExtensions.cs @@ -8,8 +8,10 @@ public static class EnumerableExtensions { public static string Join(this IEnumerable items, string separator) { - return items.Select(i => i.ToString()) + if (items.Any()) + return items.Select(i => i.ToString()) .Aggregate((acc, next) => string.Concat(acc, separator, next)); + return ""; } public static T Rand(this IEnumerable items) diff --git a/Faker.Net/Extensions/StringExtensions.cs b/Faker.Net/Extensions/StringExtensions.cs index 101a810..3f5f0e5 100644 --- a/Faker.Net/Extensions/StringExtensions.cs +++ b/Faker.Net/Extensions/StringExtensions.cs @@ -1,43 +1,43 @@ -using System; +using System; using System.Collections.Generic; -using System.Text; - -namespace Faker.Extensions -{ - public static class StringExtensions - { - public static string Replace(this string str, char item, Func character) - { - StringBuilder builder = new StringBuilder(str.Length); - - foreach (char c in str.ToCharArray()) - { - builder.Append(c == item ? character() : c); - } - - return builder.ToString(); - } - - public static string Numerify(this string number_string) - { - return number_string.Replace('#', () => FakerRandom.Rand.Next(10).ToString().ToCharArray()[0]); - } - - public static string Letterify(this string letter_string) - { - return letter_string.Replace('?', () => 'a'.To('z').Rand()); - } - - public static string Bothify(this string str) - { - return Letterify(Numerify(str)); - } - - public static IEnumerable To(this char from, char to) - { - for(char i = from; i <= to; i++) { - yield return i; - } - } - } -} +using System.Text; + +namespace Faker.Extensions +{ + public static class StringExtensions + { + public static string Replace(this string str, char item, Func character) + { + StringBuilder builder = new StringBuilder(str.Length); + + foreach (char c in str.ToCharArray()) + { + builder.Append(c == item ? character() : c); + } + + return builder.ToString(); + } + + public static string Numerify(this string number_string) + { + return number_string.Replace('#', () => FakerRandom.Rand.Next(10).ToString().ToCharArray()[0]); + } + + public static string Letterify(this string letter_string) + { + return letter_string.Replace('?', () => 'a'.To('z').Rand()); + } + + public static string Bothify(this string str) + { + return Letterify(Numerify(str)); + } + + public static IEnumerable To(this char from, char to) + { + for(char i = from; i <= to; i++) { + yield return i; + } + } + } +} diff --git a/Faker.Net/Faker.Net.csproj b/Faker.Net/Faker.Net.csproj index fc9f995..1ac9bf9 100644 --- a/Faker.Net/Faker.Net.csproj +++ b/Faker.Net/Faker.Net.csproj @@ -9,7 +9,7 @@ Library Properties Faker - Faker + FFaker.Net v4.0 512 diff --git a/Faker.Net/FakerRandom.cs b/Faker.Net/FakerRandom.cs index c466ceb..f4ac889 100644 --- a/Faker.Net/FakerRandom.cs +++ b/Faker.Net/FakerRandom.cs @@ -4,11 +4,30 @@ namespace Faker { public static class FakerRandom { - internal static Random Rand = new Random(); + public static Random Rand = new Random(); public static void Seed(int seed) { Rand = new Random(seed); } + + public static DateTime GetRandomDateTime() + { + return GetRandomDateTime(new DateTime(), DateTime.Now); + } + + public static DateTime GetRandomDateTime(DateTime from) + { + return GetRandomDateTime(from, DateTime.Now); + } + + public static DateTime GetRandomDateTime(DateTime from, DateTime to) + { + var range = to - from; + + var randTimeSpan = new TimeSpan((long)(Rand.NextDouble() * range.Ticks)); + + return from + randTimeSpan; + } } } diff --git a/Faker.Net/Internet.cs b/Faker.Net/Internet.cs index 381f522..3be588a 100644 --- a/Faker.Net/Internet.cs +++ b/Faker.Net/Internet.cs @@ -32,11 +32,17 @@ public static string GetFreeEmail(string name = null) return GetUserName(name) + "@" + HOSTS.Rand(); } + public static string GetUserName(string firstName, string lastName) + { + string parts = new string[]{firstName, lastName}.Join(new[] { ".", "_", "" }.Rand()); + return parts.ToLower(); + } + public static string GetUserName(string name = null) { if (name != null) { - string parts = name.Split(' ').Join(new[] { ".", "_" }.Rand()); + string parts = name.Split(' ').Join(new[] { ".", "_", "" }.Rand()); return parts.ToLower(); } else @@ -149,6 +155,6 @@ public static string IP_V4_Address() private static readonly string[] BYTE; //new [] { ((0..255).to_a.map { |n| n.to_s }) static readonly string[] HOSTS = new[] { "gmail.com", "yahoo.com", "hotmail.com" }; static readonly string[] DISPOSABLE_HOSTS = new[] { "mailinator.com", "suremail.info", "spamherelots.com", "binkmail.com", "safetymail.info", "tempinbox.com" }; - static readonly string[] DOMAIN_SUFFIXES = new[] { "co.uk", "com", "us", "uk", "ca", "biz", "info", "name" }; + static readonly string[] DOMAIN_SUFFIXES = new[] { "co.uk", "com", "us", "uk", "ca", "biz", "info", "name", "be", "eu", "nl", "me" }; } } diff --git a/Faker.Net/Package.nuspec b/Faker.Net/Package.nuspec new file mode 100644 index 0000000..f587f5c --- /dev/null +++ b/Faker.Net/Package.nuspec @@ -0,0 +1,15 @@ + + + + FFaker.Net + $version$ + Jon Wingfield + PulsarBlow + https://github.com/jonwingfield/Faker.Net + https://github.com/PulsarBlow/Faker.Net + $description$ + First NuGet package release. + Copyright (c) 2011, Jon Wingfield (wingfield.jon@gmail.com) + Faker Fake Test Data Generator + + \ No newline at end of file diff --git a/Faker.Net/Properties/AssemblyInfo.cs b/Faker.Net/Properties/AssemblyInfo.cs index 54eddd8..387fe8f 100644 --- a/Faker.Net/Properties/AssemblyInfo.cs +++ b/Faker.Net/Properties/AssemblyInfo.cs @@ -1,35 +1,15 @@ using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Faker.Net")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("FFaker.Net")] +[assembly: AssemblyDescription("As much as possible, a line-for-line port of ffaker for ruby (https://github.com/EmmanuelOga/ffaker). Supports .NET Framework and Mono.")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Faker.Net")] -[assembly: AssemblyCopyright("")] +[assembly: AssemblyCompany("Jon Wingfield")] +[assembly: AssemblyProduct("FFaker.Net")] +[assembly: AssemblyCopyright("Copyright (c) 2011, Jon Wingfield (wingfield.jon@gmail.com)")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("c1626824-b4d0-42ed-a767-02bf6a146c24")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.0.0")] -[assembly: AssemblyFileVersion("1.1.0.0")] +[assembly: AssemblyVersion("1.1.0.5")] +[assembly: AssemblyFileVersion("1.1.0.5")] diff --git a/README.markdown b/README.markdown index 27e9537..f867a4a 100644 --- a/README.markdown +++ b/README.markdown @@ -1,41 +1,12 @@ -Faker.NET -================================================ +# FFaker.Net -As much as possible, a line-for-line port of ffaker for ruby (https://github.com/EmmanuelOga/ffaker). +#### A simple NuGet Package wrapper for Faker.Net -Relies on ideas taken from Rob Conery's and Jon Wingfield's excellent sugar library (https://github.com/jonwingfield/sugar). I have just taken the idea to minimize the assembly's dependencies. +This is the project built upon Faker.Net by Jon Wingfield (https://github.com/jonwingfield/Faker.Net) -Supports .NET Framework and Mono. +It serves as the base project for the FFaker.Net NuGet Package. +For documentation and examples, check : https://github.com/jonwingfield/Faker.Net -Building ------------------------------------------------- - -nant build - -nant build -D:mode=Debug - - -Tests ------------------------------------------------- - -There is a project in the solution named Faker.Net.NUnit.Tests that uses the relevant ffaker tests written in Ruby to test the .NET code. - -NAnt command to run unit-tests - -nant test - -nant test -D:mode=Debug - - -Cleaning build output -------------------------------------------------- - -nant clean - -nant clean -D:mode=Debug - - -Contrib ------------------------------------------------- -This is my first open source project, so any and all feedback/pull requests are welcomed and requested. +##### Why FFaker and not Faker ? +Simply because the name Faker.Net wasn't available on NuGet. \ No newline at end of file diff --git a/package.cmd b/package.cmd new file mode 100644 index 0000000..7e244c0 --- /dev/null +++ b/package.cmd @@ -0,0 +1 @@ +.nuget\NuGet.exe pack ".\Faker.Net\Faker.Net.csproj" -Build -Symbols -Properties Configuration=Release \ No newline at end of file