public void CheckVersionAgainstHardcoded()
        {
            var version = new UITestHelper(metlWindow);
            version.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_VERSION_LABEL));

            version.Find();
            Assert.AreEqual(version.AutomationElement.Current.Name, expectedVersionString, ErrorMessages.VERSION_MISMATCH);
        }
        public void CloseInstance()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();
            Assert.IsTrue(metlWindows.Count == 1, ErrorMessages.EXPECTED_ONE_INSTANCE);

            var metlWindow = new UITestHelper(UITestHelper.RootElement, metlWindows[0]);
            metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
            metlWindow.Find();

            new ApplicationPopup(metlWindow.AutomationElement).Quit();

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
        public void CloseAllInstances()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();

            foreach (AutomationElement window in metlWindows)
            {
                var metlWindow = new UITestHelper(UITestHelper.RootElement, window);
                metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
                metlWindow.Find();

                new ApplicationPopup(metlWindow.AutomationElement).Quit();

                UITestHelper.Wait(TimeSpan.FromSeconds(2));
            }

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
        public void SwitchToSearchCurrentConversation(UITestHelper window)
        {
            var manualEvent = new ManualResetEvent(false);
            var completedSearch = false;

            var searchBox = new UITestHelper(window.AutomationElement);
            searchBox.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_BOX));
            searchBox.Find();

            Automation.AddAutomationEventHandler(AutomationElement.AsyncContentLoadedEvent, searchBox.AutomationElement, TreeScope.Element, (sender, args) => { completedSearch = true; manualEvent.Set(); });

            new ApplicationPopup(window.AutomationElement).SearchMyConversation();

            UITestHelper.Wait(TimeSpan.FromSeconds(5));
            
            manualEvent.WaitOne(5000, false);
            Assert.IsTrue(completedSearch);

            var currentConversation = new UITestHelper(window);
            currentConversation.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_SEARCH_CURRENT_CONVERSATION_BUTTON));

            currentConversation.Find();

            currentConversation.AutomationElement.Select();

            UITestHelper.Wait(TimeSpan.FromSeconds(5));

            /*var resultsText = new UITestHelper(metlWindow, metlWindow.AutomationElement.Descendant(Constants.ID_METL_SEARCH_RESULTS_TEXT));
            resultsText.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_SEARCH_RESULTS_TEXT));

            var correct = resultsText.WaitForControlCondition((uiControl) =>
            {
                if (uiControl.Current.Name == "Found 1 result.")
                {
                    return false;
                }

                return true;
            });

            Assert.IsTrue(correct);
             */
        }
        public void LogoutAndCloseInstance()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();
            Assert.IsTrue(metlWindows.Count == 1, ErrorMessages.EXPECTED_ONE_INSTANCE);

            var metlWindow = new UITestHelper(UITestHelper.RootElement, metlWindows[0]);
            metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
            metlWindow.Find();

            var logoutAndExit = new UITestHelper(metlWindow);
            logoutAndExit.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_LOGOUT_AND_EXIT_BACKNAV_BUTTON));

            logoutAndExit.WaitForControlExist();
            logoutAndExit.AutomationElement.Invoke(); 

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }