diff --git a/FakerDotNet.sln.DotSettings b/FakerDotNet.sln.DotSettings index 25c2fac..09f27ed 100644 --- a/FakerDotNet.sln.DotSettings +++ b/FakerDotNet.sln.DotSettings @@ -1,3 +1,4 @@  IP - RNG \ No newline at end of file + RNG + True \ No newline at end of file diff --git a/README.md b/README.md index e1ab1c5..7357d0c 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ A .NET port of the Ruby [faker](https://github.com/stympy/faker) gem - [Faker.HarryPotter](doc/harry_potter.md) - [Faker.Internet](doc/internet.md) - [Faker.Lorem](doc/lorem.md) + - [Faker.Music](doc/music.md) - [Faker.Name](doc/name.md) - [Faker.Number](doc/number.md) - [Faker.PhoneNumber](doc/phone_number.md) diff --git a/doc/music.md b/doc/music.md new file mode 100644 index 0000000..ae3da13 --- /dev/null +++ b/doc/music.md @@ -0,0 +1,15 @@ +# Faker.Music + +```cs +Faker.Music.Key() //=> "C" + +Faker.Music.Chord() //=> "Amaj7" + +Faker.Music.Instrument() //=> "Ukelele" + +Faker.Music.Band() //=> "The Beatles" + +Faker.Music.Album() //=> "Sgt. Pepper's Lonely Hearts Club" + +Faker.Music.Genre() //=> "Rock" +``` \ No newline at end of file diff --git a/src/FakerDotNet/Data/MusicData.cs b/src/FakerDotNet/Data/MusicData.cs new file mode 100644 index 0000000..03a422f --- /dev/null +++ b/src/FakerDotNet/Data/MusicData.cs @@ -0,0 +1,371 @@ +using System.Collections.Generic; + +namespace FakerDotNet.Data +{ + internal static class MusicData + { + public static readonly IEnumerable Keys = new[] + { + "C", + "D", + "E", + "F", + "G", + "A", + "B" + }; + + public static readonly IEnumerable KeyVariants = new[] + { + "", + "b", + "#" + }; + + public static readonly IEnumerable KeyTypes = new[] + { + "", + "m" + }; + + public static readonly IEnumerable ChordTypes = new[] + { + "", + "maj", + "6", + "maj7", + "m", + "m7", + "-7", + "7", + "dom7", + "dim", + "dim7", + "m7b5" + }; + + public static readonly IEnumerable Instruments = new[] + { + "Electric Guitar", + "Acoustic Guitar", + "Flute", + "Trumpet", + "Clarinet", + "Cello", + "Harp", + "Xylophone", + "Harmonica", + "Accordion", + "Organ", + "Piano", + "Ukelele", + "Saxophone", + "Drums", + "Violin", + "Bass Guitar", + "Oboe" + }; + + public static readonly IEnumerable Bands = new[] + { + "AC/DC", + "Adam and the Ants", + "Afrika Bambaataa", + "Al Foster", + "Alan Parsons", + "Alex Chilton", + "Amy Winehouse", + "Annie Lennox", + "Arctic Monkeys", + "B.B. King", + "Bauhaus", + "The Beatles", + "Beck", + "Billy Idol", + "The Birthday Party", + "Björk", + "Blinker The Star", + "Blondie", + "Blur", + "Bob Dylan", + "Bob Marley (and the Wailers)", + "Brian Wilson", + "Bruce Springsteen", + "Buzzcocks", + "Captain Beefheart", + "Carlos Santana", + "Cat Anderson", + "Cat Stevens", + "Catherine Wheel", + "Chic", + "Chris Isaak", + "Chrissie Hynde", + "Chuck Berry", + "The Clash", + "Cliff Richard (and the Shadows)", + "Coldplay", + "Cootie Williams", + "Cortinas", + " The", + "The Cramps", + "The Cranberries", + "Cream", + "The Cure", + "David Bowie", + "David Gilmour", + "Deepest Blue", + "Devo", + "Dizzy Gillespie", + "Dr Feelgood", + "Duke Ellington", + "Ed Sheeran", + "Ella Fitzgerald", + "Elton John", + "Elvis Costello", + "Elvis Presley", + "Eric Clapton", + "The Faces", + "Fats Domino", + "Flaming Lips", + "Florence and the Machine", + "Foo Fighters", + "Frank Sinatra", + "Frank Zappa", + "Frightened Rabbit", + "George Michael", + "Grace Jones", + "Green Day", + "Guns N' Roses", + "Herbie Hancock", + "Horace Silver", + "Hugh Masekela", + "Ian Dury", + "Iggy Pop", + "The Jam", + "James Brown", + "Jeff Beck", + "Jeff Buckley", + "Jimi Hendrix", + "John Coltrane", + "John Lydon", + "Johnny Borrell", + "Johnny Cash", + "Johnny Marr", + "Joni Mitchell", + "Joy Division", + "K.D Lang", + "Kasabian", + "Kate Bush", + "Keith Moon", + "Keith Richards", + "The Kinks", + "Kiss", + "The La's", + "Led Zeppelin", + "Lenny Kravitz", + "Leonard Cohen", + "Liam Gallagher", + "The Libertines", + "Madness", + "Madonna", + "Manic Street Preachers", + "Marc Bolan", + "Marianne Faithfull", + "Marilyn Manson", + "Maroon 5", + "The Mars Volta", + "Max Roach", + "Michael Jackson", + "Miles Davis", + "Morrissey", + "Muddy Waters", + "Mumford and Sons", + "Muse", + "Neil Young", + "New Order", + "Nick Cave", + "Nigel Kennedy", + "Nina Simone", + "Nirvana", + "Noel Gallagher", + "O.A.R.", + "Oasis", + "Offspring", + "Ozzy Osbourne", + "Paramore", + "Pat Metheny", + "Patti Smith", + "Paul Weller", + "Pearl Jam", + "Pete Townshend", + "Phil Collins", + "Phish", + "Pink Floyd", + "PJ Harvey", + "The Police", + "The Pretenders", + "Primal Scream", + "Prince", + "Program The Dead", + "Pulp", + "Queen", + "Radiohead", + "The Ramones", + "Red Hot Chili Peppers", + "R.E.M.", + "Rick Wright", + "Rod Stewart", + "The Rolling Stones", + "Rory Gallagher", + "Roxy Music", + "Roy Hargrove", + "Rufus Wainwright", + "Run-D.M.C.", + "Ryan Adams", + "Sex Pistols", + "Simply Red", + "Sinead O'connor", + "Siouxsie and The Banshees", + "The Slits", + "The Smiths", + "Sonic Youth", + "The Specials", + "Squeeze", + "Status Quo", + "Stereophonics", + "Stone Roses", + "Syd Barrett", + "Thelonius Monk", + "Thin Lizzy", + "Thornley", + "Tina Turner", + "Tom Jones", + "Tom Robinson", + "Tom Waits", + "U2", + "The Undertones", + "Van Morrison", + "Velvet Revolver", + "White Stripes", + "The Who", + "The Yardbirds", + "Yumi Matsutoya" + }; + + public static readonly IEnumerable Albums = new[] + { + "Thriller", + "Back in Black", + "The Dark Side of the Moon", + "Bat Out of Hell", + "The Bodyguard", + "Their Greatest Hits (1971–1975)", + "Saturday Night Fever", + "Rumours", + "Grease: The Original Soundtrack from the Motion Picture", + "Led Zeppelin IV", + "Bad", + "Jagged Little Pill", + "Come On Over", + "Falling into You", + "Sgt. Pepper's Lonely Hearts Club Band", + "Hotel California", + "Dirty Dancing", + "21", + "Let's Talk About Love", + "1", + "Gold: Greatest Hits", + "Dangerous", + "The Immaculate Collection", + "Abbey Road", + "Born in the U.S.A.", + "Brothers in Arms", + "Titanic: Music from the Motion Picture", + "Metallica", + "Nevermind", + "The Wall", + "Supernatural", + "Appetite for Destruction", + "Slippery When Wet", + "Music Box", + "The Eminem Show", + "Hybrid Theory", + "Come Away with Me", + "Unplugged", + "True Blue", + "Legend: The Best of Bob Marley & The Wailers", + "Tapestry", + "No Jacket Required", + "Greatest Hits", + "Bridge over Troubled Water", + "The Joshua Tree", + "...Baby One More Time", + "Backstreet's Back", + "Backstreet Boys", + "Millennium", + "Spice", + "Happy Nation", + "The Sign", + "Whitney Houston", + "(What's the Story) Morning Glory?", + "The Marshall Mathers LP", + "Like a Virgin", + "Cross Road", + "25", + "Boston", + "Oops!... I Did It Again", + "The Colour of My Love", + "Hysteria", + "Faith", + "Dookie", + "Can't Slow Down", + "Daydream", + "HIStory: Past", + " Present and Future", + " Book I", + "Off the Wall", + "The Woman in Me", + "Breakfast in America", + "Tracy Chapman", + "Flashdance: Original Soundtrack from the Motion Picture", + "Whitney", + "Confessions", + "X&Y", + "High School Musical", + "High School Musical 2", + "Viva la Vida or Death and All His Friends", + "I Dreamed a Dream", + "Recovery", + "Midnight Memories", + "Frozen", + "Lemonade", + "Brand New Eyes", + "All We Know Is Falling", + "Riot!", + "Songs About Jane", + "Hands All Over" + }; + + public static readonly IEnumerable Genres = new[] + { + "Rock", + "Pop", + "Electronic", + "Folk", + "World", + "Country", + "Jazz", + "Funk", + "Soul", + "Hip Hop", + "Classical", + "Latin", + "Reggae", + "Stage And Screen", + "Blues", + "Non Music", + "Rap" + }; + + } +} diff --git a/src/FakerDotNet/Faker.cs b/src/FakerDotNet/Faker.cs index 3e1b3e0..7e6b237 100644 --- a/src/FakerDotNet/Faker.cs +++ b/src/FakerDotNet/Faker.cs @@ -29,6 +29,7 @@ public static class Faker public static IHarryPotterFaker HarryPotter { get; } = Container.HarryPotter; public static IInternetFaker Internet { get; } = Container.Internet; public static ILoremFaker Lorem { get; } = Container.Lorem; + public static IMusicFaker Music { get; } = Container.Music; public static INameFaker Name { get; } = Container.Name; public static INumberFaker Number { get; } = Container.Number; public static IPhoneNumberFaker PhoneNumber { get; } = Container.PhoneNumber; diff --git a/src/FakerDotNet/FakerContainer.cs b/src/FakerDotNet/FakerContainer.cs index 08b6d58..471bdbf 100644 --- a/src/FakerDotNet/FakerContainer.cs +++ b/src/FakerDotNet/FakerContainer.cs @@ -27,6 +27,7 @@ internal interface IFakerContainer IHarryPotterFaker HarryPotter { get; } IInternetFaker Internet { get; } ILoremFaker Lorem { get; } + IMusicFaker Music { get; } INameFaker Name { get; } INumberFaker Number { get; } IPhoneNumberFaker PhoneNumber { get; } @@ -72,6 +73,7 @@ public FakerContainer() HarryPotter = new HarryPotterFaker(this); Internet = new InternetFaker(this); Lorem = new LoremFaker(this); + Music = new MusicFaker(this); Name = new NameFaker(this); Number = new NumberFaker(); PhoneNumber = new PhoneNumberFaker(this); @@ -113,6 +115,7 @@ public FakerContainer() public IHarryPotterFaker HarryPotter { get; } public IInternetFaker Internet { get; } public ILoremFaker Lorem { get; } + public IMusicFaker Music { get; } public INameFaker Name { get; } public INumberFaker Number { get; } public IPhoneNumberFaker PhoneNumber { get; } diff --git a/src/FakerDotNet/Fakers/MusicFaker.cs b/src/FakerDotNet/Fakers/MusicFaker.cs new file mode 100644 index 0000000..81cca6f --- /dev/null +++ b/src/FakerDotNet/Fakers/MusicFaker.cs @@ -0,0 +1,59 @@ +using System; +using FakerDotNet.Data; + +namespace FakerDotNet.Fakers +{ + public interface IMusicFaker + { + string Key(); + string Chord(); + string Instrument(); + string Band(); + string Album(); + string Genre(); + } + + internal class MusicFaker : IMusicFaker + { + private readonly IFakerContainer _fakerContainer; + + public MusicFaker(IFakerContainer fakerContainer) + { + _fakerContainer = fakerContainer; + } + + public string Key() + { + return string.Join("", + _fakerContainer.Random.Element(MusicData.Keys), + _fakerContainer.Random.Element(MusicData.KeyVariants)); + } + + public string Chord() + { + return string.Join("", + _fakerContainer.Random.Element(MusicData.Keys), + _fakerContainer.Random.Element(MusicData.ChordTypes)); + } + + public string Instrument() + { + return _fakerContainer.Random.Element(MusicData.Instruments); + } + + public string Band() + { + return _fakerContainer.Random.Element(MusicData.Bands); + } + + public string Album() + { + return _fakerContainer.Random.Element(MusicData.Albums); + } + + public string Genre() + { + return _fakerContainer.Random.Element(MusicData.Genres); + } + } +} diff --git a/tests/FakerDotNet.Tests/FakerContainerTests.cs b/tests/FakerDotNet.Tests/FakerContainerTests.cs index 984a7d8..1692d48 100644 --- a/tests/FakerDotNet.Tests/FakerContainerTests.cs +++ b/tests/FakerDotNet.Tests/FakerContainerTests.cs @@ -153,6 +153,12 @@ public void Lorem_returns_ILoremFaker() Assert.IsInstanceOf(_fakerContainer.Lorem); } + [Test] + public void Music_returns_IMusicFaker() + { + Assert.IsInstanceOf(_fakerContainer.Music); + } + [Test] public void Name_returns_INameFaker() { diff --git a/tests/FakerDotNet.Tests/FakerTests.cs b/tests/FakerDotNet.Tests/FakerTests.cs index ad8cfa6..e2bcacf 100644 --- a/tests/FakerDotNet.Tests/FakerTests.cs +++ b/tests/FakerDotNet.Tests/FakerTests.cs @@ -145,6 +145,12 @@ public void Lorem_returns_ILoremFaker() Assert.IsInstanceOf(Faker.Lorem); } + [Test] + public void Music_returns_IMusicFaker() + { + Assert.IsInstanceOf(Faker.Music); + } + [Test] public void Name_returns_INameFaker() { diff --git a/tests/FakerDotNet.Tests/Fakers/MusicFakerTests.cs b/tests/FakerDotNet.Tests/Fakers/MusicFakerTests.cs new file mode 100644 index 0000000..ce7eb11 --- /dev/null +++ b/tests/FakerDotNet.Tests/Fakers/MusicFakerTests.cs @@ -0,0 +1,102 @@ +using FakeItEasy; +using FakerDotNet.Data; +using FakerDotNet.Fakers; +using NUnit.Framework; + +namespace FakerDotNet.Tests.Fakers +{ + [TestFixture] + [Parallelizable] + public class MusicFakerTests + { + [SetUp] + public void SetUp() + { + _fakerContainer = A.Fake(); + _musicFaker = new MusicFaker(_fakerContainer); + } + + private IFakerContainer _fakerContainer; + private IMusicFaker _musicFaker; + + [Test] + public void Key_returns_a_key() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Keys)) + .Returns("C"); + A.CallTo(() => _fakerContainer.Random.Element(MusicData.KeyVariants)) + .Returns(""); + + Assert.AreEqual("C", _musicFaker.Key()); + } + + [Test] + public void Key_returns_a_key_with_key_variant() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Keys)) + .Returns("C"); + A.CallTo(() => _fakerContainer.Random.Element(MusicData.KeyVariants)) + .Returns("#"); + + Assert.AreEqual("C#", _musicFaker.Key()); + } + + [Test] + public void Chord_returns_a_chord() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Keys)) + .Returns("A"); + A.CallTo(() => _fakerContainer.Random.Element(MusicData.ChordTypes)) + .Returns(""); + + Assert.AreEqual("A", _musicFaker.Chord()); + } + + [Test] + public void Chord_returns_a_chord_with_a_chord_type() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Keys)) + .Returns("A"); + A.CallTo(() => _fakerContainer.Random.Element(MusicData.ChordTypes)) + .Returns("maj7"); + + Assert.AreEqual("Amaj7", _musicFaker.Chord()); + } + + [Test] + public void Instrument_returns_an_instrument() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Instruments)) + .Returns("Ukelele"); + + Assert.AreEqual("Ukelele", _musicFaker.Instrument()); + } + + [Test] + public void Band_returns_a_band() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Bands)) + .Returns("The Beatles"); + + Assert.AreEqual("The Beatles", _musicFaker.Band()); + } + + [Test] + public void Album_returns_an_album() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Albums)) + .Returns("Sgt. Pepper's Lonely Hearts Club"); + + Assert.AreEqual("Sgt. Pepper's Lonely Hearts Club", _musicFaker.Album()); + } + + [Test] + public void Genre_returns_a_genre() + { + A.CallTo(() => _fakerContainer.Random.Element(MusicData.Genres)) + .Returns("Rock"); + + Assert.AreEqual("Rock", _musicFaker.Genre()); + } + } +}