Skip to content

Commit 97600e0

Browse files
authored
Added the ChuckNorris faker (#100)
* Added the documentation * Added the data for the ChuckNorris faker * Implemented the ChuckNorrisFaker * Added the ChuckNorrisFaker to the main faker classes.
1 parent 47dfc88 commit 97600e0

File tree

9 files changed

+166
-2
lines changed

9 files changed

+166
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ A .NET port of the Ruby [faker](https://github.com/stympy/faker) gem
1919
- [Faker.Boolean](doc/boolean.md)
2020
- [Faker.Business](doc/business.md)
2121
- [Faker.Cat](doc/cat.md)
22+
- [Faker.ChuckNorris](doc/chuck_norris.md)
2223
- [Faker.Color](doc/color.md)
2324
- [Faker.Company](doc/company.md)
2425
- [Faker.Date](doc/date.md)

doc/chuck_norris.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Faker.ChuckNorris
2+
3+
```cs
4+
Faker.ChuckNorris.Fact() //=> "Chuck Norris can solve the Towers of Hanoi in one move."
5+
```
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System.Collections.Generic;
2+
3+
namespace FakerDotNet.Data
4+
{
5+
internal static class ChuckNorrisData
6+
{
7+
public static readonly IEnumerable<string> Facts = new[]
8+
{
9+
"All arrays Chuck Norris declares are of infinite size, because Chuck Norris knows no bounds.",
10+
"Chuck Norris doesn't have disk latency because the hard drive knows to hurry the hell up.",
11+
"All browsers support the hex definitions #chuck and #norris for the colors black and blue.",
12+
"Chuck Norris can't test for equality because he has no equal.",
13+
"Chuck Norris doesn't need garbage collection because he doesn't call .Dispose(), he calls .DropKick().",
14+
"Chuck Norris's first program was kill -9.", "Chuck Norris burst the dot com bubble.",
15+
"Chuck Norris writes code that optimizes itself.",
16+
"Chuck Norris can write infinite recursion functions... and have them return.",
17+
"Chuck Norris can solve the Towers of Hanoi in one move.",
18+
"The only pattern Chuck Norris knows is God Object.",
19+
"Chuck Norris finished World of Warcraft.",
20+
"Project managers never ask Chuck Norris for estimations... ever.",
21+
"Chuck Norris doesn't use web standards as the web will conform to him.",
22+
"\"It works on my machine\" always holds true for Chuck Norris.",
23+
"Whiteboards are white because Chuck Norris scared them that way.",
24+
"Chuck Norris's beard can type 140 wpm.",
25+
"Chuck Norris can unit test an entire application with a single assert.",
26+
"Chuck Norris doesn't bug hunt, as that signifies a probability of failure. He goes bug killing.",
27+
"Chuck Norris's keyboard doesn't have a Ctrl key because nothing controls Chuck Norris.",
28+
"Chuck Norris doesn't need a debugger, he just stares down the bug until the code confesses.",
29+
"Chuck Norris can access private methods.",
30+
"Chuck Norris can instantiate an abstract class.",
31+
"Chuck Norris doesn't need to know about class factory pattern. He can instantiate interfaces.",
32+
"The class object inherits from Chuck Norris.",
33+
"For Chuck Norris, NP-Hard = O(1).",
34+
"Chuck Norris knows the last digit of PI.",
35+
"Chuck Norris can divide by zero.",
36+
"Chuck Norris doesn't get compiler errors, the language changes itself to accommodate Chuck Norris.",
37+
"The programs that Chuck Norris writes don't have version numbers because he only writes them once. If a user reports a bug or has a feature request they don't live to see the sun set.",
38+
"Chuck Norris doesn't believe in floating point numbers because they can't be typed on his binary keyboard.",
39+
"Chuck Norris solved the Travelling Salesman problem in O(1) time.",
40+
"Chuck Norris never gets a syntax error. Instead, the language gets a DoesNotConformToChuck error.",
41+
"No statement can catch the ChuckNorrisException.",
42+
"Chuck Norris doesn't program with a keyboard. He stares the computer down until it does what he wants.",
43+
"Chuck Norris doesn't pair program.",
44+
"Chuck Norris can write multi-threaded applications with a single thread.",
45+
"There is no Esc key on Chuck Norris' keyboard, because no one escapes Chuck Norris.",
46+
"Chuck Norris doesn't delete files, he blows them away.",
47+
"Chuck Norris can binary search unsorted data.",
48+
"Chuck Norris breaks RSA 128-bit encrypted codes in milliseconds.",
49+
"Chuck Norris went out of an infinite loop.",
50+
"Chuck Norris can read all encrypted data, because nothing can hide from Chuck Norris.",
51+
"Chuck Norris hosting is 101% uptime guaranteed.",
52+
"When a bug sees Chuck Norris, it flees screaming in terror, and then immediately self-destructs to avoid being roundhouse-kicked.",
53+
"Chuck Norris rewrote the Google search engine from scratch.",
54+
"Chuck Norris doesn't need the cloud to scale his applications, he uses his laptop.",
55+
"Chuck Norris can access the DB from the UI.",
56+
"Chuck Norris' protocol design method has no status, requests or responses, only commands.",
57+
"Chuck Norris' programs occupy 150% of CPU, even when they are not executing.",
58+
"Chuck Norris can spawn threads that complete before they are started.",
59+
"Chuck Norris programs do not accept input.",
60+
"Chuck Norris doesn't need an OS.",
61+
"Chuck Norris can compile syntax errors.",
62+
"Chuck Norris compresses his files by doing a flying round house kick to the hard drive.",
63+
"Chuck Norris doesn't use a computer because a computer does everything slower than Chuck Norris.",
64+
"You don't disable the Chuck Norris plug-in, it disables you.",
65+
"Chuck Norris doesn't need a java compiler, he goes straight to .war",
66+
"Chuck Norris can use GOTO as much as he wants to. Telling him otherwise is considered harmful.",
67+
"There is nothing regular about Chuck Norris' expressions.",
68+
"Quantum cryptography does not work on Chuck Norris. When something is being observed by Chuck it stays in the same state until he's finished.",
69+
"There is no need to try catching Chuck Norris' exceptions for recovery; every single throw he does is fatal.",
70+
"Chuck Norris' beard is immutable.",
71+
"Chuck Norris' preferred IDE is hexedit.",
72+
"Chuck Norris is immutable. If something's going to change, it's going to have to be the rest of the universe.",
73+
"Chuck Norris' addition operator doesn't commute; it teleports to where he needs it to be.",
74+
"Anonymous methods and anonymous types are really all called Chuck Norris. They just don't like to boast.",
75+
"Chuck Norris doesn't have performance bottlenecks. He just makes the universe wait its turn.",
76+
"Chuck Norris does not use exceptions when programming. He has not been able to identify any of his code that is not exceptional.",
77+
"When Chuck Norris' code fails to compile the compiler apologises.",
78+
"Chuck Norris does not use revision control software. None of his code has ever needed revision.",
79+
"Chuck Norris can recite π. Backwards.",
80+
"When Chuck Norris points to null, null quakes in fear.",
81+
"Chuck Norris has root access to your system.",
82+
"When Chuck Norris gives a method an argument, the method loses.",
83+
"Chuck Norris' keyboard doesn't have a F1 key, the computer asks him for help.",
84+
"When Chuck Norris presses Ctrl+Alt+Delete, worldwide computer restart is initiated."
85+
};
86+
}
87+
}

src/FakerDotNet/Faker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static class Faker
1515
public static IBooleanFaker Boolean { get; } = Container.Boolean;
1616
public static IBusinessFaker Business { get; } = Container.Business;
1717
public static ICatFaker Cat { get; } = Container.Cat;
18+
public static IChuckNorrisFaker ChuckNorris { get; } = Container.ChuckNorris;
1819
public static IColorFaker Color { get; } = Container.Color;
1920
public static ICompanyFaker Company { get; } = Container.Company;
2021
public static IDateFaker Date { get; } = Container.Date;

src/FakerDotNet/FakerContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal interface IFakerContainer
1313
IBooleanFaker Boolean { get; }
1414
IBusinessFaker Business { get; }
1515
ICatFaker Cat { get; }
16+
IChuckNorrisFaker ChuckNorris { get; }
1617
IColorFaker Color { get; }
1718
ICompanyFaker Company { get; }
1819
IDateFaker Date { get; }
@@ -53,6 +54,7 @@ public FakerContainer()
5354
Boolean = new BooleanFaker();
5455
Business = new BusinessFaker(this);
5556
Cat = new CatFaker(this);
57+
ChuckNorris = new ChuckNorrisFaker(this);
5658
Color = new ColorFaker(this);
5759
Company = new CompanyFaker(this);
5860
Date = new DateFaker();
@@ -89,6 +91,7 @@ public FakerContainer()
8991
public IBooleanFaker Boolean { get; }
9092
public IBusinessFaker Business { get; }
9193
public ICatFaker Cat { get; }
94+
public IChuckNorrisFaker ChuckNorris { get; }
9295
public IColorFaker Color { get; }
9396
public ICompanyFaker Company { get; }
9497
public IDateFaker Date { get; }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using FakerDotNet.Data;
2+
3+
namespace FakerDotNet.Fakers
4+
{
5+
public interface IChuckNorrisFaker
6+
{
7+
string Fact();
8+
}
9+
10+
internal class ChuckNorrisFaker : IChuckNorrisFaker
11+
{
12+
private readonly IFakerContainer _fakerContainer;
13+
14+
public ChuckNorrisFaker(IFakerContainer _fakerContainer)
15+
{
16+
this._fakerContainer = _fakerContainer;
17+
}
18+
19+
public string Fact()
20+
{
21+
return _fakerContainer.Random.Element(ChuckNorrisData.Facts);
22+
}
23+
}
24+
}

tests/FakerDotNet.Tests/FakerContainerTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,19 @@ public void Business_returns_IBusinessFaker()
6262
{
6363
Assert.IsInstanceOf<IBusinessFaker>(_fakerContainer.Business);
6464
}
65-
65+
6666
[Test]
6767
public void Cat_returns_ICatFaker()
6868
{
6969
Assert.IsInstanceOf<ICatFaker>(_fakerContainer.Cat);
7070
}
7171

72+
[Test]
73+
public void ChuckNorris_returns_IChuckNorrisFaker()
74+
{
75+
Assert.IsInstanceOf<IChuckNorrisFaker>(_fakerContainer.ChuckNorris);
76+
}
77+
7278
[Test]
7379
public void Color_returns_IColorFaker()
7480
{

tests/FakerDotNet.Tests/FakerTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ public void Business_returns_IBusinessFaker()
5454
{
5555
Assert.IsInstanceOf<IBusinessFaker>(Faker.Business);
5656
}
57-
57+
5858
[Test]
5959
public void Cat_returns_ICatFaker()
6060
{
6161
Assert.IsInstanceOf<ICatFaker>(Faker.Cat);
6262
}
6363

64+
[Test]
65+
public void ChuckNorris_returns_IChuckNorrisFaker()
66+
{
67+
Assert.IsInstanceOf<IChuckNorrisFaker>(Faker.ChuckNorris);
68+
}
69+
6470
[Test]
6571
public void Color_returns_IColorFaker()
6672
{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using FakeItEasy;
2+
using FakerDotNet.Data;
3+
using FakerDotNet.Fakers;
4+
using NUnit.Framework;
5+
6+
namespace FakerDotNet.Tests.Fakers
7+
{
8+
[TestFixture]
9+
[Parallelizable]
10+
public class ChuckNorrisFakerTests
11+
{
12+
[SetUp]
13+
public void SetUp()
14+
{
15+
_fakerContainer = A.Fake<IFakerContainer>();
16+
_chuckNorrisFaker = new ChuckNorrisFaker(_fakerContainer);
17+
}
18+
19+
private IFakerContainer _fakerContainer;
20+
private IChuckNorrisFaker _chuckNorrisFaker;
21+
22+
[Test]
23+
public void Fact_returns_a_fact()
24+
{
25+
A.CallTo(() => _fakerContainer.Random.Element(ChuckNorrisData.Facts))
26+
.Returns("Chuck Norris can solve the Towers of Hanoi in one move.");
27+
28+
Assert.AreEqual("Chuck Norris can solve the Towers of Hanoi in one move.", _chuckNorrisFaker.Fact());
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)