Add unit test for ReadOnlyPagedCollection

This commit is contained in:
Haacked
2013-10-15 16:01:34 -07:00
parent bdb74af335
commit a98bc84530
2 changed files with 40 additions and 0 deletions
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Xunit;
namespace Octokit.Tests.Models
{
public class ReadOnlyPagedCollectionTests
{
public class TheGetNextPageMethod
{
[Fact]
public async Task ReturnsTheNextPage()
{
var nextPageUrl = new Uri("https://example.com/page/2");
var nextPageResponse = Task.Factory.StartNew<IResponse<List<object>>>(() =>
new ApiResponse<List<object>> {BodyAsObject = new List<object> {new object(), new object()}});
var links = new Dictionary<string, Uri> {{"next", nextPageUrl}};
var scopes = new List<string>();
var response = new ApiResponse<List<object>>
{
BodyAsObject = new List<object>(),
ApiInfo = new ApiInfo(links, scopes, scopes, "etag", 100, 100)
};
var connection = Substitute.For<IConnection>();
connection.GetAsync<List<object>>(nextPageUrl, null, null).Returns(nextPageResponse);
var pagedCollection = new ReadOnlyPagedCollection<object>(response, connection);
var nextPage = await pagedCollection.GetNextPage();
Assert.NotNull(nextPage);
Assert.Equal(2, nextPage.Count);
}
}
}
}
+1
View File
@@ -84,6 +84,7 @@
<Compile Include="Http\ResponseTests.cs" />
<Compile Include="Http\RequestTests.cs" />
<Compile Include="Models\ModelExtensionsTests.cs" />
<Compile Include="Models\ReadOnlyPagedCollectionTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\StringExtensionsTests.cs" />
<Compile Include="Clients\RepositoriesClientTests.cs" />