Exemple #1
0
        public void ZwalidowanyNipPL_ZwracaWlasciwieZwalidowanyNip(string nip, string expected)
        {
            var actual = sut.ZwalidowanyNipPL(nip);

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        private List <string> PobierzDaneZGUS_IE(string nip)
        {
            if (!kontrahentNipWalidacja.CzyNipPoprawny(nip))
            {
                return(null);
            }
            else
            {
                nip = kontrahentNipWalidacja.ZwalidowanyNipPL(nip);
            }

            var     type = Type.GetTypeFromProgID("internetexplorer.application");
            dynamic ie   = Activator.CreateInstance(type);

            ie.Visible = false;
            ie.Navigate("https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx");

            //Oczekiwanie na wlaczenie IE i nawigacje do strony
            while (ie.readyState != 4)
            {
                while (ie.Busy)
                {
                    Thread.Sleep(50);
                }
                Thread.Sleep(50);
            }

            // identyfikacja pola NIP
            dynamic inputElement = null;

            while (inputElement == null)
            {
                inputElement = ie.Document.getElementById("txtNip");
            }

            // wpisanie danych NIP - nip zmienna prywatna metody
            inputElement.Value = nip;

            //kliknięcie przycisku szukaj zindenyfikowanego przez "getElementById"
            ie.Document.getElementById("btnSzukaj").Click();

            //oczekiwanie na odswiezenie strony
            Thread.Sleep(500);

            //
            string textStrony = ie.Document.Body.innerText;

            // loopowanie przez tabele zidentyfikowana na podstawie "getElementsByClassName"
            var table = ie.Document.getElementsByClassName("tabelaZbiorczaListaJednostekAltRow");

            List <string> daneFirmy = new List <string>();

            foreach (var tr in table)            //dla kazdego table row (tr)
            {
                foreach (var td in tr.Children)  //dla kazdego table data (td)
                {
                    daneFirmy.Add(td.innerText); // dodaje elementy do listy
                }
            }

            ie.Quit();
            ie = null;

            return(daneFirmy);
        }