public void Comps_Graph_S05_TC03_CanSwitchAPIVersion()
        {
            GraphPages.Navigation.Select("Graph explorer");
            string userName = GraphUtility.GetConfigurationValue("GraphExplorerUserName");

            if (!GraphUtility.IsLoggedIn())
            {
                GraphUtility.ClickLogin();

                GraphUtility.Login(
                    userName,
                    GraphUtility.GetConfigurationValue("GraphExplorerPassword"));
            }
            //v1.0
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/me" + "\n");
            GraphBrowser.Wait(TimeSpan.FromSeconds(10));
            string v10Response  = GraphUtility.GetExplorerResponse();
            string oDataContext = GraphUtility.GetProperty(v10Response, "@odata.context");

            Assert.IsTrue(oDataContext.Contains("https://graph.microsoft.com/v1.0"),
                          "Setting a v1.0 query string should get a v1.0 response.");

            //vBeta
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/beta/me" + "\n");
            GraphBrowser.Wait(TimeSpan.FromSeconds(10));
            string betaResponse = GraphUtility.GetExplorerResponse();

            oDataContext = GraphUtility.GetProperty(betaResponse, "@odata.context");
            Assert.IsTrue(oDataContext.Contains("https://graph.microsoft.com/beta"),
                          "Setting a vBeta query string should get a vBeta response.");
        }
        public void Comps_Graph_S05_TC02_CanGetMe()
        {
            GraphPages.Navigation.Select("Graph explorer");
            string userName = GraphUtility.GetConfigurationValue("GraphExplorerUserName");

            if (!GraphUtility.IsLoggedIn(userName))
            {
                if (GraphUtility.IsLoggedIn())
                {
                    GraphUtility.ClickLogout();
                }
                GraphUtility.ClickLogin();

                GraphUtility.Login(
                    userName,
                    GraphUtility.GetConfigurationValue("GraphExplorerPassword"));
            }

            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/me" + "\n");
            GraphBrowser.Wait(TimeSpan.FromSeconds(10));
            string response = GraphUtility.GetExplorerResponse();
            string mail     = GraphUtility.GetProperty(response, "mail");

            Assert.AreEqual(
                userName,
                mail,
                @"GET ""me"" can obtain the correct response");
        }
        public void DownloadCode()
        {
            var downloadBtn = GraphBrowser.Driver.FindElement(By.Id("downloadCodeSampleButtonRest"));

            GraphBrowser.Click(downloadBtn);

            // Give 3 seconds for download to finish before checking for postdownload instructions
            GraphBrowser.Wait(TimeSpan.FromSeconds(int.Parse(GraphUtility.GetConfigurationValue("WaitTime"))));
        }
 public void BVT_Graph_S01_TC04_CanGoToGraphExplorerPage()
 {
     string title = TestHelper.VerifyAndSelectExplorerOnNavBar();
     if (GraphUtility.BrowserType == "IE32")
     {
         GraphBrowser.Wait(TimeSpan.FromSeconds(3));
     }
     Assert.IsTrue(
         GraphPages.Navigation.IsAtGraphPage(title),
         @"The opened page should be ""Graph explorer""");
 }
 public void BVT_Graph_S01_TC07_CanGoToExamplesPage()
 {
     string title = GraphPages.Navigation.Select("Examples");
     if (GraphUtility.BrowserType == "IE32")
     {
         GraphBrowser.Wait(TimeSpan.FromSeconds(3));
     }
     Assert.IsTrue(
         GraphPages.Navigation.IsAtGraphPage(title),
         @"The opened page should be ""Examples""");
 }
 public void BVT_Graph_S01_TC03_CanGoToDocumentationPage()
 {
     string title = GraphPages.Navigation.Select("Documentation");
     if(GraphUtility.BrowserType == "IE32")
     {
         GraphBrowser.Wait(TimeSpan.FromSeconds(3));
     }
     Assert.IsTrue(
         GraphPages.Navigation.IsAtGraphPage(title),
         @"The opened page should be {0}",
         title);
 }
        public void ChoosePlatform(Platform platformName)
        {
            if (!GraphBrowser.Url.Contains("/quick-start"))
            {
                GraphBrowser.Goto(GraphUtility.RemoveRedundantPartsfromExtractBaseAddress() + "/quick-start#setup");
            }

            //To account for iOS_Swift and iOS_Objective_C enums, since enum cannot contain - character but the div IDs contain -
            var platform = GraphBrowser.Driver.FindElement(By.Id("option-" + platformName.ToString().ToLower().Replace("_", "-")));

            GraphBrowser.Click(platform);

            // Need refactor: Sometimes case failed for the platform setup text is not changed in time
            GraphBrowser.Wait(TimeSpan.FromSeconds(2));
        }
        public void Comps_Graph_S05_TC04_CanPatchMe()
        {
            GraphPages.Navigation.Select("Graph explorer");
            string userName = GraphUtility.GetConfigurationValue("GraphExplorerUserName");

            if (!GraphUtility.IsLoggedIn())
            {
                GraphUtility.ClickLogin();

                GraphUtility.Login(
                    userName,
                    GraphUtility.GetConfigurationValue("GraphExplorerPassword"));
            }
            //Change the operation from GET to PATCH
            GraphUtility.ClickButton("GET");
            GraphUtility.Click("PATCH");
            string jobTitle = "JobTitle_" + DateTime.Now.ToString("M/d/yyyy/hh/mm/ss");
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("jobTitle", jobTitle);
            GraphUtility.InputExplorerJSONBody(dic);
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/me" + "\n");
            GraphBrowser.WaitForExploreResponse();
            string patchResponse = GraphUtility.GetExplorerResponse();

            //Change the operation from PATCH to GET
            GraphUtility.ClickButton("PATCH");
            GraphUtility.Click("GET");
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/me" + "\n");
            string getResponse = GraphUtility.GetExplorerResponse();
            //The response doesn't change means no GET response is returned.So wait and re-obtain it
            int waitTime   = Int32.Parse(GraphUtility.GetConfigurationValue("WaitTime"));
            int retryCount = Int32.Parse(GraphUtility.GetConfigurationValue("RetryCount"));
            int i          = 0;

            while (i < retryCount && getResponse == patchResponse)
            {
                GraphBrowser.Wait(TimeSpan.FromSeconds(waitTime));
                getResponse = GraphUtility.GetExplorerResponse();
                i++;
            }
            string newjobTitle = GraphUtility.GetProperty(getResponse, "jobTitle");

            Assert.AreEqual(jobTitle, newjobTitle, "The patched property should be updated accordingly");
        }
        public void Comps_Graph_S07_TC01_CheckInThisArticle()
        {
            GraphPages.Navigation.Select("Documentation");
            GraphBrowser.ZoomToPercent(50);
            GraphBrowser.Wait(TimeSpan.FromSeconds(3)); //In this article renders after the doc renders, so must wait
            Assert.IsTrue(GraphUtility.IsInThisArticleDisplayed(),
                          "On a large screen, in this article should be displayed");
            GraphBrowser.ZoomToPercent(100);

            Size windowSize;
            //Set as the screen size of IPad2
            double deviceScreenSize = double.Parse(GraphUtility.GetConfigurationValue("IPad2Size"));

            GraphBrowser.TransferPhysicalSizeToPixelSize(
                deviceScreenSize,
                new Size
            {
                Width  = int.Parse(GraphUtility.GetConfigurationValue("IPad2ScreenResolutionWidth")),
                Height = int.Parse(GraphUtility.GetConfigurationValue("IPad2ScreenResolutionHeight"))
            },
                out windowSize);
            GraphBrowser.SetWindowSize(windowSize.Width, windowSize.Height);

            Assert.IsFalse(GraphUtility.IsInThisArticleDisplayed(),
                           "On an iPad, in this article should not be displayed");

            //Set as the screen size of IPhone6 plus
            deviceScreenSize = double.Parse(GraphUtility.GetConfigurationValue("IPhone6PlusSize"));
            //Since mobile phone width<Height, invert the output values
            GraphBrowser.TransferPhysicalSizeToPixelSize(
                deviceScreenSize,
                new Size
            {
                Width  = int.Parse(GraphUtility.GetConfigurationValue("IPhone6PlusScreenResolutionWidth")),
                Height = int.Parse(GraphUtility.GetConfigurationValue("IPhone6PlusScreenResolutionHeight"))
            },
                out windowSize);
            //Since mobile phone widh<height, invert height and width
            GraphBrowser.SetWindowSize(windowSize.Height, windowSize.Width);

            Assert.IsFalse(GraphUtility.IsInThisArticleDisplayed(),
                           "On an iPhone, in this article should not be displayed");
        }
        public void BVT_Graph_S01_TC08_CanLoadGraphPageImages()
        {
            //Currently ignore Graph explorer and Documentation, since these pages don't have banner image
            //Graph branding image
            string[] navOptions = new string[] {
                "Home",
                "Get started", 
                "Documentation", 
                //"Graph explorer", 
                //"App registration",
                "Samples & SDKs"};

            foreach (string navPage in navOptions)
            {
                GraphPages.Navigation.Select(navPage);
                if (GraphUtility.BrowserType == "IE32")
                {
                    GraphBrowser.Wait(TimeSpan.FromSeconds(3));
                }
                if (navPage == "Home")
                {
                    foreach (GraphPageImages item in Enum.GetValues(typeof(GraphPageImages)))
                    {
                        Assert.IsTrue(GraphPages.HomePage.CanLoadImages(item));
                    }
                }
                else
                {
                    var graphPage = new GraphPage();
                    foreach (GraphPageImages item in Enum.GetValues(typeof(GraphPageImages)))
                    {
                        //No pages except Home have a banner image anymore
                        if (!item.ToString().Equals("MainBanner"))
                        {
                            Assert.IsTrue(graphPage.CanLoadImages(item));
                        }
                    }
                }
            }
        }
        public void Acceptance_Graph_S04_TC02_CanToggleArrowHideInLargeDocumentaionPage()
        {
            GraphPages.Navigation.Select("Documentation");
            int currentWidth  = 0;
            int currentHeight = 0;

            GraphBrowser.GetWindowSize(out currentWidth, out currentHeight);

            GraphBrowser.ZoomToPercent(50);
            if (GraphUtility.BrowserType == "IE32")
            {
                GraphBrowser.Wait(TimeSpan.FromSeconds(3));
            }

            Assert.IsFalse(
                GraphUtility.IsToggleArrowDisplayed(),
                "An large window size ({0} x {1}) can make table of content arrow hide.",
                currentWidth, currentHeight);

            //Change the zoom level back
            GraphBrowser.ZoomToPercent(100);
        }
        public void Comps_Graph_S05_TC05_CanPostDeleteGroup()
        {
            GraphPages.Navigation.Select("Graph explorer");
            int waitTime   = Int32.Parse(GraphUtility.GetConfigurationValue("WaitTime"));
            int retryCount = Int32.Parse(GraphUtility.GetConfigurationValue("RetryCount"));

            string userName = GraphUtility.GetConfigurationValue("GraphExplorerUserName");

            if (!GraphUtility.IsLoggedIn())
            {
                GraphUtility.ClickLogin();

                GraphUtility.Login(
                    userName,
                    GraphUtility.GetConfigurationValue("GraphExplorerPassword"));
            }

            //Change the operation from GET to POST
            GraphUtility.ClickButton("GET");
            GraphUtility.Click("POST");

            Dictionary <string, string> postProperties = new Dictionary <string, string>();

            postProperties.Add("description", "A group for test");
            string groupDisplayName = "TestGroup_" + DateTime.Now.ToString("M/d/yyyy/hh/mm/ss");

            postProperties.Add("displayName", groupDisplayName);
            postProperties.Add("mailEnabled", "false");
            postProperties.Add("securityEnabled", "true");
            postProperties.Add("mailNickname", "TestGroupMail");
            GraphUtility.InputExplorerJSONBody(postProperties);
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/groups" + "\n");
            GraphBrowser.WaitForExploreResponse();
            string postResponse    = GraphUtility.GetExplorerResponse();
            string postID          = GraphUtility.GetProperty(postResponse, "id");
            string postDisplayName = GraphUtility.GetProperty(postResponse, "displayName");

            // Reload the page to empty the response
            GraphBrowser.Refresh();
            //Check whether the created group can be gotten
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/groups/" + postID + "\n");
            GraphBrowser.WaitForExploreResponse();
            string getResponse    = GraphUtility.GetExplorerResponse();
            string getDisplayName = GraphUtility.GetProperty(getResponse, "displayName");

            Assert.AreEqual(
                postDisplayName,
                getDisplayName,
                "The posted group should be able to GET");

            // Reload the page to empty the response
            GraphBrowser.Refresh();
            GraphUtility.ClickButton("GET");
            GraphUtility.Click("DELETE");
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/groups/" + postID + "\n");
            GraphBrowser.WaitForExploreResponse();
            string deleteResponse = GraphUtility.GetExplorerResponse();

            GraphUtility.Click("DELETE");
            GraphUtility.ClickButton("GET");
            GraphUtility.InputExplorerQueryString("https://graph.microsoft.com/v1.0/groups/" + postID + "\n");
            int i = 0;

            do
            {
                GraphBrowser.Wait(TimeSpan.FromSeconds(waitTime));
                getResponse = GraphUtility.GetExplorerResponse();
                i++;
            } while (i < retryCount && getResponse.Equals(deleteResponse));

            Assert.IsTrue(
                getResponse.Contains("Request_ResourceNotFound"),
                "The group should be deleted successfully");
        }