-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using FakerDotNet.Data; | ||
|
||
namespace FakerDotNet.Fakers | ||
{ | ||
public interface ICoffeeFaker | ||
{ | ||
string BlendName(); | ||
string Origin(); | ||
string Variety(); | ||
string Notes(); | ||
string Intensifier(); | ||
} | ||
|
||
internal class CoffeeFaker : ICoffeeFaker | ||
{ | ||
private readonly IFakerContainer _fakerContainer; | ||
|
||
public CoffeeFaker(IFakerContainer fakerContainer) | ||
{ | ||
_fakerContainer = fakerContainer; | ||
} | ||
|
||
public string BlendName() | ||
{ | ||
return string.Join(" ", | ||
_fakerContainer.Random.Element(CoffeeData.BlendNamePrefixes), | ||
_fakerContainer.Random.Element(CoffeeData.BlendNameSuffixes)); | ||
} | ||
|
||
public string Origin() | ||
{ | ||
var country = _fakerContainer.Random.Element(CoffeeData.CountriesWithRegions.Keys); | ||
var region = _fakerContainer.Random.Element(CoffeeData.CountriesWithRegions[country]); | ||
return $"{region}, {country}"; | ||
} | ||
|
||
public string Variety() | ||
{ | ||
return _fakerContainer.Random.Element(CoffeeData.Varieties); | ||
} | ||
|
||
public string Notes() | ||
{ | ||
return string.Join(", ", | ||
_fakerContainer.Random.Element(CoffeeData.Intensifiers), | ||
_fakerContainer.Random.Element(CoffeeData.Bodies), | ||
string.Join(", ", _fakerContainer.Random.Assortment(CoffeeData.Descriptors, 3))); | ||
} | ||
|
||
public string Intensifier() | ||
{ | ||
return _fakerContainer.Random.Element(CoffeeData.Intensifiers); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using FakeItEasy; | ||
using FakerDotNet.Data; | ||
using FakerDotNet.Fakers; | ||
using NUnit.Framework; | ||
|
||
namespace FakerDotNet.Tests.Fakers | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class CoffeeFakerTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fakerContainer = A.Fake<IFakerContainer>(); | ||
_coffeeFaker = new CoffeeFaker(_fakerContainer); | ||
} | ||
|
||
private IFakerContainer _fakerContainer; | ||
private ICoffeeFaker _coffeeFaker; | ||
|
||
[Test] | ||
public void BlendName_returns_a_blend_name() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.BlendNamePrefixes)) | ||
.Returns("Summer"); | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.BlendNameSuffixes)) | ||
.Returns("Solstice"); | ||
|
||
Assert.AreEqual("Summer Solstice", _coffeeFaker.BlendName()); | ||
} | ||
|
||
[Test] | ||
public void Origin_returns_an_origin() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.CountriesWithRegions.Keys)) | ||
.Returns("Guatemala"); | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.CountriesWithRegions["Guatemala"])) | ||
.Returns("Antigua"); | ||
|
||
Assert.AreEqual("Antigua, Guatemala", _coffeeFaker.Origin()); | ||
} | ||
|
||
[Test] | ||
public void Variety_returns_a_variety() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.Varieties)) | ||
.Returns("Pacas"); | ||
|
||
Assert.AreEqual("Pacas", _coffeeFaker.Variety()); | ||
} | ||
|
||
[Test] | ||
public void Notes_returns_some_notes() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.Intensifiers)) | ||
.Returns("balanced"); | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.Bodies)) | ||
.Returns("silky"); | ||
A.CallTo(() => _fakerContainer.Random.Assortment(CoffeeData.Descriptors, 3)) | ||
.Returns(new[] {"marzipan", "orange-creamsicle", "bergamot"}); | ||
|
||
Assert.AreEqual("balanced, silky, marzipan, orange-creamsicle, bergamot", _coffeeFaker.Notes()); | ||
} | ||
|
||
[Test] | ||
public void Intensifier_returns_an_intensifier() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(CoffeeData.Intensifiers)) | ||
.Returns("quick"); | ||
|
||
Assert.AreEqual("quick", _coffeeFaker.Intensifier()); | ||
} | ||
} | ||
} |