From 0051b18552dcd2f07f562ea65d08ee75865590f8 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 10 Jun 2016 17:31:27 +0700 Subject: [PATCH] added new intergration tests --- .../Clients/RepositoryHooksClientTests.cs | 197 +++++++++++++++++- .../fixtures/RepositoriesHooksFixture.cs | 2 + 2 files changed, 196 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs index 767ef1d1..6b0937ca 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs @@ -31,6 +31,19 @@ namespace Octokit.Tests.Integration.Clients AssertHook(_fixture.ExpectedHook, actualHook); } + [IntegrationTest] + public async Task ReturnsAllHooksFromRepositoryWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryId); + + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + + var actualHook = hooks[0]; + AssertHook(_fixture.ExpectedHook, actualHook); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfHooksWithoutStart() { @@ -47,6 +60,22 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithoutStartWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryId, options); + + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfHooksWithStart() { @@ -64,6 +93,23 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, hooks.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithStartWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 3 + }; + + var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryId, options); + + Assert.Equal(1, hooks.Count); + } + [IntegrationTest] public async Task ReturnsDistinctResultsBasedOnStartPage() { @@ -89,6 +135,32 @@ namespace Octokit.Tests.Integration.Clients Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var startOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var firstPage = await github.Repository.Hooks.GetAll(_fixture.RepositoryId, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await github.Repository.Hooks.GetAll(_fixture.RepositoryId, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + } } [Collection(RepositoriesHooksCollection.Name)] @@ -110,6 +182,16 @@ namespace Octokit.Tests.Integration.Clients AssertHook(_fixture.ExpectedHook, actualHook); } + + [IntegrationTest] + public async Task GetHookByCreatedIdWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var actualHook = await github.Repository.Hooks.Get(_fixture.RepositoryId, _fixture.ExpectedHook.Id); + + AssertHook(_fixture.ExpectedHook, actualHook); + } } public class TheCreateMethod @@ -125,12 +207,14 @@ namespace Octokit.Tests.Integration.Clients var url = "http://test.com/example"; var contentType = WebHookContentType.Json; var secret = "53cr37"; + var config = new Dictionary { { "hostname", "http://hostname.url" }, { "username", "username" }, { "password", "password" } }; + var parameters = new NewRepositoryWebHook("windowsazure", config, url) { Events = new[] { "push" }, @@ -156,6 +240,50 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(false, hook.Active); } + [IntegrationTest] + 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 + { + { "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, hook.Config.Keys); + Assert.Equal(webHookConfig.Values, hook.Config.Values); + Assert.Equal(false, hook.Active); + } + Dictionary CreateExpectedConfigDictionary(Dictionary config, string url, WebHookContentType contentType, string secret) { return new Dictionary @@ -193,7 +321,25 @@ namespace Octokit.Tests.Integration.Clients AddEvents = new[] { "pull_request" } }; - var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id, editRepositoryHook); + var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHooks[0].Id, editRepositoryHook); + + var expectedConfig = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; + Assert.Equal(new[] { "deployment", "pull_request" }.ToList(), actualHook.Events.ToList()); + Assert.Equal(expectedConfig.Keys, actualHook.Config.Keys); + Assert.Equal(expectedConfig.Values, actualHook.Config.Values); + } + + [IntegrationTest] + public async Task EditHookWithNoNewConfigRetainsTheOldConfigWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var editRepositoryHook = new EditRepositoryHook + { + AddEvents = new[] { "pull_request" } + }; + + var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryId, _fixture.ExpectedHooks[1].Id, editRepositoryHook); var expectedConfig = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; Assert.Equal(new[] { "deployment", "pull_request" }.ToList(), actualHook.Events.ToList()); @@ -211,7 +357,25 @@ namespace Octokit.Tests.Integration.Clients AddEvents = new[] { "pull_request" } }; - var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id, editRepositoryHook); + var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHooks[2].Id, editRepositoryHook); + + var expectedConfig = new Dictionary { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } }; + Assert.Equal(new[] { "push", "pull_request" }.ToList(), actualHook.Events.ToList()); + Assert.Equal(expectedConfig.Keys, actualHook.Config.Keys); + Assert.Equal(expectedConfig.Values, actualHook.Config.Values); + } + + [IntegrationTest] + public async Task EditHookWithNewInformationWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var editRepositoryHook = new EditRepositoryHook(new Dictionary { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } }) + { + AddEvents = new[] { "pull_request" } + }; + + var actualHook = await github.Repository.Hooks.Edit(_fixture.RepositoryId, _fixture.ExpectedHooks[3].Id, editRepositoryHook); var expectedConfig = new Dictionary { { "project", "GEZDGORQFY2TCNZRGY2TSMBVGUYDK" } }; Assert.Equal(new[] { "deployment", "pull_request" }.ToList(), actualHook.Events.ToList()); @@ -237,6 +401,14 @@ namespace Octokit.Tests.Integration.Clients await github.Repository.Hooks.Test(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id); } + + [IntegrationTest] + public async Task TestACreatedHookWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + await github.Repository.Hooks.Test(_fixture.RepositoryId, _fixture.ExpectedHook.Id); + } } [Collection(RepositoriesHooksCollection.Name)] @@ -256,6 +428,14 @@ namespace Octokit.Tests.Integration.Clients await github.Repository.Hooks.Ping(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id); } + + [IntegrationTest] + public async Task PingACreatedHookWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + await github.Repository.Hooks.Ping(_fixture.RepositoryId, _fixture.ExpectedHook.Id); + } } [Collection(RepositoriesHooksCollection.Name)] @@ -276,7 +456,18 @@ namespace Octokit.Tests.Integration.Clients await github.Repository.Hooks.Delete(_fixture.RepositoryOwner, _fixture.RepositoryName, _fixture.ExpectedHook.Id); var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName); - Assert.Equal(4, hooks.Count); + Assert.Empty(hooks.Where(hook => hook.Id == _fixture.ExpectedHook.Id)); + } + + [IntegrationTest] + public async Task DeleteCreatedWebHookWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + await github.Repository.Hooks.Delete(_fixture.RepositoryId, _fixture.ExpectedHooks[1].Id); + var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryId); + + Assert.Empty(hooks.Where(hook => hook.Id == _fixture.ExpectedHooks[1].Id)); } } diff --git a/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs b/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs index 09b47c1c..0e713acc 100644 --- a/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs +++ b/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs @@ -29,6 +29,8 @@ namespace Octokit.Tests.Integration.fixtures public string RepositoryName { get { return _repository.Name; } } + public int RepositoryId { get { return _repository.Id; } } + public RepositoryHook ExpectedHook { get { return _hook; } } public IList ExpectedHooks { get { return _hooks; } }