Beispiel #1
0
        /// <summary>Main program console</summary>
        static void Main(string[] args)
        {
            bool running = true;

            BusinessIdentifierSpecification<string> businessIdentifierChecker = new BusinessIdentifierSpecification<string>();

            while (running)
            {

                Console.WriteLine("\n\nType business id (enter to exit, 'test' to run the test set): ");
                Console.ForegroundColor = ConsoleColor.White;
                string businessIdentifier = Console.ReadLine();
                Console.ResetColor();

                if (businessIdentifier.ToLower() == "test")
                {
                    // run test set
                    runTestSet(businessIdentifierChecker);
                }
                else if (businessIdentifier.Length != 0)
                {
                    // test identifier input
                    testIdentifier(businessIdentifier, businessIdentifierChecker);
                }
                else
                {
                    // exit
                    return;
                }
            }
        }
Beispiel #2
0
        /// <summary>Test set</summary>
        private static void runTestSet(BusinessIdentifierSpecification<string> checker)
        {
            Dictionary<string, bool> testData = new Dictionary<string, bool>();

            // too short
            testData.Add("1", false);

            // too long
            testData.Add("24713849XX", false);

            // too short, missing separator
            testData.Add("24713849", false);

            // checknum does not match
            testData.Add("2471385-9", false);

            // checknum does not match
            testData.Add("2471384-8", false);

            // wrong character
            testData.Add("2471A84-9", false);

            // more wrong characters
            testData.Add("a4b1C8D-E", false);

            // check num 1
            testData.Add("2471384-1", false);

            // check num count result 1
            testData.Add("1001000-9", false);

            // ok, real business id
            testData.Add("2471384-9", true);

            // ok, checknum zero
            testData.Add("1572860-0", true);

            foreach (var item in testData)
            {

                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\n" + item.Key + ": ");

                if (testIdentifier(item.Key, checker) == item.Value)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("PASSED");
                    Console.ResetColor();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("FAILED");
                    Console.ResetColor();
                }
            }
        }
        public void testBI(int testCase, string bi)
        {
            BusinessIdentifierSpecification bis = new BusinessIdentifierSpecification();

            Console.WriteLine("TEST " + testCase + "\nBI: " + bi + "\n\tisSatisfied:\t" + bis.IsSatisfiedBy(bi));
            Console.WriteLine("\tinvalidity reasons:");
            foreach (string reason in bis.ReasonsForDissatisfaction)
            {
                Console.WriteLine("\t\t\t" + reason);
            }
            Console.ReadLine();
        }
        public static bool TryCreate(string businessId, out BusinessIdentifier result, out string failureReason)
        {
            var specification = new BusinessIdentifierSpecification();
            if (specification.IsSatisfiedBy(businessId))
            {
                result = new BusinessIdentifier(businessId);
                failureReason = string.Empty;
                return true;
            }

            result = null;
            failureReason = specification.GetReasonsForDissatisfactionSeparatedWithNewLine();
            return false;
        }
        public static BusinessIdentifier Create(string businessId)
        {
            if (businessId == null)
            {
                throw new ArgumentNullException("businessId");
            }

            var specification = new BusinessIdentifierSpecification();
            if (specification.IsSatisfiedBy(businessId))
            {
                return new BusinessIdentifier(businessId);
            }
            throw new ArgumentException(string.Format("Business id '{0}' does not satisfy specification.", businessId), "businessId");
        }
Beispiel #6
0
        /// <summary>Test identifier validity</summary>
        private static bool testIdentifier(string bi, BusinessIdentifierSpecification<string> checker)
        {
            //BusinessIdChecker<string> businessIdentifierSpecification = new BusinessIdChecker<string>();
            if (checker.IsSatisfiedBy(bi))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Id OK");
                Console.ResetColor();
                return true;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Id not OK, reasons: ");
                Console.ResetColor();

                foreach (string reason in checker.ReasonsForDissatisfaction)
                {
                    Console.WriteLine(reason.ToString());
                }
                return false;
            }
        }
 private static void AssertDissatisfiedSpecification(string value)
 {
     var specification = new BusinessIdentifierSpecification();
     Assert.IsFalse(specification.IsSatisfiedBy(value));
     Assert.IsFalse(string.IsNullOrWhiteSpace(specification.GetReasonsForDissatisfactionSeparatedWithNewLine()));
 }
 public void InspectCorrectCheckDigitHandlesNullValues()
 {
     BusinessIdentifierSpecification spec = new BusinessIdentifierSpecification(new int[] { 7, 9, 10, 5, 8, 4, 2 });
     spec.InspectCorrectCheckDigit(null);
 }
 public void InspectCorrectCheckDigitHandlesEmptyId()
 {
     BusinessIdentifierSpecification spec = new BusinessIdentifierSpecification(new int[] { 7, 9, 10, 5, 8, 4, 2 });
     spec.InspectCorrectCheckDigit(new BusinessId(""));
 }