From ae67270ec5b385d272e7e229f727a442f6ab7d17 Mon Sep 17 00:00:00 2001 From: BeastlyGNome Date: Sat, 2 Feb 2019 09:27:20 -0500 Subject: [PATCH] Added LordOfTheRings faker (#84) * Added requested feature * Added the docs. * Fixed the ordering. * Updated the data class. Closes #84 --- README.md | 1 + doc/lord_of_the_rings.md | 7 + src/FakerDotNet/Data/LordOfTheRingsData.cs | 340 ++++++++++++++++++ src/FakerDotNet/Faker.cs | 1 + src/FakerDotNet/FakerContainer.cs | 3 + src/FakerDotNet/Fakers/LordOfTheRingsFaker.cs | 30 ++ .../FakerDotNet.Tests/FakerContainerTests.cs | 6 + tests/FakerDotNet.Tests/FakerTests.cs | 8 +- .../Fakers/LordOfTheRingsFakerTests.cs | 40 +++ 9 files changed, 435 insertions(+), 1 deletion(-) create mode 100644 doc/lord_of_the_rings.md create mode 100644 src/FakerDotNet/Data/LordOfTheRingsData.cs create mode 100644 src/FakerDotNet/Fakers/LordOfTheRingsFaker.cs create mode 100644 tests/FakerDotNet.Tests/Fakers/LordOfTheRingsFakerTests.cs diff --git a/README.md b/README.md index b20a2a6..794efa9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ A .NET port of the Ruby [faker](https://github.com/stympy/faker) gem - [Faker.Hacker](doc/hacker.md) - [Faker.HarryPotter](doc/harry_potter.md) - [Faker.Internet](doc/internet.md) + - [Faker.LordOfTheRings](doc/lord_of_the_rings.md) - [Faker.Lorem](doc/lorem.md) - [Faker.Music](doc/music.md) - [Faker.Name](doc/name.md) diff --git a/doc/lord_of_the_rings.md b/doc/lord_of_the_rings.md new file mode 100644 index 0000000..bad3c00 --- /dev/null +++ b/doc/lord_of_the_rings.md @@ -0,0 +1,7 @@ +# Faker.LordOfTheRings + +```cs +Faker.LordOfTheRings.Character() //=> "Legolas" + +Faker.LordOfTheRings.Location() //=> "Helm's Deep" +``` \ No newline at end of file diff --git a/src/FakerDotNet/Data/LordOfTheRingsData.cs b/src/FakerDotNet/Data/LordOfTheRingsData.cs new file mode 100644 index 0000000..ada13b0 --- /dev/null +++ b/src/FakerDotNet/Data/LordOfTheRingsData.cs @@ -0,0 +1,340 @@ +using System.Collections.Generic; + +namespace FakerDotNet.Data +{ + internal static class LordOfTheRingsData + { + public static readonly IEnumerable Characters = new[] + { + "Aragorn", + "Arwen", + "Aegnor", + "Aerandir", + "Aerin", + "Aghan", + "Amandil", + "Amarië", + "Amlach", + "Amras", + "Amrod", + "Ancalagon", + "Andreth", + "Andróg", + "Angrim", + "Angrod", + "Annael", + "Ar-Adûnakhôr", + "Ar-Gimilzôr", + "Ar-Pharazôn", + "Ar-Sakalthôr", + "Ar-Zimrathôn", + "Aranwë", + "Aratan", + "Aratar", + "Aredhel", + "Arien", + "Arthad", + "Asgon", + "Aulë", + "Azaghâl", + "Bilbo Baggins", + "Frodo Baggins", + "Barach", + "Baragund", + "Barahir", + "Baran", + "Barliman Butterbur", + "Beechbone", + "Beregond and Bergil", + "Bergil", + "Bilbo", + "Fredegar Bolger", + "Tom Bombadil", + "Meriadoc Brandybuck", + "Bregalad", + "Brego", + "Beleg", + "Belegund", + "Bereg", + "Beren", + "Borlach", + "Borlad", + "Boromir (House of Bëor)", + "Borthand", + "Brandir", + "Bregolas", + "Bregor", + "Brodda", + "Bëor", + "Bór", + "Celeborn", + "Círdan", + "Calmacil", + "Caranthir", + "Carcharoth", + "Celebrimbor", + "Celegorm", + "Ciryon", + "Curufin", + "Déagol", + "Denethor", + "Dúnhere", + "Durin's Bane", + "Daeron", + "Dairuin", + "Dior", + "Dorlas", + "Draugluin", + "Elfhelm", + "Elladan and Elrohir", + "Elrond", + "Éomer", + "Éomund", + "Éothain", + "Éowyn", + "Erestor", + "Erkenbrand", + "Ecthelion of the Fountain", + "Eilinel", + "Elatan", + "Elemmírë", + "Elendil", + "Elendur", + "Elenwë", + "Elros", + "Eluréd and Elurín", + "Elwing", + "Emeldir", + "Erellont", + "Estë", + "Eärendil", + "Eärendur, Lord of Andúnië", + "Eärendur of Arnor", + "Eärendur of Númenor", + "Eärwen", + "Eöl", + "Eönwë", + "Faramir", + "Figwit", + "Forlong the Fat", + "Freda", + "Falathar", + "Finarfin", + "Finduilas", + "Fingolfin", + "Fingon", + "Finrod", + "Finwë", + "Fuinur", + "Fëanor", + "Galadriel", + "Hamfast Gamgee", + "Samwise Gamgee", + "Gamling", + "Gandalf", + "Ghân-buri-Ghân", + "Gildor Inglorion", + "Gimli", + "Glorfindel", + "Goldberry", + "Gollum", + "Gothmog", + "Gríma Wormtongue", + "Grimbold", + "Galdor", + "Gamil Zirak", + "Gelmir", + "Gelmir (of Angrod's kin)", + "Gil-galad", + "Gimilkhâd", + "Glaurung", + "Glirhuin", + "Glóredhel", + "Gorlim", + "Guilin", + "Gundor", + "Gwindor", + "Haldir of Lórien", + "Haleth", + "Háma", + "Húrin the Tall", + "Hador", + "Haldad", + "Haldan", + "Haldar", + "Halmir", + "Handir", + "Hareth", + "Hathaldir", + "Herumor", + "Huan", + "Hundad", + "Hunthor", + "Huor", + "Irolas", + "Isildur", + "Ibûn", + "Idril", + "Ilmarë", + "Eru Ilúvatar", + "Imlach", + "Indis", + "Ingwë", + "Inzilbêth", + "Iorlas", + "Irmo", + "Khim", + "Legolas Greenleaf", + "Lurtz", + "Lalaith", + "Lenwë", + "Lorgan", + "Lúthien", + "Madril", + "Farmer Maggot", + "Morwen", + "Mouth of Sauron", + "Mablung", + "Maedhros", + "Maeglin", + "Maglor", + "Mahtan", + "Malach", + "Mandos", + "Manwë", + "Marach", + "Mardil Voronwë", + "Melian", + "Melkor", + "Meneldil", + "Morwen", + "Míriel", + "Mîm", + "Nazgûl", + "Nerdanel", + "Nessa", + "Nienna", + "Nimloth", + "Nimrodel", + "Niënor", + "Númendil", + "Old Man Willow", + "Orophin", + "Ohtar", + "Olwë", + "Orodreth", + "Oromë", + "Ossë", + "Radagast", + "Radhruin", + "Ragnor", + "Rían", + "Rúmil (Noldo)", + "Samwise Gamgee", + "Saruman", + "Sauron", + "Sharku", + "Shelob", + "Smaug", + "Sador", + "Saeros", + "Salmar", + "Soronto", + "Théoden", + "Théodred", + "Peregrin Took", + "Treebeard", + "Tar-Alcarin", + "Tar-Aldarion", + "Tar-Ancalimon", + "Tar-Ancalimë", + "Tar-Anárion", + "Tar-Ardamin", + "Tar-Atanamir", + "Tar-Calmacil", + "Tar-Ciryatan", + "Tar-Elendil", + "Tar-Minastir", + "Tar-Míriel", + "Tar-Palantir", + "Tar-Súrion", + "Tar-Telemmaitë", + "Tar-Telperiën", + "Tar-Vanimeldë", + "Telchar", + "Thingol", + "Thorondor", + "Thuringwethil", + "Tilion", + "Valar", + "Witch-king of Angmar" + }; + + public static readonly IEnumerable Locations = new[] + { + "Almaren", + "Amon Hen", + "Andram, The Long Wall", + "Anduin", + "Arnor", + "Bag End", + "Barad-dûr", + "Baranduin", + "Beleriand", + "Belegaer, The Great Sea", + "Blue Mountains", + "Bree-land", + "Brithon", + "Bruinen", + "Cuiviénen", + "Dorthonion", + "Erebor", + "Ered Luin", + "Ered Mithrin", + "Ered Nimrais", + "Eriador", + "Esgaroth", + "Falas", + "Fangorn", + "Forodwaith", + "Gelion", + "Gondolin", + "Gondor", + "Great East Road", + "Harad", + "Helm's Deep", + "Himring", + "Hithlum", + "Isengard", + "Khazad-dûm", + "Lindon & the Grey Havens", + "Lonely Mountains", + "Lothlórien", + "Minas Tirith", + "Mirkwood", + "Misty Mountains", + "Mordor", + "Mount Doom", + "Nenning", + "Nevrast", + "North-South Road", + "Ossiriand, The Land of Seven Rivers", + "Rhovanion", + "Rhûn", + "Rivendell", + "Rohan", + "Running River", + "Sirion", + "Thangorodrim", + "The Fens of Sirion", + "The Gates of Sirion", + "The Necromancer", + "The Shire", + "The Two Lamps", + "The White Mountains", + "Théoden", + "Weathertop", + "Wilderland", + }; + } +} diff --git a/src/FakerDotNet/Faker.cs b/src/FakerDotNet/Faker.cs index cc8761d..cc6ab10 100644 --- a/src/FakerDotNet/Faker.cs +++ b/src/FakerDotNet/Faker.cs @@ -31,6 +31,7 @@ public static class Faker public static IHackerFaker Hacker { get; } = Container.Hacker; public static IHarryPotterFaker HarryPotter { get; } = Container.HarryPotter; public static IInternetFaker Internet { get; } = Container.Internet; + public static ILordOfTheRingsFaker LordOfTheRings { get; } = Container.LordOfTheRings; public static ILoremFaker Lorem { get; } = Container.Lorem; public static IMusicFaker Music { get; } = Container.Music; public static INameFaker Name { get; } = Container.Name; diff --git a/src/FakerDotNet/FakerContainer.cs b/src/FakerDotNet/FakerContainer.cs index 4368984..30a2758 100644 --- a/src/FakerDotNet/FakerContainer.cs +++ b/src/FakerDotNet/FakerContainer.cs @@ -29,6 +29,7 @@ internal interface IFakerContainer IHackerFaker Hacker { get; } IHarryPotterFaker HarryPotter { get; } IInternetFaker Internet { get; } + ILordOfTheRingsFaker LordOfTheRings { get; } ILoremFaker Lorem { get; } IMusicFaker Music { get; } INameFaker Name { get; } @@ -80,6 +81,7 @@ public FakerContainer() Hacker = new HackerFaker(this); HarryPotter = new HarryPotterFaker(this); Internet = new InternetFaker(this); + LordOfTheRings = new LordOfTheRingsFaker(this); Lorem = new LoremFaker(this); Music = new MusicFaker(this); Name = new NameFaker(this); @@ -127,6 +129,7 @@ public FakerContainer() public IHackerFaker Hacker { get; } public IHarryPotterFaker HarryPotter { get; } public IInternetFaker Internet { get; } + public ILordOfTheRingsFaker LordOfTheRings { get; } public ILoremFaker Lorem { get; } public IMusicFaker Music { get; } public INameFaker Name { get; } diff --git a/src/FakerDotNet/Fakers/LordOfTheRingsFaker.cs b/src/FakerDotNet/Fakers/LordOfTheRingsFaker.cs new file mode 100644 index 0000000..6bff6a4 --- /dev/null +++ b/src/FakerDotNet/Fakers/LordOfTheRingsFaker.cs @@ -0,0 +1,30 @@ +using FakerDotNet.Data; + +namespace FakerDotNet.Fakers +{ + public interface ILordOfTheRingsFaker + { + string Character(); + string Location(); + } + + internal class LordOfTheRingsFaker : ILordOfTheRingsFaker + { + private readonly IFakerContainer _fakerContainer; + + public LordOfTheRingsFaker(IFakerContainer fakerContainer) + { + _fakerContainer = fakerContainer; + } + + public string Character() + { + return _fakerContainer.Random.Element(LordOfTheRingsData.Characters); + } + + public string Location() + { + return _fakerContainer.Random.Element(LordOfTheRingsData.Locations); + } + } +} diff --git a/tests/FakerDotNet.Tests/FakerContainerTests.cs b/tests/FakerDotNet.Tests/FakerContainerTests.cs index 629f417..6f1c06f 100644 --- a/tests/FakerDotNet.Tests/FakerContainerTests.cs +++ b/tests/FakerDotNet.Tests/FakerContainerTests.cs @@ -165,6 +165,12 @@ public void Internet_returns_IInternetFaker() Assert.IsInstanceOf(_fakerContainer.Internet); } + [Test] + public void LordOfTheRings_returns_ILordOfTheRingsFaker() + { + Assert.IsInstanceOf(_fakerContainer.LordOfTheRings); + } + [Test] public void Lorem_returns_ILoremFaker() { diff --git a/tests/FakerDotNet.Tests/FakerTests.cs b/tests/FakerDotNet.Tests/FakerTests.cs index 74fa068..c01399a 100644 --- a/tests/FakerDotNet.Tests/FakerTests.cs +++ b/tests/FakerDotNet.Tests/FakerTests.cs @@ -157,6 +157,12 @@ public void Internet_returns_IInternetFaker() Assert.IsInstanceOf(Faker.Internet); } + [Test] + public void LordOfTheRings_returns_ILordOfTheRingsFaker() + { + Assert.IsInstanceOf(Faker.LordOfTheRings); + } + [Test] public void Lorem_returns_ILoremFaker() { @@ -234,7 +240,7 @@ public void StarWars_returns_IStarWarsFaker() { Assert.IsInstanceOf(Faker.StarWars); } - + [Test] public void Superhero_returns_ISuperheroFaker() { diff --git a/tests/FakerDotNet.Tests/Fakers/LordOfTheRingsFakerTests.cs b/tests/FakerDotNet.Tests/Fakers/LordOfTheRingsFakerTests.cs new file mode 100644 index 0000000..986c547 --- /dev/null +++ b/tests/FakerDotNet.Tests/Fakers/LordOfTheRingsFakerTests.cs @@ -0,0 +1,40 @@ +using FakeItEasy; +using FakerDotNet.Data; +using FakerDotNet.Fakers; +using NUnit.Framework; + +namespace FakerDotNet.Tests.Fakers +{ + [TestFixture] + [Parallelizable] + public class LordOfTheRingsFakerTests + { + [SetUp] + public void SetUp() + { + _fakerContainer = A.Fake(); + _lordOfTheRingsFaker = new LordOfTheRingsFaker(_fakerContainer); + } + + private IFakerContainer _fakerContainer; + private ILordOfTheRingsFaker _lordOfTheRingsFaker; + + [Test] + public void Character_Returns_a_Character() + { + A.CallTo(() => _fakerContainer.Random.Element(LordOfTheRingsData.Characters)) + .Returns("Legolas"); + + Assert.AreEqual("Legolas", _lordOfTheRingsFaker.Character()); + } + + [Test] + public void Location_Returns_a_Location() + { + A.CallTo(() => _fakerContainer.Random.Element(LordOfTheRingsData.Locations)) + .Returns("Helm's Deep"); + + Assert.AreEqual("Helm's Deep", _lordOfTheRingsFaker.Location()); + } + } +}