コード例 #1
0
        public void LengthTest()
        {
            // Too short
            var businessId = "12345678";
            var spec       = new BusinessIdSpecification();
            var actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("BusinessId length is not 9 characters"));

            // Too long
            businessId = "1234567890";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("BusinessId length is not 9 characters"));

            // Empty
            businessId = string.Empty;
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("BusinessId length is not 9 characters"));

            // Correct length
            businessId = "123456789";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsFalse(spec.ReasonsForDissatisfaction.Contains("BusinessId length is not 9 characters"));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NaZzu/CGIEnnakko
        static void Main(string[] args)
        {
            Console.WriteLine("type exit to exit");
            while (true)
            {
restart:
                Console.Write("Please enter your business digit:");
                string input = System.Console.ReadLine();
                if (input.Equals("exit"))
                {
                    break;
                }

                BusinessIdSpecification test = new BusinessIdSpecification();
                test.IsSatisfiedBy(input);
                foreach (string errorsDigit in test.ReasonsForDissatisfaction)
                {
                    if (!test.IsSatisfiedBy(input))
                    {
                        Console.Clear();
                        Console.WriteLine(errorsDigit);
                        Console.WriteLine("Please do it right this time");
                        goto restart;
                    }
                }
                Console.Clear();
                Console.WriteLine("You have entered the correct amount of digits");
                Console.WriteLine("Please enter your control mark");

                string control = System.Console.ReadLine();
                test.IsControlOk(control);

                if (control.Equals("exit"))
                {
                    break;
                }


                foreach (string errorsControl in test.ControlMarkDissaatisfaction)
                {
                    if (!test.IsControlOk(control))
                    {
                        Console.Clear();
                        Console.WriteLine(errorsControl);
                        Console.WriteLine("You typed poorly, let's try again from the beginning");
                        goto restart;
                    }
                }
                Console.Clear();
                Console.WriteLine("You typed a correct BusinessID!");
                Console.WriteLine("Well done lad, press any key to exit");
                Console.ReadKey();
                break;
            }
        }
コード例 #3
0
        public void ReasonsGetClearedTest()
        {
            var businessId = "A20481.1"; // invalid business id
            var spec       = new BusinessIdSpecification();

            spec.IsSatisfiedBy(businessId);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Any());

            businessId = "0204819-8";       // valid business id
            spec.IsSatisfiedBy(businessId); // same spec object
            Assert.IsFalse(spec.ReasonsForDissatisfaction.Any());
        }
コード例 #4
0
        public void ChecksumTest()
        {
            var businessId = "1234567-1";
            var spec       = new BusinessIdSpecification();
            var actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Checksum cannot be 1"));

            businessId = "0204819-9";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Checksum 9 is not correct, should be 8"));
        }
コード例 #5
0
        public void CorrectBusinessIdTest()
        {
            var businessId = "0204819-8";
            var spec       = new BusinessIdSpecification();
            var actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsTrue(actual);
            Assert.IsFalse(spec.ReasonsForDissatisfaction.Any());

            businessId = "2542362-4";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsTrue(actual);
            Assert.IsFalse(spec.ReasonsForDissatisfaction.Any());
        }
コード例 #6
0
        public void NullTest()
        {
            string businessId = null;
            var    spec       = new BusinessIdSpecification();
            var    actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("BusinessId should not be null"));
        }
コード例 #7
0
            static void Main()
            {
                string tunnus = "kk";
                BusinessIdSpecification <string> testi = new BusinessIdSpecification <string>();

                testi.IsSatisfiedBy(id);
                string[] virheet = testi.ReasonsForDissatisfaction.ToArray();
                Console.ReadLine();
            }
コード例 #8
0
        public void SeparatorTest()
        {
            // Wrong separator
            var businessId = "1234567.8";
            var spec       = new BusinessIdSpecification();
            var actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Separator character '-' not found in correct position"));

            // Wrong position
            businessId = "-------0-";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Separator character '-' not found in correct position"));

            // Correct separator in correct position
            businessId = "---------";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsFalse(spec.ReasonsForDissatisfaction.Contains("Separator character '-' not found in correct position"));
        }
コード例 #9
0
        public void MultipleReasonsTest()
        {
            var businessId = "A20481.1";
            var spec       = new BusinessIdSpecification();
            var actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("BusinessId length is not 9 characters"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Separator character '-' not found in correct position"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character A at position 1 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Checksum cannot be 1"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Checksum 1 is not correct, should be 2"));
        }
コード例 #10
0
        public void DigitTest()
        {
            // No digits
            var businessId = "ABCDEFGH½";
            var spec       = new BusinessIdSpecification();
            var actual     = spec.IsSatisfiedBy(businessId);

            Assert.IsFalse(actual);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character A at position 1 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character B at position 2 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character C at position 3 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character D at position 4 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character E at position 5 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character F at position 6 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character G at position 7 is not a digit"));
            Assert.IsFalse(spec.ReasonsForDissatisfaction.Contains("Character H at position 8 is not a digit"));
            Assert.IsTrue(spec.ReasonsForDissatisfaction.Contains("Character ½ at position 9 is not a digit"));

            // Correct digits
            businessId = "1234567A8";
            actual     = spec.IsSatisfiedBy(businessId);
            Assert.IsTrue(spec.ReasonsForDissatisfaction.All(r => !r.EndsWith("is not a digit", StringComparison.CurrentCulture)));
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: vvenla/cgiEnnakko
        static void Main(string[] args)
        {
            Console.WriteLine("Press x to exit");
            while (true)
            {
                Console.Write("Write id: ");
                string id = System.Console.ReadLine();

                if (id.Equals("x"))
                {
                    break;
                }

                BusinessIdSpecification test = new BusinessIdSpecification();
                test.IsSatisfiedBy(id);

                foreach (string error in test.ReasonsForDissatisfaction)
                {
                    Console.WriteLine(error);
                }
            }
        }