Skip to content

Commit

Permalink
Added tests to make sure we throw exceptions if we are passed null or…
Browse files Browse the repository at this point in the history
… empty strings.
  • Loading branch information
mrstebo committed Sep 20, 2018
1 parent 357bbdd commit 8b8ff5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FakerDotNet/Fakers/FakeFaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public FakeFaker(IFakerContainer fakerContainer)

public string F(string format)
{
if (string.IsNullOrEmpty(format)) throw new FormatException("A string must be specified");

var result = format;
Match match;
while ((match = Regex.Match(result, @"\{(\w+).(\w+)\}")).Success)
Expand Down
18 changes: 18 additions & 0 deletions tests/FakerDotNet.Tests/Fakers/FakeFakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public void F_handles_duplicate_placeholders()
Assert.AreEqual("Test1 Test2", _fakeFaker.F(format));
}

[Test]
public void F_with_null_throws_FormatException()
{
var ex = Assert.Throws<FormatException>(() => _fakeFaker.F(null));

Assert.AreEqual("A string must be specified", ex.Message);
}

[Test]
public void F_with_empty_string_throws_FormatException()
{
const string format = "";

var ex = Assert.Throws<FormatException>(() => _fakeFaker.F(format));

Assert.AreEqual("A string must be specified", ex.Message);
}

[Test]
public void F_with_invalid_faker_throws_FormatException()
{
Expand Down

0 comments on commit 8b8ff5e

Please sign in to comment.