Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

893 readonlypagecollection null body #897

Merged
merged 2 commits into from
Sep 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Octokit.Tests/Http/ReadOnlyPagedCollectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit.Internal;
using NSubstitute;
using Xunit;

namespace Octokit.Tests.Http
{
public class ReadOnlyPagedCollectionTests
{
public class TheConstructor
{
[Fact]
public void AcceptsAResponseWithANullBody()
{
var response = Substitute.For<IApiResponse<List<string>>>();
response.Body.Returns((List<string>)null);

var exception = Record.Exception(() =>
new ReadOnlyPagedCollection<string>(response, uri => Task.FromResult(response)));

Assert.Null(exception);
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/OctoKit.Tests-NetCore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Authentication\TokenAuthenticatorTests.cs" />
<Compile Include="Http\ConnectionTests.cs" />
<Compile Include="Http\RateLimitTests.cs" />
<Compile Include="Http\ReadOnlyPagedCollectionTests.cs" />
<Compile Include="Http\ResponseTests.cs" />
<Compile Include="Http\RequestTests.cs" />
<Compile Include="Models\DeploymentStatusTests.cs" />
Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests-Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="Authentication\TokenAuthenticatorTests.cs" />
<Compile Include="Http\ConnectionTests.cs" />
<Compile Include="Http\RateLimitTests.cs" />
<Compile Include="Http\ReadOnlyPagedCollectionTests.cs" />
<Compile Include="Http\ResponseTests.cs" />
<Compile Include="Http\RequestTests.cs" />
<Compile Include="Models\DeploymentStatusTests.cs" />
Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<Compile Include="Http\ConnectionTests.cs" />
<Compile Include="Http\RateLimitTests.cs" />
<Compile Include="Http\RedirectHandlerTests.cs" />
<Compile Include="Http\ReadOnlyPagedCollectionTests.cs" />
<Compile Include="Http\ResponseTests.cs" />
<Compile Include="Http\RequestTests.cs" />
<Compile Include="Models\DeploymentStatusTests.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Http/ReadOnlyPagedCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReadOnlyPagedCollection<T> : ReadOnlyCollection<T>, IReadOnlyPagedC
readonly Func<Uri, Task<IApiResponse<List<T>>>> _nextPageFunc;

public ReadOnlyPagedCollection(IApiResponse<List<T>> response, Func<Uri, Task<IApiResponse<List<T>>>> nextPageFunc)
: base(response != null ? response.Body : new List<T>())
: base(response != null ? response.Body ?? new List<T>() : new List<T>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I really understand the power of the ?. operator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! 😒

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably upgrade our compiler to use C# 6 if someone wants to take a crack at it. As long as we don't break our other platforms.

{
Ensure.ArgumentNotNull(response, "response");
Ensure.ArgumentNotNull(nextPageFunc, "nextPageFunc");
Expand Down