using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;
using Calculator.AcceptanceTests.StepHelpers;
using WatiN.Core;

namespace Calculator.AcceptanceTests.SharedSteps
{
    [Binding]
    public class PageInteraction
    {
        [Then("the page contains a \"(.*)\" element with id \"(.*)\"")]
        public void ThePageContainsAnElementWithId(string element, string id)
        {
            // Arrange

            // Act
            Element pageElement = WebBrowser.Current.Element(id);

            // Assert
            Assert.AreEqual(element.ToLower(), pageElement.TagName.ToLower(), string.Format("Element with id \"{0}\" was expected to be of type \"{1}\", but instead was of type \"{2}\".", id, element.ToLower(), pageElement.TagName.ToLower()));
        }

        [When("the user clicks the \"(.*)\" element with the id \"(.*)\"")]
        public void TheUserClicksTheElementWithId(string element, string id)
        {
            // Arrange

            // Act
            Element clickElement = WebBrowser.Current.Element(id);

            // Assert
            Assert.AreEqual(element.ToLower(), clickElement.TagName.ToLower(), string.Format("Element with id \"{0}\" was expected to be of type \"{1}\", but instead was of type \"{2}\".", id, element.ToLower(), clickElement.TagName.ToLower()));

            // Click the element (e.g. 'a', 'button', or 'input[type="button"]')
            clickElement.Click();
        }
    }
}
