-
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.
* Added the documentation. * Implemented the Business faker. * Added the BusinessFaker to the faker container and main faker class.
- Loading branch information
Showing
9 changed files
with
148 additions
and
1 deletion.
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
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,9 @@ | ||
# Faker.Business | ||
|
||
```cs | ||
Faker.Business.CreditCardNumber() //=> "1228-1221-1221-1431" | ||
Faker.Business.CreditCardExpiryDate() //=> <DateTime: 2015-11-11 ((2457338j,0s,0n),+0s,2299161j)> | ||
Faker.Business.CreditCardType() //=> "visa" | ||
``` |
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,31 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FakerDotNet.Data | ||
{ | ||
internal static class BusinessData | ||
{ | ||
public static readonly IEnumerable<string> CreditCardNumbers = new[] | ||
{ | ||
"1234-2121-1221-1211", | ||
"1212-1221-1121-1234", | ||
"1211-1221-1234-2201", | ||
"1228-1221-1221-1431" | ||
}; | ||
|
||
public static readonly IEnumerable<string> CreditCardTypes = new[] | ||
{ | ||
"visa", | ||
"mastercard", | ||
"american_express", | ||
"discover", | ||
"diners_club", | ||
"jcb", | ||
"switch", | ||
"solo", | ||
"dankort", | ||
"maestro", | ||
"forbrugsforeningen", | ||
"laser" | ||
}; | ||
} | ||
} |
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
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
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,37 @@ | ||
using System; | ||
using FakerDotNet.Data; | ||
|
||
namespace FakerDotNet.Fakers | ||
{ | ||
public interface IBusinessFaker | ||
{ | ||
string CreditCardNumber(); | ||
DateTime CreditCardExpiryDate(); | ||
string CreditCardType(); | ||
} | ||
|
||
internal class BusinessFaker : IBusinessFaker | ||
{ | ||
private readonly IFakerContainer _fakerContainer; | ||
|
||
public BusinessFaker(IFakerContainer fakerContainer) | ||
{ | ||
_fakerContainer = fakerContainer; | ||
} | ||
|
||
public string CreditCardNumber() | ||
{ | ||
return _fakerContainer.Random.Element(BusinessData.CreditCardNumbers); | ||
} | ||
|
||
public DateTime CreditCardExpiryDate() | ||
{ | ||
return _fakerContainer.Date.Forward(365 * (int) _fakerContainer.Number.Between(1, 5)); | ||
} | ||
|
||
public string CreditCardType() | ||
{ | ||
return _fakerContainer.Random.Element(BusinessData.CreditCardTypes); | ||
} | ||
} | ||
} |
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
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
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,54 @@ | ||
using System; | ||
using FakeItEasy; | ||
using FakerDotNet.Data; | ||
using FakerDotNet.Fakers; | ||
using NUnit.Framework; | ||
|
||
namespace FakerDotNet.Tests.Fakers | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class BusinessFakerTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fakerContainer = A.Fake<IFakerContainer>(); | ||
_businessFaker = new BusinessFaker(_fakerContainer); | ||
} | ||
|
||
private IFakerContainer _fakerContainer; | ||
private IBusinessFaker _businessFaker; | ||
|
||
[Test] | ||
public void CreditCardNumber_returns_a_credit_card_number() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(BusinessData.CreditCardNumbers)) | ||
.Returns("1228-1221-1221-1431"); | ||
|
||
Assert.AreEqual("1228-1221-1221-1431", _businessFaker.CreditCardNumber()); | ||
} | ||
|
||
[Test] | ||
public void CreditCardExpiryDate_returns_a_credit_card_expiry_date() | ||
{ | ||
var expectedDate = DateTime.UtcNow.AddYears(1); | ||
|
||
A.CallTo(() => _fakerContainer.Date.Forward(365 * 1)) | ||
.Returns(expectedDate); | ||
A.CallTo(() => _fakerContainer.Number.Between(1, 5)) | ||
.Returns(1); | ||
|
||
Assert.AreEqual(expectedDate, _businessFaker.CreditCardExpiryDate()); | ||
} | ||
|
||
[Test] | ||
public void CreditCardType_returns_a_credit_card_type() | ||
{ | ||
A.CallTo(() => _fakerContainer.Random.Element(BusinessData.CreditCardTypes)) | ||
.Returns("visa"); | ||
|
||
Assert.AreEqual("visa", _businessFaker.CreditCardType()); | ||
} | ||
} | ||
} |