1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Components
.Validator
.Tests
.ValidatorTests
18 using System
.Collections
.Generic
;
20 using NUnit
.Framework
;
23 public class CreditCardValidatorTestCase
25 #region Credit Card Validator Test
28 public void CreditCardValidatorTest()
30 Assert
.IsTrue(CreditCardValidatorTest(null, CreditCardValidator
.CardType
.All
, new string[] { }
));
31 Assert
.IsTrue(CreditCardValidatorTest("2323-2005 77663 554", CreditCardValidator
.CardType
.Unknown
, new string[] { }
));
32 Assert
.IsFalse(CreditCardValidatorTest("3323-2005 77663 554", CreditCardValidator
.CardType
.Unknown
, new string[] { }
));
33 Assert
.IsFalse(CreditCardValidatorTest("3323-2005 77663 554", CreditCardValidator
.CardType
.Unknown
, new string[] { "3323-2005-7766-3554" }
));
34 Assert
.IsTrue(CreditCardValidatorTest("3323-2005 77663 554", CreditCardValidator
.CardType
.Unknown
, new string[] { "3323200577663554" }
));
35 Assert
.IsTrue(CreditCardValidatorTest("4111-1111 1111 1111", CreditCardValidator
.CardType
.VISA
, new string[] { }
));
36 Assert
.IsTrue(CreditCardValidatorTest("3400-0000 0000009", CreditCardValidator
.CardType
.Amex
, new string[] { }
));
37 Assert
.IsTrue(CreditCardValidatorTest("3400-0000 0000 009", CreditCardValidator
.CardType
.Amex
, new string[] { }
));
38 Assert
.IsTrue(CreditCardValidatorTest("6011-0000 00000004", CreditCardValidator
.CardType
.Discover
, new string[] { }
));
39 Assert
.IsTrue(CreditCardValidatorTest("5500-0000 000 00004", CreditCardValidator
.CardType
.MasterCard
, new string[] { }
));
42 private bool CreditCardValidatorTest(string input
, CreditCardValidator
.CardType allowedTypes
, string[] exceptions
)
44 CreditCardValidator validator
= new CreditCardValidator(allowedTypes
, exceptions
);
45 return validator
.IsValid(this, input
);