Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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.AreEqual(3, repositories.Count);
            Assert.IsNotNull(repositories.FirstOrDefault(r => r.Name.Equals("userrepo1")));
            Assert.IsNotNull(repositories.FirstOrDefault(r => r.Name.Equals("org1repo1")));
            Assert.IsNotNull(repositories.FirstOrDefault(r => r.Name.Equals("org2repo1")));
        }
Ejemplo n.º 3
0
        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.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual("Link already established", e.Message);
            }
        }
        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 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.AreEqual(3, repositories.Count);
            Assert.IsNotNull(repositories.FirstOrDefault(r => r.Name.Equals("userrepo1")));
            Assert.IsNotNull(repositories.FirstOrDefault(r => r.Name.Equals("org1repo1")));
            Assert.IsNotNull(repositories.FirstOrDefault(r => r.Name.Equals("org2repo1")));
        }