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

            GithubRepositoryHook createdHook = null;
            bool tested = false;

            channel.GetRepositoryHooksThunk   = ar => new List <GithubRepositoryHook>();
            channel.CreateRepositoryHookThunk = 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 = "$username"
                        },
                        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.IsNotNull(createdHook);
            Assert.IsTrue(tested);
        }
        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.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Link already established", e.Message);
            }
        }
        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);
        }