From d902e0cb213118ab41caeb1b30d0d0a8566a0f59 Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Tue, 29 Jan 2019 08:03:39 +0000 Subject: [PATCH] Added the StarWars faker (#103) * Added the documentation. * Added data for the StarWars faker. * Set up the faker classes. * Added the StarWarsFaker class to the main faker classes. * Finished implementing the StarWars faker. --- README.md | 1 + doc/star_wars.md | 25 + src/FakerDotNet/Data/StarWarsData.cs | 630 ++++++++++++++++++ src/FakerDotNet/Faker.cs | 1 + src/FakerDotNet/FakerContainer.cs | 3 + src/FakerDotNet/Fakers/StarWarsFaker.cs | 112 ++++ .../FakerDotNet.Tests/FakerContainerTests.cs | 6 + tests/FakerDotNet.Tests/FakerTests.cs | 17 +- .../Fakers/StarWarsFakerTests.cs | 153 +++++ 9 files changed, 943 insertions(+), 5 deletions(-) create mode 100644 doc/star_wars.md create mode 100644 src/FakerDotNet/Data/StarWarsData.cs create mode 100644 src/FakerDotNet/Fakers/StarWarsFaker.cs create mode 100644 tests/FakerDotNet.Tests/Fakers/StarWarsFakerTests.cs diff --git a/README.md b/README.md index 6137ae8..71b83db 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ A .NET port of the Ruby [faker](https://github.com/stympy/faker) gem - [Faker.RickAndMorty](doc/rick_and_morty.md) - [Faker.RockBand](doc/rockband.md) - [Faker.SlackEmoji](doc/slackemoji.md) + - [Faker.StarWars](doc/star_wars.md) - [Faker.Superhero](doc/superhero.md) - [Faker.Team](doc/team.md) - [Faker.Time](doc/time.md) diff --git a/doc/star_wars.md b/doc/star_wars.md new file mode 100644 index 0000000..d9d839a --- /dev/null +++ b/doc/star_wars.md @@ -0,0 +1,25 @@ +# Faker.StarWars + +```cs +Faker.StarWars.CallSquadron() //=> "Green" + +Faker.StarWars.CallSign() //=> "Grey 5" + +Faker.StarWars.CallNumber() //=> "Leader" + +Faker.StarWars.Character() //=> "Anakin Skywalker" + +Faker.StarWars.Droid() //=> "C-3PO" + +Faker.StarWars.Planet() //=> "Tatooine" + +Faker.StarWars.Quote() //=> "Aren’t you a little short for a Stormtrooper?" + +Faker.StarWars.Quote("leia_organa")() //=> "Aren’t you a little short for a Stormtrooper?" + +Faker.StarWars.Specie() //=> "Gungan" + +Faker.StarWars.Vehicle() //=> "Sandcrawler" + +Faker.StarWars.WookieeSentence() //=> "Yrroonn ru ooma roo ahuma ur roooarrgh hnn-rowr." +``` \ No newline at end of file diff --git a/src/FakerDotNet/Data/StarWarsData.cs b/src/FakerDotNet/Data/StarWarsData.cs new file mode 100644 index 0000000..8db3ec5 --- /dev/null +++ b/src/FakerDotNet/Data/StarWarsData.cs @@ -0,0 +1,630 @@ +using System.Collections.Generic; + +namespace FakerDotNet.Data +{ + internal static class StarWarsData + { + public static readonly IEnumerable Characters = new[] + { + "Padme Amidala", + "Jar Jar Binks", + "Borvo the Hutt", + "Darth Caedus", + "Boba Fett", + "Jabba the Hutt", + "Obi-Wan Kenobi", + "Darth Maul", + "Leia Organa", + "Sheev Palpatine", + "Kylo Ren", + "Darth Sidious", + "Anakin Skywalker", + "Luke Skywalker", + "Ben Solo", + "Han Solo", + "Darth Vader", + "Watto", + "Mace Windu", + "Yoda", + "Count Dooku", + "Sebulba", + "Qui-Gon Jinn", + "Chewbacca", + "Jango Fett", + "Lando Calrissian", + "Bail Organa", + "Wedge Antilles", + "Poe Dameron", + "Ki-Adi-Mundi", + "Nute Gunray", + "Panaka", + "Rune Haako", + "Rey", + "Finn", + "Supreme Leader Snoke", + "General Hux", + "Admiral Ackbar", + "Ahsoka Tano", + "Asajj Ventress", + "Bendu", + "Captain Phasma", + "Chirrut Imwe", + "Ezra Bridger", + "Galen Erso", + "Grand Moff Tarkin", + "Grand Admiral Thrawn", + "Greedo", + "Jyn Erso", + "Lyra Erso", + "Maz Kanata", + "Mon Mothma", + "Sabine Wren", + "Saw Gerrera", + "Savage Opress", + "Shmi Skywalker", + "Kanan Jarrus", + "Hera Syndulla", + "Rose Tico", + "Vice Admiral Holdo" + }; + + public static readonly IEnumerable CallSquadrons = new[] + { + "Rogue", + "Red", + "Gray", + "Green", + "Blue", + "Gold", + "Black", + "Yellow", + "Phoenix" + }; + + public static readonly IEnumerable CallNumbers = new[] + { + "Leader", + "#" + }; + + public static readonly IEnumerable Droids = new[] + { + "2-1B", + "4-LOM", + "ASP", + "B2-RP", + "B1", + "BD-3000", + "C1-10P", + "FA-4", + "GH-7", + "GNK", + "LM-432", + "ID9", + "11-4D", + "2-1B", + "327-T", + "4-LOM", + "B4-D4", + "NR-N99", + "C-3PO", + "R2-D2", + "BB-8", + "R2-Q5", + "Super Battle Droid", + "Mouse Droid", + "Droideka", + "Buzz Droid", + "Magnaguard", + "Interrogation Droid", + "Vulture Droid", + "BB-9E", + "K-2SO" + }; + + public static readonly IEnumerable Planets = new[] + { + "Alderaan", + "Ahch-To", + "Bespin", + "Cantonica", + "Coruscant", + "Cloud City", + "Crait", + "DQar", + "Dathomir", + "Dagobah", + "Death Star", + "Eadu", + "Endor", + "Felucia", + "Geonosis", + "Hoth", + "Hosnian Prime", + "Jakku", + "Jedha", + "Kamino", + "Kashyyyk", + "Lothal", + "Mandalore", + "Mustafar", + "Mygeeto", + "Naboo", + "Onderon", + "Ryloth", + "Scarif", + "Starkiller Base", + "Sullust", + "Takodana", + "Tatooine", + "Utapau", + "Yavin 4" + }; + + public static readonly IEnumerable Species = new[] + { + "Ewok", + "Hutt", + "Gungan", + "Ithorian", + "Jawa", + "Neimoidian", + "Sullustan", + "Wookiee", + "Mon Calamari", + "Bith", + "Dathomirian", + "Gamorreans", + "Kaminoan", + "Twi'lek", + "Porg" + }; + + public static readonly IEnumerable Vehicles = new[] + { + "V-Wing Fighter", + "ATT Battle Tank", + "Naboo N-1 Starfighter", + "Republic Cruiser", + "Naboo Royal Starship", + "Gungan Bongo Submarine", + "Flash Speeder", + "Trade Federation Battleship", + "Millennium Falcon", + "Sith Infiltrator", + "AT-ST Walker", + "TIE Bomber", + "Imperial Shuttle", + "Sandcrawler", + "TIE Interceptor", + "Speeder Bike", + "Death Star", + "AT-AT Walker", + "Imperial Star Destroyer", + "X-Wing Fighter", + "A-Wing Fighter", + "GR-75 Transport", + "Imperial Interdictor", + "MTT", + "Phantom II", + "Republic Attack Gunship", + "Rey's Speeder", + "Ghost", + "U-Wing", + "Y-Wing Starfighter", + "First Order TIE Fighter", + "AT-M6 Walker", + "First Order Dreadnought", + "TIE Silencer", + "Resistance Bomber", + "Resistance Ski Speeder" + }; + + public static readonly IEnumerable WookieWords = new[] + { + "wyaaaaaa", + "ruh", + "huewaa", + "muaa", + "mumwa", + "wua", + "ga", + "ma", + "ahuma", + "ooma", + "youw", + "kabukk", + "wyogg", + "gwyaaaag", + "roooarrgh", + "ur", + "ru", + "roo", + "hnn-rowr", + "yrroonn", + "nng", + "rarr" + }; + + public static readonly IEnumerable SentenceEndings = new[] + { + ".", + "?", + "!" + }; + + public static readonly IDictionary QuotesForCharacters = new Dictionary + { + { + "admiral_ackbar", + new[] + { + "It's a trap!", + "The Shield is down! Commence attack on the Death star's main reactor.", + "We have no choice, General Calrissian! Our cruisers can't repel firepower of that magnitude!" + } + }, + { + "ahsoka_tano", + new[] + { + "Suicide is not the Jedi way, master.", + "Let's just say my master will always do what needs to be done. I'm not even sure how peacetime will agree with him.", + "Sorry to interrupt your playtime, Grumpy, but wouldn't you prefer a challenge?" + } + }, + { + "anakin_skywalker", + new[] + { + "I've got a bad feeling about this.", + "Just for once, let me look on you with my own eyes.", + "Jedi business, go back to your drinks!" + } + }, + { + "asajj_ventress", + new[] + { + "You're tenacious, Jedi.", + "Not even the dark side can give you that power." + } + }, + { + "bendu", + new[] + { + "Your presence is like a violent storm in this quiet world", + "An object can not make you good, or evil. The temptation of power, forbidden knowledge, even the desire to do good can lead some down that path. But only you can change yourself.", + "Once something is known, it cannot be unknown." + } + }, + { + "boba_fett", + new[] + { + "He's no good to me dead.", + "You can run, but you'll only die tired." + } + }, + { + "c_3po", + new[] + { + "I have a bad feeling about this.", + "R2-D2, you know better than to trust a strange computer!", + "You’ll be malfunctioning within a day, you nearsighted scrap pile.", + "I'm terribly sorry about all this. After all, he's only a Wookiee!", + "Don’t you call me a mindless philosopher, you overweight glob of grease!", + "We're doomed.", + "I suggest a new strategy, R2. Let the Wookiee win.", + "We seem to be made to suffer. It's our lot in life.", + "I'm backwards you filthy furball!", + "If I told you half the things I've heard about this Jabba the Hutt, you'd probably short circuit.", + "Don’t worry about Master Luke. I’m sure he’ll be all right. He’s quite clever, you know… for a human being.", + "I can’t abide these Jawas. Disgusting creatures.", + "It's against my programming to impersonate a deity.", + "Just you reconsider playing that message for him! No, I don't think he likes you at all. No, I don't like you either.", + "Now don't you forget this! Why I should stick my neck out for you is far beyond my capacity!" + } + }, + { + "count_dooku", + new[] + { + "Twice the pride, double the fall." + } + }, + { + "darth_caedus", + new[] + { + "You're smarter than a tree, aren't you?" + } + }, + { + "darth_vader", + new[] + { + "I find your lack of faith disturbing.", + "You are a member of the rebel alliance, and a traitor.", + "You are unwise to lower your defenses!", + "I am altering the deal. Pray I don't alter it any further.", + "Perhaps you think you're being treated unfairly?", + "The circle is now complete. When I left you, I was but the learner. Now I am the master.", + "Obi-Wan was wise to hide her from me. Now, his failure is complete. If you will not turn to the Dark Side… then perhaps she will.", + "Search your feelings, you know it to be true!", + "Impressive. Most impressive. Obi-Wan has taught you well. You have controlled your fear. Now, release your anger. Only your hatred can destroy me.", + "I hope so for your sake, the Emperor is not as forgiving as I am", + "Be careful not to choke on your aspirations, Director.", + "He is as clumsy as he is stupid.", + "You may use any methods necessary, but I want them alive. No disintegrations!", + "You have failed me for the last time, Admiral." + } + }, + { + "emperor_palpatine", + new[] + { + "Only at the end do you realize the power of the Dark Side.", + "Oh, I'm afraid the deflector shield will be quite operational when your friends arrive.", + "There is a great disturbance in the Force.", + "Give in to your anger. With each passing moment you make yourself more my servant.", + "Let the hate flow through you!", + "Your feeble skills are no match for the power of the Dark Side.", + "Your hate has made you powerful. Now fulfill your destiny, take you're father's place by my side.", + "So be it, Jedi.", + "The Force is strong with him. The son of Skywalker must not become a Jedi." + } + }, + { + "finn", + new[] + { + "Droid, please!", + "Sanitation", + "Solo, we'll figure it out. We'll use the Force.", + "I'm a big deal in the Resistance. Which puts a real target on my back." + } + }, + { + "general_hux", + new[] + { + "I won't have you question my methods.", + "Careful, Ren, that your personal interests not interfere with orders from Leader Snoke." + } + }, + { + "grand_admiral_thrawn", + new[] + { + "I will start my operations here, and pull the rebels apart piece by piece. They'll be the architects of their own destruction.", + "War is in your blood. I studied the art of war, worked to perfect it, but you? You were forged by it." + } + }, + { + "grand_moff_tarkin", + new[] + { + "Now, witness the power of this fully operational battle station.", + "The Jedi are extinct. Their fire has gone out of the universe. You, my friend, are all that's left of their religion." + } + }, + { + "greedo", + new[] + { + "Koona t'chuta Solo? (Going somewhere Solo?)", + "Soong peetch alay. (It's too late.)", + "Ee mara tom tee tok maky cheesa. (You should have paid him when you had the chance.)", + "Jabba won neechee kochba mu shanee wy tonny wya uska. (Jabba put a price on your head so large, every bounty hunter in the galaxy will be looking for you.)", + "Chosky nowy u chusu. (I'm lucky I found you first.)", + "El jaya kulpa intick kuny ku suwa. (If you give it to me, I might forget I found you.)", + "Semal hi teek teek. (Jabba's through with you.)", + "Sone guru ye buya nyah oo won spasteega koo shu coon bon duwa weeptee. (He has no time for smugglers who drop their shipments at the first sign of an Imperial cruiser.)", + "Talk Jabba. (Tell that to Jabba.)", + "Boompa kom bok nee aht am bompah. (He may only take your ship.)", + "Nuklee numaa (that's the idea.)", + "Ches ko ba tuta creesta crenko ya kolska! (This is something I've been looking forward to for a long time.)" + } + }, + { + "han_solo", + new[] + { + "It's the ship that made the Kessel Run in less than 12 parsecs.", + "She may not look like much, but she's got it where it counts, kid.", + "Never tell me the odds", + "Well, you said you wanted to be around when I made a mistake.", + "No reward is worth this.", + "Shut him up or shut him down.", + "I got a bad feeling about this.", + "I have a really bad feeling about this.", + "Ungh. And I thought they smelled bad on the outside.", + "I have a bad feeling about this.", + "Bounty hunters! We don't need this scum.", + "If they follow standard Imperial procedure, they'll dump their garbage before they go to light-speed.", + "Hokey religions and ancient weapons are no match for a good blaster at your side, kid." + } + }, + { + "jabba_the_hutt", + new[] + { + "Solo, la pa loiya Solo! (Solo, come out of there! Solo!)", + "Bone duwa pweepway? (Have you now?)", + "Han, ma bookie, keel-ee calleya ku kah. (Han, my boy, you disappoint me.)", + "Wanta dah moolee-rah... (Why haven't you paid me...)", + "Mon kee chees kreespa Greedo? (And why did you fry poor Greedo?)", + "Han, ma kee chee zay. (Han, I can't make exceptions.)", + "Hassa ba una kulkee malia... (What if everyone who smuggled for me...)", + "Lude eveela deesa... (drooped their cargo at the sight...)", + "sloan dwa spasteega el was nwo yana da gooloo? (of an Imperial starship?)", + "Han, ma bookie, baldo nee anna dodo da eena. (You're the best.)", + "See fa doi dee yaba... (So for an extra twenty percent...)", + "Dee do ee deen. (Okay, fifteen percent.)", + "Ee ya ba ma dookie massa... (But if you fail me again...)", + "Eek bon chee ko pa na green. (I'll put a price on your head so big...)", + "na meeto do buny dunko la cho ya. (you won't be able to get near a civilized system.)", + "Boska! (Come on!)" + } + }, + { + "jar_jar_binks", + new[] + { + "Ooh mooey mooey I love you!", + "Yoosa should follow me now, okeeday?", + "Yipe! How wude!", + "Ohh, maxi big da Force. Well dat smells stinkowiff.", + "Oh Gooberfish", + "Exsqueeze me", + "Mesa cause one, two-y little bitty axadentes, huh? Yud say boom de gasser, den crashin der bosses heyblibber, den banished.", + "Mesa called Jar-Jar Binks. Mesa your humble servant.", + "My forgotten, da Bosses will do terrible tings to me TERRRRRIBLE is me going back der!", + "Mesa day startin pretty okee-day with a brisky morning munchy, then BOOM! Gettin very scared and grabbin that Jedi and POW! Mesa here! Mesa gettin' very very scared!" + } + }, + { + "k_2so", + new[] + { + "I have a bad feeling about..." + } + }, + { + "kylo_ren", + new[] + { + "You need a teacher. I can show you the ways of the Force.", + "Show me again, grandfather, and I will finish what you started." + } + }, + { + "lando_calrissian", + new[] + { + "Why you slimy, double-crossing, no-good swindler. You've got a lot of guts coming here, after what you pulled.", + "How you doin' Chewbacca? Still hanging around with this loser?", + "But how could they be jamming us if they don't know that we're coming?", + "This deal is getting worse all the time." + } + }, + { + "leia_organa", + new[] + { + "You do have your moments. Not many, but you have them.", + "I have a bad feeling about this.", + "Would somebody get this big walking carpet out of my way?", + "Aren't you a little short for a Stormtrooper?", + "Help me Obi-Wan. You're my only hope", + "Why, you stuck-up, half-witted, scruffy-looking nerf herder!", + "Governor Tarkin, I should've expected to find you holding Vader's leash. I recognized your foul stench when I was brought on board.", + "Somebody has to save our skins. Into the garbage chute, flyboy!" + } + }, + { + "luke_skywalker", + new[] + { + "But I was going into Tosche Station to pick up some power converters!", + "I have a very bad feeling about this.", + "It's not impossible. I used to bullseye womp rats in my T-16 back home, they're not much bigger than two meters.", + "You know, that little droid is going to cause me a lot of trouble.", + "If you're saying that coming here was a bad idea, I'm starting to agree with you.", + "You'll find I'm full of surprises!", + "Your overconfidence is your weakness.", + "You serve your master well. And you will be rewarded.", + "Threepio, tell them if they don't do as you wish, you'll become angry and use your magic", + "I am a Jedi, like my father before me." + } + }, + { + "mace_windu", + new[] + { + "The senate will decide your fate.", + "Then our worst fears have been realized. We must move quickly if the Jedi Order is to survive." + } + }, + { + "maz_kanata", + new[] + { + "I assume you need something. Desperately." + } + }, + { + "obi_wan_kenobi", + new[] + { + "An elegant weapon for a more civilized age.", + "You don’t need to see his identification. These aren’t the droids you’re looking for.", + "You will never find a more wretched hive of scum and villainy. We must be cautious.", + "Who's the more foolish; the fool, or the fool who follows him?", + "I have a bad feeling about this.", + "Strike me down, and I will become more powerful than you could possibly imagine.", + "In my experience there is no such thing as luck.", + "The Force will be with you. Always.", + "That's no moon. It's a space station.", + "I felt a great disturbance in the Force. As if millions of voices suddenly cried out in terror and were suddenly silenced.", + "Use the Force, Luke." + } + }, + { + "padme_amidala", + new[] + { + "So this is how liberty dies. With thunderous applause.", + "Ani? My goodness, you've grown.", + "Anakin you're breaking my heart, you're going down a path I can't follow.", + "Hold me, like you did by the lake on Naboo; so long ago when there was nothing but our love. No politics, no plotting, no war.", + "I was not elected to watch my people suffer and die while you discuss this invasion in a committee!" + } + }, + { + "qui_gon_jinn", + new[] + { + "Remember your focus determines your reality." + } + }, + { + "rey", + new[] + { + "You will remove these restraints and leave this cell with the door open.", + "The garbage'll do" + } + }, + { + "shmi_skywalker", + new[] + { + "You can't stop change any more than you can stop the suns from setting.", + "The Republic doesn't exist out here. We must survive on our own." + } + }, + { + "yoda", + new[] + { + "Wars not make one great.", + "Truly wonderful, the mind of a child is.", + "That is why you fail.", + "A Jedi uses the Force for knowledge and defense, never for attack.", + "Adventure. Excitement. A Jedi craves not these things.", + "Fear is the path to the dark side... fear leads to anger... anger leads to hate... hate leads to suffering.", + "Judge me by my size, do you?", + "Do. Or do not. There is no try.", + "Luminous beings are we... not this crude matter.", + "Train yourself to let go of everything you fear to lose.", + "Size matters not. Look at me. Judge me by my size, do you?", + "Ohhh. Great warrior. Wars not make one great." + } + } + }; + } +} diff --git a/src/FakerDotNet/Faker.cs b/src/FakerDotNet/Faker.cs index 162abe5..20b2804 100644 --- a/src/FakerDotNet/Faker.cs +++ b/src/FakerDotNet/Faker.cs @@ -36,6 +36,7 @@ public static class Faker public static IRickAndMortyFaker RickAndMorty { get; } = Container.RickAndMorty; public static IRockBandFaker RockBand { get; } = Container.RockBand; public static ISlackEmojiFaker SlackEmoji { get; } = Container.SlackEmoji; + public static IStarWarsFaker StarWars { get; } = Container.StarWars; public static ISuperheroFaker Superhero { get; } = Container.Superhero; public static ITeamFaker Team { get; } = Container.Team; public static ITimeFaker Time { get; } = Container.Time; diff --git a/src/FakerDotNet/FakerContainer.cs b/src/FakerDotNet/FakerContainer.cs index 6c4176a..d3a9832 100644 --- a/src/FakerDotNet/FakerContainer.cs +++ b/src/FakerDotNet/FakerContainer.cs @@ -34,6 +34,7 @@ internal interface IFakerContainer IRickAndMortyFaker RickAndMorty { get; } IRockBandFaker RockBand { get; } ISlackEmojiFaker SlackEmoji { get; } + IStarWarsFaker StarWars { get; } ISuperheroFaker Superhero { get; } ITeamFaker Team { get; } ITimeFaker Time { get; } @@ -77,6 +78,7 @@ public FakerContainer() RickAndMorty = new RickAndMortyFaker(this); RockBand = new RockBandFaker(this); SlackEmoji = new SlackEmojiFaker(this); + StarWars = new StarWarsFaker(this); Superhero = new SuperheroFaker(this); Team = new TeamFaker(this); Time = new TimeFaker(); @@ -116,6 +118,7 @@ public FakerContainer() public IRickAndMortyFaker RickAndMorty { get; } public IRockBandFaker RockBand { get; } public ISlackEmojiFaker SlackEmoji { get; } + public IStarWarsFaker StarWars { get; } public ISuperheroFaker Superhero { get; } public ITeamFaker Team { get; } public ITimeFaker Time { get; } diff --git a/src/FakerDotNet/Fakers/StarWarsFaker.cs b/src/FakerDotNet/Fakers/StarWarsFaker.cs new file mode 100644 index 0000000..cd6e9b0 --- /dev/null +++ b/src/FakerDotNet/Fakers/StarWarsFaker.cs @@ -0,0 +1,112 @@ +using System; +using System.Linq; +using System.Text.RegularExpressions; +using FakerDotNet.Data; + +namespace FakerDotNet.Fakers +{ + public interface IStarWarsFaker + { + string CallSquadron(); + string CallSign(); + string CallNumber(); + string Character(); + string Droid(); + string Planet(); + string Quote(string character = ""); + string Specie(); + string Vehicle(); + string WookieeSentence(); + } + + internal class StarWarsFaker : IStarWarsFaker + { + private readonly IFakerContainer _fakerContainer; + + public StarWarsFaker(IFakerContainer fakerContainer) + { + _fakerContainer = fakerContainer; + } + + public string CallSquadron() + { + return _fakerContainer.Random.Element(StarWarsData.CallSquadrons); + } + + public string CallSign() + { + return $"{CallSquadron()} {CallNumber()}"; + } + + public string CallNumber() + { + var callNumber = _fakerContainer.Random.Element(StarWarsData.CallNumbers); + + return Numerify(callNumber); + } + + public string Character() + { + return _fakerContainer.Random.Element(StarWarsData.Characters); + } + + public string Droid() + { + return _fakerContainer.Random.Element(StarWarsData.Droids); + } + + public string Planet() + { + return _fakerContainer.Random.Element(StarWarsData.Planets); + } + + public string Quote(string character = "") + { + var key = (string.IsNullOrEmpty(character) ? Character() : character) + .ToLowerInvariant() + .Replace(" ", "_"); + + if (!StarWarsData.QuotesForCharacters.ContainsKey(key)) + { + var keys = string.Join(", ", StarWarsData.QuotesForCharacters.Keys); + throw new ArgumentException($"Character for quotes can be left blank or {keys}"); + } + + var quotes = StarWarsData.QuotesForCharacters[key]; + + return _fakerContainer.Random.Element(quotes); + } + + public string Specie() + { + return _fakerContainer.Random.Element(StarWarsData.Species); + } + + public string Vehicle() + { + return _fakerContainer.Random.Element(StarWarsData.Vehicles); + } + + public string WookieeSentence() + { + var numberOfWords = (int) _fakerContainer.Number.Between(0, 10); + var words = Enumerable.Range(0, numberOfWords) + .Select(_ => _fakerContainer.Random.Element(StarWarsData.WookieWords)) + .ToArray(); + var ending = _fakerContainer.Random.Element(StarWarsData.SentenceEndings); + var sentence = string.Join(" ", words) + ending; + + return Capitalize(sentence); + } + + private string Numerify(string text) + { + return Regex.Replace(text, "#", m => _fakerContainer.Number.NonZeroDigit()); + } + + private static string Capitalize(string text) + { + return Regex.Replace(text, "^(.)", m => m.Value.ToUpperInvariant()); + } + } +} diff --git a/tests/FakerDotNet.Tests/FakerContainerTests.cs b/tests/FakerDotNet.Tests/FakerContainerTests.cs index 2bab9cd..fff16b8 100644 --- a/tests/FakerDotNet.Tests/FakerContainerTests.cs +++ b/tests/FakerDotNet.Tests/FakerContainerTests.cs @@ -195,6 +195,12 @@ public void SlackEmoji_returns_ISlackEmoji() Assert.IsInstanceOf(_fakerContainer.SlackEmoji); } + [Test] + public void StarWars_returns_IStarWarsFaker() + { + Assert.IsInstanceOf(_fakerContainer.StarWars); + } + [Test] public void Superhero_returns_ISuperheroFaker() { diff --git a/tests/FakerDotNet.Tests/FakerTests.cs b/tests/FakerDotNet.Tests/FakerTests.cs index 338893f..1f0692e 100644 --- a/tests/FakerDotNet.Tests/FakerTests.cs +++ b/tests/FakerDotNet.Tests/FakerTests.cs @@ -180,6 +180,18 @@ public void RockBand_returns_IRockBandFaker() { Assert.IsInstanceOf(Faker.RockBand); } + + [Test] + public void SlackEmoji_returns_ISlackEmoji() + { + Assert.IsInstanceOf(Faker.SlackEmoji); + } + + [Test] + public void StarWars_returns_IStarWarsFaker() + { + Assert.IsInstanceOf(Faker.StarWars); + } [Test] public void Superhero_returns_ISuperheroFaker() @@ -192,11 +204,6 @@ public void Team_returns_ITeamFaker() { Assert.IsInstanceOf(Faker.Team); } - [Test] - public void SlackEmoji_returns_ISlackEmoji() - { - Assert.IsInstanceOf(Faker.SlackEmoji); - } [Test] public void Time_returns_ITimeFaker() diff --git a/tests/FakerDotNet.Tests/Fakers/StarWarsFakerTests.cs b/tests/FakerDotNet.Tests/Fakers/StarWarsFakerTests.cs new file mode 100644 index 0000000..61de756 --- /dev/null +++ b/tests/FakerDotNet.Tests/Fakers/StarWarsFakerTests.cs @@ -0,0 +1,153 @@ +using System; +using FakeItEasy; +using FakerDotNet.Data; +using FakerDotNet.Fakers; +using NUnit.Framework; + +namespace FakerDotNet.Tests.Fakers +{ + [TestFixture] + [Parallelizable] + public class StarWarsFakerTests + { + [SetUp] + public void SetUp() + { + _fakerContainer = A.Fake(); + _starwarsFaker = new StarWarsFaker(_fakerContainer); + } + + private IFakerContainer _fakerContainer; + private IStarWarsFaker _starwarsFaker; + + [Test] + public void CallSquadron_returns_returns_a_call_squadron() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.CallSquadrons)) + .Returns("Green"); + + Assert.AreEqual("Green", _starwarsFaker.CallSquadron()); + } + + [Test] + public void CallSign_returns_a_call_sign() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.CallSquadrons)) + .Returns("Grey"); + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.CallNumbers)) + .Returns("#"); + A.CallTo(() => _fakerContainer.Number.NonZeroDigit()) + .Returns("5"); + + Assert.AreEqual("Grey 5", _starwarsFaker.CallSign()); + } + + [Test] + public void CallNumber_returns_a_call_number() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.CallNumbers)) + .Returns("Leader"); + + Assert.AreEqual("Leader", _starwarsFaker.CallNumber()); + } + + [Test] + public void CallNumber_returns_a_numerified_call_number() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.CallNumbers)) + .Returns("#"); + A.CallTo(() => _fakerContainer.Number.NonZeroDigit()) + .Returns("6"); + + Assert.AreEqual("6", _starwarsFaker.CallNumber()); + } + + [Test] + public void Character_returns_a_character() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.Characters)) + .Returns("Anakin Skywalker"); + + Assert.AreEqual("Anakin Skywalker", _starwarsFaker.Character()); + } + + [Test] + public void Droid_returns_a_droid() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.Droids)) + .Returns("C-3PO"); + + Assert.AreEqual("C-3PO", _starwarsFaker.Droid()); + } + + [Test] + public void Planet_returns_a_planet() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.Planets)) + .Returns("Tatooine"); + + Assert.AreEqual("Tatooine", _starwarsFaker.Planet()); + } + + [Test] + public void Quote_returns_a_quote() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.Characters)) + .Returns("Leia Organa"); + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.QuotesForCharacters["leia_organa"])) + .Returns("Aren’t you a little short for a Stormtrooper?"); + + Assert.AreEqual("Aren’t you a little short for a Stormtrooper?", _starwarsFaker.Quote()); + } + + [Test] + public void Quote_with_character_name_returns_a_quote() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.QuotesForCharacters["leia_organa"])) + .Returns("Aren’t you a little short for a Stormtrooper?"); + + Assert.AreEqual("Aren’t you a little short for a Stormtrooper?", _starwarsFaker.Quote("leia_organa")); + } + + [Test] + public void Quote_with_unrecognised_character_name_throws_ArgumentException() + { + var keys = string.Join(", ", StarWarsData.QuotesForCharacters.Keys); + + var ex = Assert.Throws(() => _starwarsFaker.Quote("bad")); + + Assert.That(ex.Message.StartsWith($"Character for quotes can be left blank or {keys}")); + } + + [Test] + public void Specie_returns_a_specie() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.Species)) + .Returns("Gungan"); + + Assert.AreEqual("Gungan", _starwarsFaker.Specie()); + } + + [Test] + public void Vehicle_returns_a_vehicle() + { + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.Vehicles)) + .Returns("Sandcrawler"); + + Assert.AreEqual("Sandcrawler", _starwarsFaker.Vehicle()); + } + + [Test] + public void WookieeSentence_returns_a_wookiee_sentence() + { + A.CallTo(() => _fakerContainer.Number.Between(0, 10)) + .Returns(8); + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.WookieWords)) + .ReturnsNextFromSequence("yrroonn", "ru", "ooma", "roo", "ahuma", "ur", "roooarrgh", "hnn-rowr"); + A.CallTo(() => _fakerContainer.Random.Element(StarWarsData.SentenceEndings)) + .Returns("."); + + Assert.AreEqual("Yrroonn ru ooma roo ahuma ur roooarrgh hnn-rowr.", _starwarsFaker.WookieeSentence()); + } + } +}