using System;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;
using Hochbaustatistik.Business;
using Hochbaustatistik.Database;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Edge;
using System.Net;
using System.Data;

namespace Hochbaustatistik.Testing
{
    public class WebTesting
    {   

        [Fact (Skip ="Derzeit keine Daten zum Download vorhanden")]
        public void DownloadList()
        {
            //DownloadFolder
            string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            string pathDownloadedList = Path.Combine(pathUser, "Downloads", "BU-Liste_913000.csv");

            //User: 0521442179
            //Passwort: #Dortmund2022
            IWebDriver driver = new EdgeDriver();

            string loginUrl = "https://www.idev.nrw.de/";

            driver.Navigate().GoToUrl(loginUrl);

            IWebElement site = driver.FindElement(By.Id("05"));
            site.Click();

            site = driver.FindElement(By.Id("loginid"));
            site.SendKeys("0521442179");

            site = driver.FindElement(By.Id("password"));
            site.SendKeys("#Dortmund2022");

            site = driver.FindElement(By.Id("login"));
            site.Click();

            site = driver.FindElement(By.Id("menu100"));
            site.Click();

            site = driver.FindElement(By.LinkText("Bauüberhangsliste"));

            site.Click();

            Thread.Sleep(1500);
            driver.Quit();

            Assert.True(File.Exists(pathDownloadedList));
            File.Delete(pathDownloadedList);
        }        
    }
}
