<commit_before>﻿using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Drawing;


namespace ScenarioTest
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class VerifiyWebApp_RoleClaims
    {
        public VerifiyWebApp_RoleClaims()
        {
        }

        [TestMethod]
        public void CodedUITestMethod1()
        {
            RunEndToEnd("https://todolistservicewithcertificate.azurewebsites.net/",
                "<EMAIL>",
                "xam/vtIMPD+uFpEd5RMKu/KJLwpi0c+tr6WoA9KfHcg=", "Approver");
        }

        private void RunEndToEnd(string url, string userLogin, string userPassword, string role)
        {
            // Launch a brower
            BrowserWindow browser = BrowserWindow.Launch(new Uri(url));
            HtmlDocument page = new HtmlDocument(browser);
            page.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = url;

            // Sign in
            page = ClickSignInHyperLink(browser, page);
            page = EnterCredentialsAndSignIn(browser, page, userLogin, userPassword);

            // Accept consent (if necessary)
            page = AcceptConsent(browser, page);

#if VerifyRole
            // Navigate to the About page and verify that the user has the right role
            page = NavigateToAboutPage(browser, page);
            VerifyThatTheUserIsInRole(page, role);
#endif

            // Sign out
            SignOut(page);
        }

        private static void SignOut(HtmlDocument page)
        {
            // Click the "Sign-out" Hyperlink
            HtmlHyperlink signOutHyperLink = new HtmlHyperlink(page);
            signOutHyperLink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "logoutLink";
            signOutHyperLink.EnsureClickable();
            Mouse.Click(signOutHyperLink);
        }

        private static void VerifyThatTheUserIsInRole(HtmlDocument page, string roleName)
        {
            // Verify that the  users has a role of Approver
            HtmlCustom ul = new HtmlCustom(page);
            ul.SearchProperties["TagName"] = "UL";
            HtmlCustom li = new HtmlCustom(ul);
            li.SearchProperties["TagName"] = "LI";
            Assert.IsTrue(li.InnerText.Contains(roleName),
                          string.Format("the About box should show that the user has the '{0}' role", roleName));
        }

        private static HtmlDocument NavigateToAboutPage(BrowserWindow browser, HtmlDocument page)
        {
            // Click the "About" Hyperlink
            HtmlHyperlink aboutHyperlink = new HtmlHyperlink(page);
            aboutHyperlink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "about";
            aboutHyperlink.SearchProperties[HtmlHyperlink.PropertyNames.AbsolutePath] = "/Home/About";
            Mouse.Click(aboutHyperlink);
            page = new HtmlDocument(browser);
            return page;
        }

        private static HtmlDocument AcceptConsent(BrowserWindow browser, HtmlDocument page)
        {
            HtmlControl acceptConsentButton = new HtmlControl(page);<commit_msg>Fixing the accept consent<commit_after>﻿using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Drawing;


namespace ScenarioTest
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class VerifiyWebApp_RoleClaims
    {
        public VerifiyWebApp_RoleClaims()
        {
        }

        [TestMethod]
        public void CodedUITestMethod1()
        {
            RunEndToEnd("https://todolistservicewithcertificate.azurewebsites.net/",
                "<EMAIL>",
                "xam/vtIMPD+uFpEd5RMKu/KJLwpi0c+tr6WoA9KfHcg=", "Approver");
        }

        private void RunEndToEnd(string url, string userLogin, string userPassword, string role)
        {
            // Launch a brower
            BrowserWindow browser = BrowserWindow.Launch(new Uri(url));
            HtmlDocument page = new HtmlDocument(browser);
            page.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = url;


            // Sign in
            page = ClickSignInHyperLink(browser, page);
            browser.WaitForControlReady();
            page = AcceptConsent(browser, page);
            page = EnterCredentialsAndSignIn(browser, page, userLogin, userPassword);

#if VerifyRole
            // Navigate to the About page and verify that the user has the right role
            page = NavigateToAboutPage(browser, page);
            VerifyThatTheUserIsInRole(page, role);
#endif

            // Sign out
            SignOut(page);
        }

        private static void SignOut(HtmlDocument page)
        {
            // Click the "Sign-out" Hyperlink
            HtmlHyperlink signOutHyperLink = new HtmlHyperlink(page);
            signOutHyperLink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "logoutLink";
            if (signOutHyperLink.Exists)
            {
                signOutHyperLink.EnsureClickable();
                Mouse.Click(signOutHyperLink);
            }
        }

        private static void VerifyThatTheUserIsInRole(HtmlDocument page, string roleName)
        {
            // Verify that the  users has a role of Approver
            HtmlCustom ul = new HtmlCustom(page);
            ul.SearchProperties["TagName"] = "UL";
            HtmlCustom li = new HtmlCustom(ul);
            li.SearchProperties["TagName"] = "LI";
            Assert.IsTrue(li.InnerText.Contains(roleName),
                          string.Format("the About box should show that the user has the '{0}' role", roleName));
        }

        private static HtmlDocument NavigateToAboutPage(BrowserWindow browser, HtmlDocument page)
        {
            // Click the "About" Hyperlink
            HtmlHyperlink aboutHyperlink = new HtmlHyperlink(page);
            aboutHyperlink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "about";
            aboutHyperlink.SearchProperties[HtmlHyperlink.PropertyNames.AbsolutePath] = "/Home/About";
            Mouse.Click(aboutHyperlink);
            page = new HtmlDocument(browser);
            return page;
        }

        private static HtmlDocument AcceptConsent(BrowserWindow browser, HtmlDocument page)
        {
            HtmlControl acceptConsentButton = new HtmlControl(page);
{'fraction_non_alphanumeric': 0.08430806623120159, 'fraction_numerical': 0.002126689958985265, 'mean_word_length': 2.295295295295295, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6331560', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1719, 'n_words': 385}