Files
octokit.net/Octokit.Tests/AsyncEnumerableExtensionTests.cs
dependabot[bot] c895ac8efb build(deps): bump xunit from 2.6.1 to 2.6.3 (#2834)
* build(deps): bump xunit from 2.6.1 to 2.6.3

Bumps [xunit](https://github.com/xunit/xunit) from 2.6.1 to 2.6.3.
- [Commits](https://github.com/xunit/xunit/compare/2.6.1...2.6.3)

---
updated-dependencies:
- dependency-name: xunit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Add required async/awaits

* public async void --> public async Task

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
2023-12-18 13:07:52 -08:00

82 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.AsyncPaginationExtension;
using Xunit;
namespace Octokit.Tests
{
public class AsyncEnumerableExtensionTests
{
public class ThePaginatedList
{
[Fact]
public async Task RejectsInvalidValues()
{
var client = Substitute.For<IRepositoriesClient>();
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => client.GetAllForOrgAsync("octokit")[-1]);
}
[Fact]
public async Task ReturnsNullOnExceedingTotalSize()
{
var client = Substitute.For<IRepositoriesClient>();
Assert.Null(await client.GetAllForOrgAsync("octokit")[int.MaxValue]);
}
[Fact]
public async Task EnumeratesCorrectValues()
{
var client = Substitute.For<IRepositoriesClient>();
var list = new List<Repository>();
var enumerator = client.GetAllForOrgAsync("octokit").GetAsyncEnumerator();
while (await enumerator.MoveNextAsync())
{
list.Add(enumerator.Current);
}
Assert.Equal(await client.GetAllForOrg("octokit"), list);
}
[Fact]
public async Task HandlesZeroCorrectly()
{
var client = Substitute.For<IRepositoriesClient>();
client.GetAllForOrg(Arg.Any<string>(), Arg.Any<ApiOptions>())
.Returns(Enumerable.Repeat(new Repository(), 24).ToList());
Assert.NotNull(await client.GetAllForOrgAsync("octokit")[0]);
}
[Fact]
public async Task HandlesPageEdgesCorrectly()
{
var client = Substitute.For<IRepositoriesClient>();
client.GetAllForOrg(Arg.Any<string>(), Arg.Any<ApiOptions>())
.Returns(Enumerable.Repeat(new Repository(), 5).ToList());
var repos = client.GetAllForOrgAsync("octokit", 5);
Assert.NotNull(await repos[4]);
Assert.NotNull(await repos[5]);
}
}
public class ThePaginationOverloads
{
[Fact]
public void RejectInvalidValues()
{
var client = Substitute.For<IRepositoriesClient>();
Assert.Throws<ArgumentOutOfRangeException>(() => client.GetAllForUserAsync("fake", -1));
Assert.Throws<ArgumentOutOfRangeException>(() => client.GetAllForUserAsync("fake", 0));
}
}
}
}