Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding constructor overloading in Faker, Faker<T> and DataSet #568

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Source/Bogus.Tests/HandlebarsTests/ArgumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ public ArgumentsTest(ITestOutputHelper console)
this.console = console;
}

[Fact]
public void can_instantiate_faker_with_locale_type()
{
var faker = new Faker(LocaleType.pt_BR);
}

[Fact]
public void can_instantiate_faker_t_with_locale_type()
{
var faker = new Faker<Person>(LocaleType.fr);
}

[Fact]
public void can_instantiate_dataset_with_locale_type()
{
var dataset = new DataSet(LocaleType.ko);
}

[Fact]
public void can_parse_random_number_request_without_arguments()
Expand Down
13 changes: 12 additions & 1 deletion Source/Bogus/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public DataSet(string locale = "en")
this.Category = ResolveCategory(this.GetType());
}

/// <summary>
/// Initializes a new instance of the <see cref="DataSet"/> class.
/// </summary>
/// <param name="localeType">The locale wanting to be set.</param>
/// <exception cref="BogusException">
/// When the given <paramref name="localeType"/> isn't found.
/// </exception>
public DataSet(LocaleType localeType) : this(localeType.ToString())
{
}

/// <summary>
/// Gets or sets the category name inside the locale.
/// </summary>
Expand All @@ -39,7 +50,7 @@ public DataSet(string locale = "en")
/// Gets or sets the current locale of the data set.
/// </summary>
public string Locale { get; set; }

/// <summary>
/// See <see cref="SeedNotifier"/>.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion Source/Bogus/Faker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ public Faker(string locale = "en")

this.Music = this.Notifier.Flow(new Music());

this.Hashids = new Hashids();
this.Hashids = new Hashids();
}

/// <summary>
/// Create a Faker with a specific locale.
/// </summary>
public Faker(LocaleType localeType) : this(localeType.ToString())
{
}

Dictionary<string, object> IHasContext.Context { get; } = new Dictionary<string, object>();
Expand Down
13 changes: 10 additions & 3 deletions Source/Bogus/Faker[T].cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,28 @@ public Faker<T> Clone()
/// The current locale.
/// </summary>
public string Locale { get; set; }

/// <summary>
/// Creates a Faker with default 'en' locale.
/// </summary>
public Faker() : this("en", null)
{
}

/// <summary>
/// Creates a Faker with a locale
/// </summary>
public Faker(string locale) : this(locale, null)
{
}

/// <summary>
/// Creates a Faker with a locale
/// </summary>
public Faker(LocaleType localeType) : this(localeType.ToString(), null)
{
}

/// <summary>
/// Creates a Faker with a locale.
/// </summary>
Expand All @@ -147,7 +154,7 @@ public Faker(string locale) : this(locale, null)
public Faker(string locale = "en", IBinder binder = null)
{
this.binder = binder ?? new Binder();
this.Locale = locale;
this.Locale = locale;
FakerHub = new Faker(locale);
TypeProperties = this.binder.GetMembers(typeof(T));
this.CreateActions[Default] = faker => Activator.CreateInstance<T>();
Expand Down
258 changes: 257 additions & 1 deletion Source/Bogus/ILocaleAware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,260 @@ public interface ILocaleAware
public interface IHasContext
{
Dictionary<string, object> Context { get; }
}
}

/// <summary>
/// Represents all locales available for use, with language or dialect information and respective country or region.
/// </summary>
public enum LocaleType
{
/// <summary>
/// Afrikaans language (South Africa).
/// </summary>
af_ZA,

/// <summary>
/// Arabic language.
/// </summary>
ar,

/// <summary>
/// Azerbaijani language (Azerbaijan).
/// </summary>
az,

/// <summary>
/// Czech language (Czech Republic).
/// </summary>
cz,

/// <summary>
/// German language (Germany).
/// </summary>
de,

/// <summary>
/// German language (Austria).
/// </summary>
de_AT,

/// <summary>
/// German language (Switzerland).
/// </summary>
de_CH,

/// <summary>
/// Greek language (Greece).
/// </summary>
el,

/// <summary>
/// English language.
/// </summary>
en,

/// <summary>
/// English language (Australia).
/// </summary>
en_AU,

/// <summary>
/// English language (Australia Ocker).
/// </summary>
en_AU_ocker,

/// <summary>
/// English language in Bork dialect (fictional/humorous).
/// </summary>
en_BORK,

/// <summary>
/// English language (Canada).
/// </summary>
en_CA,

/// <summary>
/// English language (United Kingdom).
/// </summary>
en_GB,

/// <summary>
/// English language (Ireland).
/// </summary>
en_IE,

/// <summary>
/// English language (India).
/// </summary>
en_IND,

/// <summary>
/// English language (Nigeria).
/// </summary>
en_NG,

/// <summary>
/// English language (United States).
/// </summary>
en_US,

/// <summary>
/// English language (South Africa).
/// </summary>
en_ZA,

/// <summary>
/// Spanish language.
/// </summary>
es,

/// <summary>
/// Spanish language (Mexico).
/// </summary>
es_MX,

/// <summary>
/// Persian language (Iran).
/// </summary>
fa,

/// <summary>
/// Finnish language (Finland).
/// </summary>
fi,

/// <summary>
/// French language (France).
/// </summary>
fr,

/// <summary>
/// French language (Canada).
/// </summary>
fr_CA,

/// <summary>
/// French language (Switzerland).
/// </summary>
fr_CH,

/// <summary>
/// Georgian language (Georgia).
/// </summary>
ge,

/// <summary>
/// Croatian language (Croatia).
/// </summary>
hr,

/// <summary>
/// Indonesian language (Indonesia).
/// </summary>
id_ID,

/// <summary>
/// Italian language (Italy).
/// </summary>
it,

/// <summary>
/// Japanese language (Japan).
/// </summary>
ja,

/// <summary>
/// Korean language (South Korea).
/// </summary>
ko,

/// <summary>
/// Latvian language (Latvia).
/// </summary>
lv,

/// <summary>
/// Norwegian language (Bokm�l dialect, Norway).
/// </summary>
nb_NO,

/// <summary>
/// Nepali language (Nepal).
/// </summary>
ne,

/// <summary>
/// Dutch language (Netherlands).
/// </summary>
nl,

/// <summary>
/// Dutch language (Belgium).
/// </summary>
nl_BE,

/// <summary>
/// Polish language (Poland).
/// </summary>
pl,

/// <summary>
/// Portuguese language (Brazil).
/// </summary>
pt_BR,

/// <summary>
/// Portuguese language (Portugal).
/// </summary>
pt_PT,

/// <summary>
/// Romanian language (Romania).
/// </summary>
ro,

/// <summary>
/// Russian language (Russia).
/// </summary>
ru,

/// <summary>
/// Slovak language (Slovakia).
/// </summary>
sk,

/// <summary>
/// Swedish language (Sweden).
/// </summary>
sv,

/// <summary>
/// Turkish language (Turkey).
/// </summary>
tr,

/// <summary>
/// Ukrainian language (Ukraine).
/// </summary>
uk,

/// <summary>
/// Vietnamese language (Vietnam).
/// </summary>
vi,

/// <summary>
/// Chinese language (Simplified, China).
/// </summary>
zh_CN,

/// <summary>
/// Chinese language (Traditional, Taiwan).
/// </summary>
zh_TW,

/// <summary>
/// Zulu language (South Africa).
/// </summary>
zu_ZA
}