Пример #1
0
        public void RegexKoordinatyPropertyPattern_Data_Data()
        {
            var k       = new RegexKoordinaty("11.1111,55.6666", "([0-9]{2}[.][0-9]{4})[,]([0-9]{2}[.][0-9]{4})");
            var pattern = k.Pattern;

            Assert.AreEqual(pattern, "([0-9]{2}[.][0-9]{4})[,]([0-9]{2}[.][0-9]{4})");
        }
Пример #2
0
        public void CountBadLinesTest_GoodFormat_NotReturn()
        {
            var k        = new RegexKoordinaty("11.1111,55.6666");
            var usertext = k.CountBadLines();
            var NewText  = "";

            Assert.AreEqual(NewText, usertext);
        }
Пример #3
0
        public void AllUserTextNewFormat_Data_ShouldFormatData()
        {
            var k        = new RegexKoordinaty("11.1111,55.6666");
            var usertext = k.AllUserTextNewFormat();
            var NewText  = "X: 11.1111 Y: 55.6666";

            Assert.AreEqual(NewText, usertext);
        }
Пример #4
0
        public void RegexKoordinatyPropertyUserText_Data_Data()
        {
            var k        = new RegexKoordinaty("11.1111,55.6666");
            var usertext = k.UserText;
            var NewText  = "11.1111,55.6666";

            Assert.AreEqual(NewText, usertext);
        }
Пример #5
0
        public void AllUserTextNewFormat_Datafromfile_ShouldFormatData()
        {
            var k = new RegexKoordinaty("11.1111,55.6666");

            k.Pathfile = @"d:\ASP\ASP\Task1\Consolka\bin\Release\123.txt";
            var usertext = k.AllUserTextNewFormat();
            var NewText  = "X: 45.8888 Y: 65.9989\r\nX: 33.8595 Y: 66.6595\r\nX: 88.3658 Y: 95.8595\r\nX: 11.5555 Y: 65.6958\r\n";

            Assert.AreEqual(NewText, usertext);
        }
Пример #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("По завершению ввода строк введите: end");
            StringBuilder SB = new StringBuilder();
            //StringBuilder userEnter = new StringBuilder();
            //while(true)
            //{
            //    userEnter.Append(Console.ReadLine());
            //    if (userEnter.ToString()=="end")
            //    {
            //        break;
            //    }
            //    SB.AppendLine(userEnter.ToString());

            //    userEnter.Clear();
            //}

            RegexKoordinaty k = new RegexKoordinaty(SB.ToString());

            ///путь к экзэшнику
            Assembly asm          = Assembly.GetExecutingAssembly();
            string   assemblyPath = new Uri(asm.EscapedCodeBase).LocalPath;

            ///путь к текстовому файлу
            k.Pathfile = Path.Combine(Path.GetDirectoryName(assemblyPath), "12.txt");

            try
            {
                string NewText = k.AllUserTextNewFormat();
                Console.WriteLine(NewText);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message + e.FileName);
            }

            try
            {
                string message = k.CountBadLines();
                Console.WriteLine(message);
            }

            catch (FormatException)
            {
                Console.WriteLine("ВАЖНО!!! Не все строки имели правильный формат");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("ошибка к доступу файла");
            }
            Console.ReadLine();
        }
Пример #7
0
        public void CountBadLines_BadFormat_Exception()
        {
            var k = new RegexKoordinaty("11.1111, 55.6666");

            try
            {
                var ExceptionText = k.CountBadLines();
            }
            catch (FormatException e)
            {
                StringAssert.Contains(e.Message, "1 строк имели неправильный формат. Вводите правильный формат везде");
            }
        }
Пример #8
0
        public void CountBadLines_FileNotExist_Exception()
        {
            var k = new RegexKoordinaty("11.1111, 55.6666");

            k.Pathfile = @"d:\ASP\ASP\Task1\Consolka\bin\Release\13.txt";
            try
            {
                var ExceptionText = k.CountBadLines();
            }
            catch (FileNotFoundException e)
            {
                StringAssert.Contains(e.Message, "Файл не существует либо указан неверный путь");
            }
        }
Пример #9
0
        public void AllUserTextNewFormat_File_Not_Find_Exception()
        {
            var k = new RegexKoordinaty("11.1111, 55.6666");

            k.Pathfile = @"d:\ASP\ASP\Task1\Consolka\bin\Release\13.txt";
            try
            {
                var ExceptionText = k.AllUserTextNewFormat();
            }
            catch (FileNotFoundException e)
            {
                StringAssert.Contains(e.Message, "файл не найден либо указан неверный путь");
            }
        }
Пример #10
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            TextRange       pp = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            RegexKoordinaty k  = new RegexKoordinaty(pp.Text);

            if (new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text.Length > 3)
            {
                FlowDocument myflow  = new FlowDocument();
                string       newtext = k.AllUserTextNewFormat();
                myflow.Blocks.Add(new Paragraph(new Run(newtext)));
                richTextBox1.Document = myflow;

                string       warning = "";
                FlowDocument myflow1 = new FlowDocument();

                try
                {
                    warning = k.CountBadLines();
                }
                catch (FormatException)
                {
                }
                finally
                {
                    myflow1.Blocks.Add(new Paragraph(new Run(warning)));
                    richTextBox2.Document = myflow1;
                }
            }
            if (textBox.Text.Length > 2)
            {
                k.Pathfile = textBox.Text;
                string newtext1 = "";
                try
                {
                    newtext1 = k.AllUserTextNewFormat();
                }
                catch (FileNotFoundException exf)
                {
                    FlowDocument myflow4 = new FlowDocument();
                    myflow4.Blocks.Add(new Paragraph(new Run(exf.Message)));
                    richTextBox2.Document = myflow4;
                }
                FlowDocument myflow2 = new FlowDocument();
                myflow2.Blocks.Add(new Paragraph(new Run(newtext1)));
                richTextBox1.Document = myflow2;

                string       warning1 = "";
                FlowDocument myflow3  = new FlowDocument();

                try
                {
                    warning1 = k.CountBadLines();
                }
                catch (FormatException)
                {
                }
                finally
                {
                    myflow3.Blocks.Add(new Paragraph(new Run(warning1)));
                    richTextBox2.Document = myflow3;
                }
            }
        }