using DryRunner;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
using WatiN.Core;

namespace Calculator.AcceptanceTests.StepHelpers
{
    [Binding]
    public static class WebBrowser
    {
        private static TestSiteManager _testSiteManager;

        public static IE Current
        {
            get
            {
                if (!ScenarioContext.Current.ContainsKey("browser"))
                    ScenarioContext.Current["browser"] = new IE();
                return ScenarioContext.Current["browser"] as IE;
            }
        }

        [BeforeTestRun]
        public static void SetupIISExpress()
        {
            _testSiteManager = new TestSiteManager("Calculator", new TestSiteOptions()
            {
                Port = 8888,
            });

            _testSiteManager.Start();
        }

        [AfterTestRun]
        public static void DestroyIISExpress()
        {
            _testSiteManager.Stop();
        }

        [AfterScenario]
        public static void DestroyIE()
        {
            Current.Close();
            Current.Dispose();
        }
    }
}
