Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4fddb5c
caching layer for GET responses
frankyfrankyren Jan 3, 2023
37fbf4e
Setting the ResponseCache property sets the caching layer/wrapper - C…
frankyfrankyren Jan 3, 2023
ef2b462
sets the underlying IHttpClient when passing a CachingHttpClient into…
frankyfrankyren Jan 3, 2023
d9c82dc
added tests for CachingHttpClient constructor
frankyfrankyren Jan 10, 2023
ab81983
ensures constructors parameters are not null for CachingHttpClient
frankyfrankyren Jan 10, 2023
146f930
added unit tests for CachingHttpClient::SetRequestTimeout
frankyfrankyren Jan 10, 2023
0f7dc19
added unit tests for CachingHttpClient::Dispose
frankyfrankyren Jan 10, 2023
cb8a7b2
added unit tests for CachingHttpClient::Send
frankyfrankyren Jan 10, 2023
f76ea9f
ensure we throw early when request parameter is null in CachingHttpCl…
frankyfrankyren Jan 10, 2023
8e5858e
added tests for CachedResponse.V1 constructor
frankyfrankyren Jan 10, 2023
5845227
ensure we throw when headers parameter is null in CachedResponse.V1 c…
frankyfrankyren Jan 10, 2023
7de3a05
added tests for CachedResponse.V1::Create and CachedResponse.V1::ToRe…
frankyfrankyren Jan 10, 2023
63f236c
ensure we throw early when response is null in CachedResponse.V1::Create
frankyfrankyren Jan 10, 2023
6c5d2d9
added more tests for CachingHttpClient::Send
frankyfrankyren Jan 10, 2023
8dc278e
tests for GithubClient Response property
frankyfrankyren Jan 10, 2023
9ebbfce
tests for Connection Response property
frankyfrankyren Jan 10, 2023
3e813ed
Merge branch 'main' into response-caching
nickfloyd Jan 13, 2023
17c2981
Merge branch 'main' into response-caching
nickfloyd Jan 23, 2023
c881c53
Merge branch 'main' into response-caching
nickfloyd Feb 6, 2023
23f6458
Merge branch 'main' into response-caching
nickfloyd Feb 7, 2023
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
102 changes: 102 additions & 0 deletions Octokit.Tests/Caching/CachedResponseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Net;
using NSubstitute;
using NSubstitute.ReturnsExtensions;
using Octokit.Caching;
using Octokit.Internal;
using Octokit.Tests.Helpers;
using Xunit;

namespace Octokit.Tests.Caching
{
public class CachedResponseTests
{
public class V1
{
public class TheToResponseMethod
{
[Fact]
public void CreatesResponseWithSameProperties()
{
var body = new object();
var headers = new Dictionary<string, string>();
var apiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit());
const HttpStatusCode httpStatusCode = HttpStatusCode.OK;
const string contentType = "content-type";
var v1 = new CachedResponse.V1(body, headers, apiInfo, httpStatusCode, contentType);

var response = v1.ToResponse();

Assert.Equal(new Response(httpStatusCode, body, headers, contentType), response, new ResponseComparer());
}
}

public class TheCreateMethod
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => CachedResponse.V1.Create(null));
}

[Fact]
public void EnsuresNonNullResponseHeader()
{
var response = Substitute.For<IResponse>();
response.Headers.ReturnsNull();

Assert.Throws<ArgumentNullException>(() => CachedResponse.V1.Create(response));
}

[Fact]
public void CreatesV1WithSameProperties()
{
var response = Substitute.For<IResponse>();
response.Headers.Returns(new Dictionary<string, string>());

var v1 = CachedResponse.V1.Create(response);
Assert.Equal(response.Body, v1.Body);
Assert.Equal(response.Headers, v1.Headers);
Assert.Equal(response.ApiInfo, v1.ApiInfo);
Assert.Equal(response.StatusCode, v1.StatusCode);
Assert.Equal(response.ContentType, v1.ContentType);
}
}

public class TheCtor
{
[Fact]
public void EnsuresNonNullHeaders()
{
Assert.Throws<ArgumentNullException>(() => new CachedResponse.V1("body", null, new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()), HttpStatusCode.OK, "content-type"));
}

[Fact]
public void AllowsParametersOtherThanHeadersToBeNull()
{
new CachedResponse.V1(null, new Dictionary<string, string>(), null, HttpStatusCode.OK, null);
}

[Fact]
public void SetsProperties()
{
var body = new object();
var headers = new Dictionary<string, string>();
var apiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit());
const HttpStatusCode httpStatusCode = HttpStatusCode.OK;
const string contentType = "content-type";

var v1 = new CachedResponse.V1(body, headers, apiInfo, httpStatusCode, contentType);

Assert.Equal(body, v1.Body);
Assert.Equal(headers, v1.Headers);
Assert.Equal(apiInfo, v1.ApiInfo);
Assert.Equal(httpStatusCode, v1.StatusCode);
Assert.Equal(contentType, v1.ContentType);
}
}
}

}
}
Loading