-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Faker.Demographic | ||
|
||
```cs | ||
Faker.Demographic.Race() //=> "Native Hawaiian or Other Pacific Islander" | ||
Faker.Demographic.EducationalAttainment() //=> "GED or alternative credential" | ||
Faker.Demographic.Demonym() //=> "Panamanian" | ||
Faker.Demographic.MaritalStatus() //=> "Widowed" | ||
Faker.Demographic.Sex() //=> "Female" | ||
Faker.Demographic.Height() //=> "1.61" | ||
Faker.Demographic.Height(UnitType.Imperial) //=> "6 ft, 2 in" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FakerDotNet.Data | ||
{ | ||
internal static class DemographicData | ||
{ | ||
public static readonly IEnumerable<string> Races = new[] | ||
{ | ||
"American Indian or Alaska Native", | ||
"Asian", | ||
"Black or African American", | ||
"Native Hawaiian or Other Pacific Islander", | ||
"White" | ||
}; | ||
|
||
public static readonly IEnumerable<string> Sexes = new[] | ||
{ | ||
"Male", | ||
"Female" | ||
}; | ||
|
||
public static readonly IEnumerable<string> Demonyms = new[] | ||
{ | ||
"Afghan","Albanian","Algerian","American","Andorran","Angolan","Argentine","Armenian","Aromanian","Aruban","Australian","Austrian","Azerbaijani","Bahamian","Bahraini","Bangladeshi","Barbadian","Basotho","Basque","Belarusian","Belgian","Belizean","Bermudian","Bissau-Guinean","Boer","Bosniak","Brazilian","Breton","Briton","British Virgin Islander","Bruneian","Bulgarian","Burkinabè","Burundian","Cambodian","Cameroonian","Canadian","Catalan","Cape Verdean","Chadian","Chilean","Chinese","Colombian","Comorian","Congolese","Croatian","Cuban","Cypriot","Czech","Dane","Dominican","Dutch","East Timorese","Ecuadorian","Egyptian","Emirati","English","Eritrean","Estonian","Ethiopian","Falkland Islander","Faroese","Finn","Fijian","Filipino","French","Georgian","German","Ghanaian","Gibraltar","Greek","Grenadian","Guatemalan","French Guianan","Guinean","Guyanese","Haitian","Honduran","Hong Konger","Hungarian","Icelander","I-Kiribati","Indian","Indonesian","Iranian","Iraqi","Irish","Israeli","Italian","Ivoirian","Jamaican","Japanese","Jordanian","Kazakh","Kenyan","Korean","Kosovar","Kurd","Kuwaiti","Kyrgyz","Lao","Latvian","Lebanese","Liberian","Libyan","Liechtensteiner","Lithuanian","Luxembourger","Macanese","Macedonian","Malagasy","Malaysian","Malawian","Maldivian","Malian","Maltese","Manx","Mauritian","Mexican","Moldovan","Moroccan","Mongolian","Montenegrin","Namibian","Nepalese","New Zealander","Nicaraguan","Nigerien","Nigerian","Norwegian","Pakistani","Palauan","Palestinian","Panamanian","Papua New Guinean","Paraguayan","Peruvian","Pole","Portuguese","Puerto Rican","Quebecer","Romanian","Russian","Rwandan","Salvadoran","São Toméan","Saudi","Scottish","Senegalese","Serb","Sierra Leonean","Singaporean","Sindhian","Slovak","Slovene","Somali","Somalilander","South African","Spaniard","Sri Lankan","St Lucian","Sudanese","Surinamese","Swede","Swiss","Syriac","Syrian","Tajik","Taiwanese","Tanzanian","Thai","Tibetan","Tobagonian","Trinidadian","Tunisian","Turk","Tuvaluan","Ugandan","Ukrainian","Uruguayan","Uzbek","Vanuatuan","Venezuelan","Vietnamese","Welsh","Yemeni","Zambian","Zimbabwean" | ||
}; | ||
|
||
public static readonly IEnumerable<string> EducationalAttainments = new[] | ||
{ | ||
"No schooling completed", | ||
"Nursery school", | ||
"Kindergarten", | ||
"Grade 1 though 11", | ||
"12th grade - No Diploma", | ||
"Regular high school diploma", | ||
"GED or alternative credential", | ||
"Some college", | ||
"Associate's degree", | ||
"Bachelor's degree", | ||
"Master's degree", | ||
"Professional degree", | ||
"Doctorate degree" | ||
}; | ||
|
||
public static readonly IEnumerable<string> MaritalStatuses = new[] | ||
{ | ||
"Married", | ||
"Widowed", | ||
"Divorced", | ||
"Separated", | ||
"Never married" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using FakerDotNet.Data; | ||
|
||
namespace FakerDotNet.Fakers | ||
{ | ||
public interface IDemographicFaker | ||
{ | ||
string Race(); | ||
string EducationalAttainment(); | ||
string Demonym(); | ||
string MaritalStatus(); | ||
string Sex(); | ||
string Height(UnitType unitType = UnitType.Metric); | ||
} | ||
|
||
internal class DemographicFaker : IDemographicFaker | ||
{ | ||
private readonly IFakerContainer _fakerContainer; | ||
|
||
public DemographicFaker(IFakerContainer fakerContainer) | ||
{ | ||
_fakerContainer = fakerContainer; | ||
} | ||
|
||
public string Race() | ||
{ | ||
return _fakerContainer.Random.Element(DemographicData.Races); | ||
} | ||
|
||
public string EducationalAttainment() | ||
{ | ||
return _fakerContainer.Random.Element(DemographicData.EducationalAttainments); | ||
} | ||
|
||
public string Demonym() | ||
{ | ||
return _fakerContainer.Random.Element(DemographicData.Demonyms); | ||
} | ||
|
||
public string MaritalStatus() | ||
{ | ||
return _fakerContainer.Random.Element(DemographicData.MaritalStatuses); | ||
} | ||
|
||
public string Sex() | ||
{ | ||
return _fakerContainer.Random.Element(DemographicData.Sexes); | ||
} | ||
|
||
public string Height(UnitType unitType = UnitType.Metric) | ||
{ | ||
switch (unitType) | ||
{ | ||
case UnitType.Imperial: | ||
var inches = _fakerContainer.Number.Between(57, 86); | ||
return $"{inches / 12:#} ft, {inches % 12} in"; | ||
|
||
default: | ||
return _fakerContainer.Number.Between(1.45, 2.13).ToString("#.##"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace FakerDotNet | ||
{ | ||
public enum UnitType | ||
{ | ||
Metric, | ||
Imperial | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using FakeItEasy; | ||
using FakerDotNet.Data; | ||
using FakerDotNet.Fakers; | ||
using NUnit.Framework; | ||
|
||
namespace FakerDotNet.Tests.Fakers | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class DemographicFakerTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fakerContainer = A.Fake<IFakerContainer>(); | ||
_demographicFaker = new DemographicFaker(_fakerContainer); | ||
} | ||
|
||
private IFakerContainer _fakerContainer; | ||
private IDemographicFaker _demographicFaker; | ||
|
||
[Test] | ||
public void Race_returns_a_race() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(DemographicData.Races)) | ||
.Returns("Native Hawaiian or Other Pacific Islander"); | ||
|
||
Assert.AreEqual("Native Hawaiian or Other Pacific Islander", _demographicFaker.Race()); | ||
} | ||
|
||
[Test] | ||
public void EducationalAttainment_returns_an_educational_attainment() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(DemographicData.EducationalAttainments)) | ||
.Returns("GED or alternative credential"); | ||
|
||
Assert.AreEqual("GED or alternative credential", _demographicFaker.EducationalAttainment()); | ||
} | ||
|
||
[Test] | ||
public void Demonym_returns_a_demonym() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(DemographicData.Demonyms)) | ||
.Returns("Panamanian"); | ||
|
||
Assert.AreEqual("Panamanian", _demographicFaker.Demonym()); | ||
} | ||
|
||
[Test] | ||
public void MaritalStatus_returns_a_marital_status() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(DemographicData.MaritalStatuses)) | ||
.Returns("Widowed"); | ||
|
||
Assert.AreEqual("Widowed", _demographicFaker.MaritalStatus()); | ||
} | ||
|
||
[Test] | ||
public void Sex_returns_a_sex() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(DemographicData.Sexes)) | ||
.Returns("Female"); | ||
|
||
Assert.AreEqual("Female", _demographicFaker.Sex()); | ||
} | ||
|
||
[Test] | ||
public void Height_returns_a_height_in_metric_units() | ||
{ | ||
A.CallTo(() => _fakerContainer.Number.Between(1.45, 2.13)) | ||
.Returns(1.613243); | ||
|
||
Assert.AreEqual("1.61", _demographicFaker.Height()); | ||
} | ||
|
||
[Test] | ||
public void Height_returns_a_height_in_imperial_units_when_specified() | ||
{ | ||
A.CallTo(() => _fakerContainer.Number.Between(57, 86)) | ||
.Returns(74); | ||
|
||
Assert.AreEqual("6 ft, 2 in", _demographicFaker.Height(UnitType.Imperial)); | ||
} | ||
} | ||
} |