public void ShouldNotContainDuplicateConfigEntriesOnSubsequentRequests()
            {
                var create = new NewRepositoryWebHook("web", new Dictionary <string, string>(), "http://test.com/example");

                var request         = create.ToRequest();
                var requestRepeated = create.ToRequest();

                Assert.Equal(4, request.Config.Count);
                Assert.Equal(4, requestRepeated.Config.Count);
            }
            public void EnsureCanCallToRequestMultipleTimes()
            {
                var create = new NewRepositoryWebHook("web", new Dictionary <string, string>(), "http://test.com/example")
                {
                    Events = new List <string> {
                        "*"
                    }
                };

                var request         = create.ToRequest();
                var requestRepeated = create.ToRequest();

                Assert.Contains("*", request.Events);
                Assert.Contains("*", requestRepeated.Events);
            }
示例#3
0
            public void ShouldThrowRepositoryWebHookConfigExceptionWhenDuplicateKeysExists()
            {
                var config = new Dictionary <string, string>
                {
                    { "url", "http://example.com/test" },
                    { "hostname", "http://hostname.url" },
                    { "username", "username" },
                    { "password", "password" }
                };

                var create = new NewRepositoryWebHook("windowsazure", config, "http://test.com/example")
                {
                    ContentType = WebHookContentType.Json,
                    Secret      = string.Empty,
                    InsecureSsl = true
                };

                Assert.Equal(create.Url, "http://test.com/example");
                Assert.Equal(create.ContentType, WebHookContentType.Json);
                Assert.Empty(create.Secret);
                Assert.True(create.InsecureSsl);

                var ex = Assert.Throws <RepositoryWebHookConfigException>(() => create.ToRequest());

                Assert.Equal(ExpectedRepositoryWebHookConfigExceptionMessage, ex.Message);
            }
            public void PropertiesShouldTakePrecedenceOverConfigPassedIn()
            {
                var config = new Dictionary <string, string>
                {
                    { "url", "http://originalurl.com/test" },
                };

                var create = new NewRepositoryWebHook("web", config, "http://test.com/example");

                var request = create.ToRequest();

                Assert.Equal("http://test.com/example", request.Config["url"]);

                var subsequentRequest = create.ToRequest();

                Assert.Equal("http://test.com/example", subsequentRequest.Config["url"]);
            }
            public void ShouldNotContainDuplicateConfigEntriesOnSubsequentRequestsWithCustomisedConfig()
            {
                var config = new Dictionary <string, string>
                {
                    { "url", "http://example.com/test" },
                    { "hostname", "http://hostname.url" },
                    { "username", "username" },
                    { "password", "password" }
                };

                var create = new NewRepositoryWebHook("web", config, "http://test.com/example");

                var request         = create.ToRequest();
                var requestRepeated = create.ToRequest();

                //This is not 8, because `url` used in config, is already part of the base config
                Assert.Equal(7, request.Config.Count);
                Assert.Equal(7, requestRepeated.Config.Count);
            }
            public void CanSetHookEvents()
            {
                var create = new NewRepositoryWebHook("web", new Dictionary <string, string>(), "http://test.com/example")
                {
                    Events = new List <string> {
                        "*"
                    }
                };

                var request = create.ToRequest();

                Assert.Contains("*", request.Events);
            }
            public void CanSetHookAsActive()
            {
                var config = new Dictionary <string, string>
                {
                    { "hostname", "http://hostname.url" },
                    { "username", "username" },
                    { "password", "password" }
                };

                var create = new NewRepositoryWebHook("web", config, "http://test.com/example")
                {
                    Active = true
                };

                var request = create.ToRequest();

                Assert.True(request.Active);
            }
示例#8
0
            public void CombinesUserSpecifiedContentTypeWithConfig()
            {
                var config = new Dictionary <string, string>
                {
                    { "hostname", "http://hostname.url" },
                    { "username", "username" },
                    { "password", "password" }
                };

                var create = new NewRepositoryWebHook("windowsazure", config, "http://test.com/example")
                {
                    ContentType = WebHookContentType.Json,
                    Secret      = string.Empty,
                    InsecureSsl = true
                };

                Assert.Equal(create.Url, "http://test.com/example");
                Assert.Equal(create.ContentType, WebHookContentType.Json);
                Assert.Empty(create.Secret);
                Assert.True(create.InsecureSsl);

                var request = create.ToRequest();

                Assert.Equal(request.Config.Count, 7);

                Assert.True(request.Config.ContainsKey("url"));
                Assert.True(request.Config.ContainsKey("content_type"));
                Assert.True(request.Config.ContainsKey("secret"));
                Assert.True(request.Config.ContainsKey("insecure_ssl"));

                Assert.Equal(request.Config["url"], "http://test.com/example");
                Assert.Equal(request.Config["content_type"], WebHookContentType.Json.ToParameter());
                Assert.Equal(request.Config["secret"], "");
                Assert.Equal(request.Config["insecure_ssl"], true.ToString());

                Assert.True(request.Config.ContainsKey("hostname"));
                Assert.Equal(request.Config["hostname"], config["hostname"]);
                Assert.True(request.Config.ContainsKey("username"));
                Assert.Equal(request.Config["username"], config["username"]);
                Assert.True(request.Config.ContainsKey("password"));
                Assert.Equal(request.Config["password"], config["password"]);
            }
示例#9
0
            public async Task CreateAWebHookForTestRepositoryWithRepositoryId()
            {
                var github = Helper.GetAuthenticatedClient();

                var repoName   = Helper.MakeNameWithTimestamp("create-hooks-test");
                var repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true });

                var url         = "http://test.com/example";
                var contentType = WebHookContentType.Json;
                var secret      = "53cr37";

                var config = new Dictionary <string, string>
                {
                    { "hostname", "http://hostname.url" },
                    { "username", "username" },
                    { "password", "password" }
                };

                var parameters = new NewRepositoryWebHook("windowsazure", config, url)
                {
                    Events      = new[] { "push" },
                    Active      = false,
                    ContentType = contentType,
                    Secret      = secret
                };

                var hook = await github.Repository.Hooks.Create(repository.Id, parameters.ToRequest());

                var baseHookUrl   = CreateExpectedBaseHookUrl(repository.Url, hook.Id);
                var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType, secret);

                Assert.Equal("windowsazure", hook.Name);
                Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList());
                Assert.Equal(baseHookUrl, hook.Url);
                Assert.Equal(baseHookUrl + "/test", hook.TestUrl);
                Assert.Equal(baseHookUrl + "/pings", hook.PingUrl);
                Assert.NotNull(hook.CreatedAt);
                Assert.NotNull(hook.UpdatedAt);
                Assert.Equal(webHookConfig.Keys.OrderBy(x => x), hook.Config.Keys.OrderBy(x => x));
                Assert.Equal(webHookConfig.Values.OrderBy(x => x), hook.Config.Values.OrderBy(x => x));
                Assert.Equal(false, hook.Active);
            }
            public void CombinesUserSpecifiedContentTypeWithConfig()
            {
                var config = new Dictionary<string, string>
                {
                    {"hostname", "http://hostname.url"},
                    {"username", "username"},
                    {"password", "password"}
                };

                var create = new NewRepositoryWebHook("windowsazure", config, "http://test.com/example")
                {
                    ContentType = WebHookContentType.Json,
                    Secret = string.Empty,
                    InsecureSsl = true
                };

                Assert.Equal(create.Url, "http://test.com/example");
                Assert.Equal(create.ContentType, WebHookContentType.Json);
                Assert.Empty(create.Secret);
                Assert.True(create.InsecureSsl);

                var request = create.ToRequest();

                Assert.Equal(request.Config.Count, 7);

                Assert.True(request.Config.ContainsKey("url"));
                Assert.True(request.Config.ContainsKey("content_type"));
                Assert.True(request.Config.ContainsKey("secret"));
                Assert.True(request.Config.ContainsKey("insecure_ssl"));

                Assert.Equal(request.Config["url"], "http://test.com/example");
                Assert.Equal(request.Config["content_type"], WebHookContentType.Json.ToParameter());
                Assert.Equal(request.Config["secret"], "");
                Assert.Equal(request.Config["insecure_ssl"], true.ToString());

                Assert.True(request.Config.ContainsKey("hostname"));
                Assert.Equal(request.Config["hostname"], config["hostname"]);
                Assert.True(request.Config.ContainsKey("username"));
                Assert.Equal(request.Config["username"], config["username"]);
                Assert.True(request.Config.ContainsKey("password"));
                Assert.Equal(request.Config["password"], config["password"]);
            }
            public void UsesDefaultValuesForDefaultConfig()
            {
                var create = new NewRepositoryWebHook("windowsazure", new Dictionary<string, string>(), "http://test.com/example");
                Assert.Equal(create.Url, "http://test.com/example");
                Assert.Equal(create.ContentType, WebHookContentType.Form);
                Assert.Empty(create.Secret);
                Assert.False(create.InsecureSsl);

                var request = create.ToRequest();
                Assert.Equal(request.Config.Count, 4);

                Assert.True(request.Config.ContainsKey("url"));
                Assert.True(request.Config.ContainsKey("content_type"));
                Assert.True(request.Config.ContainsKey("secret"));
                Assert.True(request.Config.ContainsKey("insecure_ssl"));

                Assert.Equal(request.Config["url"], "http://test.com/example");
                Assert.Equal(request.Config["content_type"], WebHookContentType.Form.ToParameter());
                Assert.Equal(request.Config["secret"], "");
                Assert.Equal(request.Config["insecure_ssl"], "False");
            }
            public async Task CreateAWebHookForTestRepository()
            {
                var github = Helper.GetAuthenticatedClient();

                var repoName = Helper.MakeNameWithTimestamp("create-hooks-test");
                var repository = await github.Repository.Create(new NewRepository(repoName) { AutoInit = true });

                var url = "http://test.com/example";
                var contentType = WebHookContentType.Json;
                var secret = "53cr37";
                var config = new Dictionary<string, string>
                {
                    { "hostname", "http://hostname.url" },
                    { "username", "username" },
                    { "password", "password" }
                };
                var parameters = new NewRepositoryWebHook("windowsazure", config, url)
                {
                    Events = new[] { "push" },
                    Active = false,
                    ContentType = contentType,
                    Secret = secret
                };

                var hook = await github.Repository.Hooks.Create(Helper.UserName, repository.Name, parameters.ToRequest());

                var baseHookUrl = CreateExpectedBaseHookUrl(repository.Url, hook.Id);
                var webHookConfig = CreateExpectedConfigDictionary(config, url, contentType, secret);

                Assert.Equal("windowsazure", hook.Name);
                Assert.Equal(new[] { "push" }.ToList(), hook.Events.ToList());
                Assert.Equal(baseHookUrl, hook.Url);
                Assert.Equal(baseHookUrl + "/test", hook.TestUrl);
                Assert.Equal(baseHookUrl + "/pings", hook.PingUrl);
                Assert.NotNull(hook.CreatedAt);
                Assert.NotNull(hook.UpdatedAt);
                Assert.Equal(webHookConfig.Keys, hook.Config.Keys);
                Assert.Equal(webHookConfig.Values, hook.Config.Values);
                Assert.Equal(false, hook.Active);
            }
示例#13
0
            public void UsesDefaultValuesForDefaultConfig()
            {
                var create = new NewRepositoryWebHook("windowsazure", new Dictionary <string, string>(), "http://test.com/example");

                Assert.Equal(create.Url, "http://test.com/example");
                Assert.Equal(create.ContentType, WebHookContentType.Form);
                Assert.Empty(create.Secret);
                Assert.False(create.InsecureSsl);

                var request = create.ToRequest();

                Assert.Equal(request.Config.Count, 4);

                Assert.True(request.Config.ContainsKey("url"));
                Assert.True(request.Config.ContainsKey("content_type"));
                Assert.True(request.Config.ContainsKey("secret"));
                Assert.True(request.Config.ContainsKey("insecure_ssl"));

                Assert.Equal(request.Config["url"], "http://test.com/example");
                Assert.Equal(request.Config["content_type"], WebHookContentType.Form.ToParameter());
                Assert.Equal(request.Config["secret"], "");
                Assert.Equal(request.Config["insecure_ssl"], "False");
            }
            public void ShouldThrowRepositoryWebHookConfigExceptionWhenDuplicateKeysExists()
            {
                var config = new Dictionary<string, string>
                {
                    {"url", "http://example.com/test"},
                    {"hostname", "http://hostname.url"},
                    {"username", "username"},
                    {"password", "password"}
                };

                var create = new NewRepositoryWebHook("windowsazure", config, "http://test.com/example")
                {
                    ContentType = WebHookContentType.Json,
                    Secret = string.Empty,
                    InsecureSsl = true
                };

                Assert.Equal(create.Url, "http://test.com/example");
                Assert.Equal(create.ContentType, WebHookContentType.Json);
                Assert.Empty(create.Secret);
                Assert.True(create.InsecureSsl);

                var ex = Assert.Throws<RepositoryWebHookConfigException>(() => create.ToRequest());
                Assert.Equal(ExpectedRepositoryWebHookConfigExceptionMessage, ex.Message);
            }