Skip to content

Commit

Permalink
added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-efremov committed Jun 9, 2016
1 parent 23eaf16 commit 053fb58
Showing 1 changed file with 230 additions and 0 deletions.
230 changes: 230 additions & 0 deletions Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ public async Task ReturnsForksForRepository()
Assert.Equal("TeamBinary", masterFork.Owner.Login);
}

[IntegrationTest]
public async Task ReturnsForksForRepositoryWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var forks = await github.Repository.Forks.GetAll(7528679);

var masterFork = forks.FirstOrDefault(fork => fork.FullName == "TeamBinary/octokit.net");
Assert.NotNull(masterFork);
Assert.Equal("TeamBinary", masterFork.Owner.Login);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithoutStart()
{
Expand All @@ -36,6 +48,22 @@ public async Task ReturnsCorrectCountOfForksWithoutStart()
Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithoutStartWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var options = new ApiOptions
{
PageCount = 1,
PageSize = 1
};

var forks = await github.Repository.Forks.GetAll(7528679, options);

Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithStart()
{
Expand All @@ -53,6 +81,23 @@ public async Task ReturnsCorrectCountOfForksWithStart()
Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithStartWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

var forks = await github.Repository.Forks.GetAll(7528679, options);

Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsDistinctForksBasedOnStartPage()
{
Expand Down Expand Up @@ -83,6 +128,36 @@ public async Task ReturnsDistinctForksBasedOnStartPage()
Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
}

[IntegrationTest]
public async Task ReturnsDistinctForksBasedOnStartPageWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var startOptions = new ApiOptions
{
PageCount = 1,
PageSize = 3,
StartPage = 1
};

var firstPage = await github.Repository.Forks.GetAll(7528679, startOptions);

var skipStartOptions = new ApiOptions
{
PageCount = 1,
PageSize = 3,
StartPage = 2
};

var secondPage = await github.Repository.Forks.GetAll(7528679, skipStartOptions);

Assert.Equal(3, firstPage.Count);
Assert.Equal(3, secondPage.Count);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
Assert.NotEqual(firstPage[1].Id, secondPage[1].Id);
Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithoutStartParameterized()
{
Expand All @@ -101,6 +176,24 @@ public async Task ReturnsCorrectCountOfForksWithoutStartParameterized()
Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithoutStartParameterizedWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var options = new ApiOptions
{
PageCount = 1,
PageSize = 1
};

var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest };

var forks = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, options);

Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithStartParameterized()
{
Expand All @@ -120,6 +213,25 @@ public async Task ReturnsCorrectCountOfForksWithStartParameterized()
Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfForksWithStartParameterizedWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest };

var forks = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, options);

Assert.Equal(1, forks.Count);
}

[IntegrationTest]
public async Task ReturnsDistinctForksBasedOnStartPageParameterized()
{
Expand Down Expand Up @@ -152,6 +264,38 @@ public async Task ReturnsDistinctForksBasedOnStartPageParameterized()
Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
}

[IntegrationTest]
public async Task ReturnsDistinctForksBasedOnStartPageParameterizedWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest };

var startOptions = new ApiOptions
{
PageCount = 1,
PageSize = 3,
StartPage = 1
};

var firstPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, startOptions);

var skipStartOptions = new ApiOptions
{
PageCount = 1,
PageSize = 3,
StartPage = 2
};

var secondPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, skipStartOptions);

Assert.Equal(3, firstPage.Count);
Assert.Equal(3, secondPage.Count);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
Assert.NotEqual(firstPage[1].Id, secondPage[1].Id);
Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
}

[IntegrationTest]
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithApiOptions()
{
Expand Down Expand Up @@ -190,6 +334,44 @@ public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithAp
}
}

[IntegrationTest]
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithApiOptionsWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Oldest };

var startOptions = new ApiOptions
{
PageCount = 1,
PageSize = 3,
StartPage = 1
};

var firstPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, startOptions);
var firstPageOrdered = firstPage.OrderBy(r => r.CreatedAt).ToList();

var skipStartOptions = new ApiOptions
{
PageCount = 1,
PageSize = 3,
StartPage = 1
};

var secondPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, skipStartOptions);
var secondPageOrdered = secondPage.OrderBy(r => r.CreatedAt).ToList();

for (var index = 0; index < firstPage.Count; index++)
{
Assert.Equal(firstPageOrdered[index].FullName, firstPage[index].FullName);
}

for (var index = 0; index < firstPage.Count; index++)
{
Assert.Equal(secondPageOrdered[index].FullName, secondPage[index].FullName);
}
}

[IntegrationTest]
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirst()
{
Expand All @@ -203,6 +385,20 @@ public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirst()
Assert.Equal(sortedForks[index].FullName, actualForks[index].FullName);
}
}

[IntegrationTest]
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();

var actualForks = (await github.Repository.Forks.GetAll(7528679, new RepositoryForksListRequest { Sort = Sort.Oldest })).ToArray();
var sortedForks = actualForks.OrderBy(fork => fork.CreatedAt).ToArray();

for (var index = 0; index < actualForks.Length; index++)
{
Assert.Equal(sortedForks[index].FullName, actualForks[index].FullName);
}
}
}

public class TheCreateMethod
Expand All @@ -224,6 +420,23 @@ public async Task ForkCreatedForUserLoggedIn()
Assert.Equal(true, forkCreated.Fork);
}

[IntegrationTest]
public async Task ForkCreatedForUserLoggedInWithRepositoryId()
{
// The fork is created asynchronously by github and therefore it cannot
// be certain that the repo exists when the test ends. It is therefore deleted
// before the test starts instead of after.
Helper.DeleteRepo(Helper.Credentials.Login, "octokit.net");

var github = Helper.GetAuthenticatedClient();

var forkCreated = await github.Repository.Forks.Create(7528679, new NewRepositoryFork());

Assert.NotNull(forkCreated);
Assert.Equal(string.Format("{0}/octokit.net", Helper.UserName), forkCreated.FullName);
Assert.Equal(true, forkCreated.Fork);
}

[OrganizationTest]
public async Task ForkCreatedForOrganization()
{
Expand All @@ -240,6 +453,23 @@ public async Task ForkCreatedForOrganization()
Assert.Equal(string.Format("{0}/octokit.net", Helper.Organization), forkCreated.FullName);
Assert.Equal(true, forkCreated.Fork);
}

[OrganizationTest]
public async Task ForkCreatedForOrganizationWithRepositoryId()
{
// The fork is created asynchronously by github and therefore it cannot
// be certain that the repo exists when the test ends. It is therefore deleted
// before the test starts.
Helper.DeleteRepo(Helper.Organization, "octokit.net");

var github = Helper.GetAuthenticatedClient();

var forkCreated = await github.Repository.Forks.Create(7528679, new NewRepositoryFork { Organization = Helper.Organization });

Assert.NotNull(forkCreated);
Assert.Equal(string.Format("{0}/octokit.net", Helper.Organization), forkCreated.FullName);
Assert.Equal(true, forkCreated.Fork);
}
}
}
}

0 comments on commit 053fb58

Please sign in to comment.