diff --git a/README.md b/README.md index d250111..8439c50 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ A .NET port of the Ruby [faker](https://github.com/stympy/faker) gem - [Faker.Company](doc/company.md) - [Faker.Date](doc/date.md) - [Faker.DragonBall](doc/dragon_ball.md) + - [Faker.Educator](doc/educator.md) - [Faker.Fake](doc/fake.md) - [Faker.File](doc/file.md) - [Faker.Fillmurray](doc/fillmurray.md) diff --git a/doc/educator.md b/doc/educator.md new file mode 100644 index 0000000..ee8ea1e --- /dev/null +++ b/doc/educator.md @@ -0,0 +1,13 @@ +# Faker.Educator + +```cs +Faker.Educator.University() //=> "Mallowtown Technical College" + +Faker.Educator.SecondarySchool() //=> "Iceborough Secondary College" + +Faker.Educator.Degree() //=> "Associate Degree in Criminology" + +Faker.Educator.CourseName() //=> "Criminology 101" + +Faker.Educator.Campus() //=> "Vertapple Campus" +``` \ No newline at end of file diff --git a/src/FakerDotNet/Data/EducatorData.cs b/src/FakerDotNet/Data/EducatorData.cs new file mode 100644 index 0000000..6081955 --- /dev/null +++ b/src/FakerDotNet/Data/EducatorData.cs @@ -0,0 +1,84 @@ +using System.Collections.Generic; + +namespace FakerDotNet.Data +{ + internal static class EducatorData + { + public static readonly IEnumerable Names = new[] + { + "Marblewald", + "Mallowtow", + "Brookville", + "Flowerlake", + "Falconholt", + "Ostbarrow", + "Lakeacre", + "Clearcourt", + "Ironston", + "Mallowpond", + "Iceborough", + "Icelyn", + "Brighthurst", + "Bluemeadow", + "Vertapple", + "Ironbarrow" + }; + + public static readonly IEnumerable SecondaryNames = new[] + { + "High School", + "Secondary College", + "High" + }; + + public static readonly IEnumerable Types = new[] + { + "College", + "University", + "Technical College", + "TAFE" + }; + + public static readonly IEnumerable DegreeSubjects = new[] + { + "Arts", + "Business", + "Education", + "Applied Science (Psychology)", + "Architectural Technology", + "Biological Science", + "Biomedical Science", + "Commerce", + "Communications", + "Creative Arts", + "Criminology", + "Design", + "Engineering", + "Forensic Science", + "Health Science", + "Information Systems", + "Computer Science", + "Law", + "Nursing", + "Medicine", + "Psychology", + "Teaching" + }; + + public static readonly IEnumerable DegreeTypes = new[] + { + "Associate Degree in", + "Bachelor of", + "Master of" + }; + + public static readonly IEnumerable CourseNumbers = new[] + { + "1##", + "2##", + "3##", + "4##", + "5##" + }; + } +} diff --git a/src/FakerDotNet/Faker.cs b/src/FakerDotNet/Faker.cs index 2635e50..ff01837 100644 --- a/src/FakerDotNet/Faker.cs +++ b/src/FakerDotNet/Faker.cs @@ -21,6 +21,7 @@ public static class Faker public static ICompanyFaker Company { get; } = Container.Company; public static IDateFaker Date { get; } = Container.Date; public static IDragonBallFaker DragonBall { get; } = Container.DragonBall; + public static IEducatorFaker Educator { get; } = Container.Educator; public static IFakeFaker Fake { get; } = Container.Fake; public static IFileFaker File { get; } = Container.File; public static IFillmurrayFaker Fillmurray { get; } = Container.Fillmurray; diff --git a/src/FakerDotNet/FakerContainer.cs b/src/FakerDotNet/FakerContainer.cs index 20c68f0..5df3b96 100644 --- a/src/FakerDotNet/FakerContainer.cs +++ b/src/FakerDotNet/FakerContainer.cs @@ -19,6 +19,7 @@ internal interface IFakerContainer ICompanyFaker Company { get; } IDateFaker Date { get; } IDragonBallFaker DragonBall { get; } + IEducatorFaker Educator { get; } IFakeFaker Fake { get; } IFileFaker File { get; } IFillmurrayFaker Fillmurray { get; } @@ -68,6 +69,7 @@ public FakerContainer() Company = new CompanyFaker(this); Date = new DateFaker(); DragonBall = new DragonBallFaker(this); + Educator = new EducatorFaker(this); Fake = new FakeFaker(this); File = new FileFaker(this); Fillmurray = new FillmurrayFaker(); @@ -113,6 +115,7 @@ public FakerContainer() public ICompanyFaker Company { get; } public IDateFaker Date { get; } public IDragonBallFaker DragonBall { get; } + public IEducatorFaker Educator { get; } public IFakeFaker Fake { get; } public IFileFaker File { get; } public IFillmurrayFaker Fillmurray { get; } diff --git a/src/FakerDotNet/Fakers/EducatorFaker.cs b/src/FakerDotNet/Fakers/EducatorFaker.cs new file mode 100644 index 0000000..da4fcdd --- /dev/null +++ b/src/FakerDotNet/Fakers/EducatorFaker.cs @@ -0,0 +1,65 @@ +using System; +using System.Text.RegularExpressions; +using FakerDotNet.Data; + +namespace FakerDotNet.Fakers +{ + public interface IEducatorFaker + { + string University(); + string SecondarySchool(); + string Degree(); + string CourseName(); + string Campus(); + } + + internal class EducatorFaker : IEducatorFaker + { + private readonly IFakerContainer _fakerContainer; + + public EducatorFaker(IFakerContainer fakerContainer) + { + _fakerContainer = fakerContainer; + } + + public string University() + { + return string.Join(" ", + _fakerContainer.Random.Element(EducatorData.Names), + _fakerContainer.Random.Element(EducatorData.Types)); + } + + public string SecondarySchool() + { + return string.Join(" ", + _fakerContainer.Random.Element(EducatorData.Names), + _fakerContainer.Random.Element(EducatorData.SecondaryNames)); + } + + public string Degree() + { + return string.Join(" ", + _fakerContainer.Random.Element(EducatorData.DegreeTypes), + _fakerContainer.Random.Element(EducatorData.DegreeSubjects)); + } + + public string CourseName() + { + return string.Join(" ", + _fakerContainer.Random.Element(EducatorData.DegreeSubjects), + Numerify(_fakerContainer.Random.Element(EducatorData.CourseNumbers))); + } + + public string Campus() + { + return string.Join(" ", + _fakerContainer.Random.Element(EducatorData.Names), + "Campus"); + } + + private string Numerify(string text) + { + return Regex.Replace(text, "#", m => _fakerContainer.Number.Digit()); + } + } +} diff --git a/tests/FakerDotNet.Tests/FakerContainerTests.cs b/tests/FakerDotNet.Tests/FakerContainerTests.cs index ec94c22..e34404a 100644 --- a/tests/FakerDotNet.Tests/FakerContainerTests.cs +++ b/tests/FakerDotNet.Tests/FakerContainerTests.cs @@ -105,6 +105,12 @@ public void DragonBall_returns_IDragonBallFaker() Assert.IsInstanceOf(_fakerContainer.DragonBall); } + [Test] + public void Educator_returns_IEducatorFaker() + { + Assert.IsInstanceOf(_fakerContainer.Educator); + } + [Test] public void Fake_returns_IFakeFaker() { diff --git a/tests/FakerDotNet.Tests/FakerTests.cs b/tests/FakerDotNet.Tests/FakerTests.cs index 36ef08a..0837bad 100644 --- a/tests/FakerDotNet.Tests/FakerTests.cs +++ b/tests/FakerDotNet.Tests/FakerTests.cs @@ -97,6 +97,12 @@ public void DragonBall_returns_IDragonBallFaker() Assert.IsInstanceOf(Faker.DragonBall); } + [Test] + public void Educator_returns_IEducatorFaker() + { + Assert.IsInstanceOf(Faker.Educator); + } + [Test] public void Fake_returns_IFakeFaker() { diff --git a/tests/FakerDotNet.Tests/Fakers/EducatorFakerTests.cs b/tests/FakerDotNet.Tests/Fakers/EducatorFakerTests.cs new file mode 100644 index 0000000..2ebd448 --- /dev/null +++ b/tests/FakerDotNet.Tests/Fakers/EducatorFakerTests.cs @@ -0,0 +1,77 @@ +using FakeItEasy; +using FakerDotNet.Data; +using FakerDotNet.Fakers; +using NUnit.Framework; + +namespace FakerDotNet.Tests.Fakers +{ + [TestFixture] + [Parallelizable] + public class EducatorFakerTests + { + [SetUp] + public void SetUp() + { + _fakerContainer = A.Fake(); + _educatorFaker = new EducatorFaker(_fakerContainer); + } + + private IFakerContainer _fakerContainer; + private IEducatorFaker _educatorFaker; + + [Test] + public void University_returns_a_university() + { + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.Names)) + .Returns("Mallowtown"); + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.Types)) + .Returns("Technical College"); + + Assert.AreEqual("Mallowtown Technical College", _educatorFaker.University()); + } + + [Test] + public void SecondarySchool_returns_a_secondary_school() + { + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.Names)) + .Returns("Iceborough"); + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.SecondaryNames)) + .Returns("Secondary College"); + + Assert.AreEqual("Iceborough Secondary College", _educatorFaker.SecondarySchool()); + } + + [Test] + public void Degree_returns_a_degree() + { + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.DegreeTypes)) + .Returns("Associate Degree in"); + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.DegreeSubjects)) + .Returns("Criminology"); + + Assert.AreEqual("Associate Degree in Criminology", _educatorFaker.Degree()); + } + + [Test] + public void CourseName_returns_a_course_name() + { + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.DegreeSubjects)) + .Returns("Criminology"); + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.CourseNumbers)) + .Returns("1##"); + A.CallTo(() => _fakerContainer.Number.Digit()) + .ReturnsNextFromSequence("0", "1"); + + Assert.AreEqual("Criminology 101", _educatorFaker.CourseName()); + } + + [Test] + public void Campus_returns_a_campus() + { + A.CallTo(() => _fakerContainer.Random.Element(EducatorData.Names)) + .Returns("Vertapple"); + + Assert.AreEqual("Vertapple Campus", _educatorFaker.Campus()); + } + } +}