Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add troy #57

Merged
merged 4 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Dedge.Cardidy/CardType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum CardType
RuPay,
InstaPayment,

Troy,
LankaPay,
Humo
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
Expand Down
2 changes: 2 additions & 0 deletions src/Dedge.Cardidy/Cardidy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static class Cardidy
new RuPay(),
new InstaPayment(),


new Troy(),
new LankaPay(),
new Humo()
};
Expand Down
5 changes: 5 additions & 0 deletions src/Dedge.Cardidy/Model/Cards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ internal record InstaPayment : ALuhnCard
public InstaPayment() : base(CardType.InstaPayment, new [] { new PaddedRange(637, 639) }, Sixteen) { }
}

internal record Troy : ALuhnCard
{
public Troy() : base(CardType.Troy, new[] { 65, 9792 }, Sixteen) { }
}

internal record LankaPay : ACard
{
public LankaPay() : base(CardType.LankaPay, 357111, Sixteen) { }
Expand Down
16 changes: 10 additions & 6 deletions src/Tests/IdentifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class IdentifyTests
public CardType ShouldIdentifyAsMir(string cardNumber) => Cardidy.Identify(cardNumber, useCheck: false).First();

[TestCase("6011-773331987017", ExpectedResult = new[] { CardType.Discover, CardType.RuPay })]
[TestCase("65-18958254583145", ExpectedResult = new[] { CardType.Discover, CardType.RuPay })]
[TestCase("65-18958254583145", ExpectedResult = new[] { CardType.Discover, CardType.RuPay, CardType.Troy })]
[TestCase("622126-1230594033", ExpectedResult = new[] { CardType.Discover, CardType.UnionPay })]
[TestCase("622225-1230594033", ExpectedResult = new[] { CardType.Discover, CardType.UnionPay })]
[TestCase("622925-1230594033", ExpectedResult = new[] { CardType.Discover, CardType.UnionPay })]
Expand All @@ -110,9 +110,9 @@ public class IdentifyTests
[TestCase("6500100000000001", true, ExpectedResult = new[] { CardType.Verve })]
[TestCase("6500270000000000", true, ExpectedResult = new[] { CardType.Verve })]
[TestCase("6500270000000000000", true, ExpectedResult = new[] { CardType.Verve })]
[TestCase("6500020000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover, CardType.RuPay })]
[TestCase("6500100000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover, CardType.RuPay })]
[TestCase("6500270000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover, CardType.RuPay })]
[TestCase("6500020000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover, CardType.RuPay, CardType.Troy })]
[TestCase("6500100000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover, CardType.RuPay, CardType.Troy })]
[TestCase("6500270000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover, CardType.RuPay, CardType.Troy })]
[TestCase("65002700000000000", false, ExpectedResult = new[] { CardType.Discover })]
[TestCase("650027000000000000", false, ExpectedResult = new[] { CardType.Discover })]
[TestCase("6500270000000000000", false, ExpectedResult = new[] { CardType.Verve, CardType.Discover })]
Expand All @@ -123,7 +123,7 @@ public class IdentifyTests
[TestCase("621055300027361412", ExpectedResult = CardType.UnionPay)]
[TestCase("6210553000273614234", ExpectedResult = CardType.UnionPay)]
public CardType ShouldIdentifyAsUnionPay(string cardNumber) => Cardidy.Identify(cardNumber, useCheck: false, ignoreNoise: true).First();

[TestCase("5610553000273614", ExpectedResult = CardType.BankCard)]
[TestCase("5602213166347852", ExpectedResult = CardType.BankCard)]
[TestCase("5602253004948429", ExpectedResult = CardType.BankCard)]
Expand All @@ -150,7 +150,7 @@ public class IdentifyTests

// note that: 65 is shared by both RuPay and Discover; 353 and 356 are part of JCB Card
[TestCase("6000123456789010", ExpectedResult = new[] { CardType.RuPay })]
[TestCase("6505071901000005", ExpectedResult = new[] { CardType.Discover, CardType.RuPay })]
[TestCase("6505071901000005", ExpectedResult = new[] { CardType.Discover, CardType.RuPay, CardType.Troy })]
[TestCase("8104830500000000", ExpectedResult = new[] { CardType.RuPay })]
[TestCase("8204930400000001", ExpectedResult = new[] { CardType.RuPay })]
[TestCase("3534930400000001", ExpectedResult = new[] { CardType.Jcb, CardType.RuPay })]
Expand All @@ -167,6 +167,10 @@ public class IdentifyTests
[TestCase("6384960368309025--", ExpectedResult = CardType.InstaPayment)]
public CardType ShouldIdentifyAsInstaPayment(string cardNumber) => Cardidy.Identify(cardNumber, useCheck: true, ignoreNoise: true).First();

[TestCase("9792123456789876", ExpectedResult = new[] { CardType.Troy })]
[TestCase("65-00000004583145", ExpectedResult = new[] { CardType.Discover, CardType.RuPay, CardType.Troy })]
public IEnumerable<CardType> ShouldIdentifyAsTroy(string cardNumber) => Cardidy.Identify(cardNumber, useCheck: false, ignoreNoise: true).ToArray();

[TestCase("9860123456789876", ExpectedResult = CardType.Humo)]
[TestCase("9860010102205720", ExpectedResult = CardType.Humo)]
public CardType ShouldIdentifyAsHumo(string cardNumber) => Cardidy.Identify(cardNumber).First();
Expand Down