public void TestGetRepositories()
        {
            // Setup
            SimpleGithubManagement channel = new SimpleGithubManagement();

            channel.GetRepositoriesThunk = ar => new List<GithubRepository> { new GithubRepository { Name = "userrepo1" } };
            channel.GetOrganizationsThunk = ar => new List<GithubOrganization> { new GithubOrganization { Login = "******" }, new GithubOrganization { Login = "******" } };
            channel.GetRepositoriesFromOrgThunk = ar => 
            {
                if (ar.Values["organization"].Equals("org1"))
                {
                    return new List<GithubRepository> { new GithubRepository { Name = "org1repo1" } };
                }
                
                if (ar.Values["organization"].Equals("org2"))
                {
                    return new List<GithubRepository> { new GithubRepository { Name = "org2repo1" } };
                }

                return new List<GithubRepository> { new GithubRepository { Name = "other" } };
            };


            // Test
            CmdletAccessor cmdletAccessor = new CmdletAccessor();
            cmdletAccessor.GithubChannel = channel;
            
            GithubClientAccessor githubClientAccessor = new GithubClientAccessor(cmdletAccessor, null, null);
            var repositories = githubClientAccessor.GetRepositoriesAccessor();

            Assert.Equal(3, repositories.Count);
            Assert.NotNull(repositories.FirstOrDefault(r => r.Name.Equals("userrepo1")));
            Assert.NotNull(repositories.FirstOrDefault(r => r.Name.Equals("org1repo1")));
            Assert.NotNull(repositories.FirstOrDefault(r => r.Name.Equals("org2repo1")));
        }
        public void TestCreateOrUpdateHookAlreadyExists()
        {
            // Setup
            SimpleGithubManagement channel = new SimpleGithubManagement();

            channel.GetRepositoryHooksThunk = ar => new List<GithubRepositoryHook> { new GithubRepositoryHook { Name = "web", Config = new GithubRepositoryHookConfig { Url = "https://$username:[email protected]:443/deploy" } } };

            Site website = new Site
            {
                SiteProperties = new SiteProperties
                {
                    Properties = new List<NameValuePair>
                    {
                        new NameValuePair 
                        {
                            Name = "RepositoryUri",
                            Value = "https://mynewsite999.scm.azurewebsites.net:443"
                        },
                        new NameValuePair 
                        {
                            Name = "PublishingUsername",
                            Value = "$username"
                        },
                        new NameValuePair 
                        {
                            Name = "PublishingPassword",
                            Value = "password"
                        }
                    }
                }
            };

            // Test
            CmdletAccessor cmdletAccessor = new CmdletAccessor();
            cmdletAccessor.GithubChannel = channel;

            GithubClientAccessor githubClientAccessor = new GithubClientAccessor(cmdletAccessor, null, null);
            
            try
            {
                githubClientAccessor.CreateOrUpdateHookAccessor("owner", "repository", website);
                Assert.True(false, "Fail");
            }
            catch (Exception e)
            {
                Assert.Equal("Link already established", e.Message);
            }
        }
        public void TestCreateOrUpdateHookUpdate()
        {
            // Setup
            SimpleGithubManagement channel = new SimpleGithubManagement();

            GithubRepositoryHook createdHook = null;
            bool tested = false;

            channel.GetRepositoryHooksThunk = ar => new List<GithubRepositoryHook> { new GithubRepositoryHook { Name = "web", Config = new GithubRepositoryHookConfig { Url = "https://$username:[email protected]:443/deploy" } } };
            channel.UpdateRepositoryHookThunk = ar =>
            {
                createdHook = ar.Values["hook"] as GithubRepositoryHook;
                createdHook.Id = "id";
                return createdHook;
            };

            channel.TestRepositoryHookThunk = ar =>
            {
                if (ar.Values["id"].Equals("id"))
                {
                    tested = true;
                }
            };

            Site website = new Site
            {
                SiteProperties = new SiteProperties
                {
                    Properties = new List<NameValuePair>
                    {
                        new NameValuePair 
                        {
                            Name = "RepositoryUri",
                            Value = "https://mynewsite999.scm.azurewebsites.net:443"
                        },
                        new NameValuePair 
                        {
                            Name = "PublishingUsername",
                            Value = "$usernamenew"
                        },
                        new NameValuePair 
                        {
                            Name = "PublishingPassword",
                            Value = "password"
                        }
                    }
                }
            };

            // Test
            CmdletAccessor cmdletAccessor = new CmdletAccessor();
            cmdletAccessor.GithubChannel = channel;

            GithubClientAccessor githubClientAccessor = new GithubClientAccessor(cmdletAccessor, null, null);
            githubClientAccessor.CreateOrUpdateHookAccessor("owner", "repository", website);
            Assert.NotNull(createdHook);
            Assert.True(tested);
        }