[WIP] Add repository traffic preview (#1457)

* Add response models

* Supress message

* correct spelling Timestamp

* implement traffic client

* add reactive client

* [WIP] unit tests

* add argument check

* finish unit tests

* add integration tests

* Change repositoryId from int to long
Remove GetAll naming of endpoints and add to PaginationTest exclusions
Rename View and Clone classes to be more specific
Add handling of TimeStamp fields being UtcUnix time
Add integration tests for repositoryId methods
This commit is contained in:
Martin Scholz
2016-09-28 17:16:58 +02:00
committed by Ryan Gribble
parent 693cc29dd5
commit a57fb1278d
31 changed files with 1281 additions and 2 deletions
@@ -0,0 +1,181 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Clients
{
public class RepositoryTrafficClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(
() => new RepositoryTrafficClient(null));
}
}
public class TheGetAllReferrersMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
await client.GetReferrers("fake", "repo");
connection.Received().GetAll<RepositoryTrafficReferrer>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/traffic/popular/referrers"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
await client.GetReferrers(1);
connection.Received().GetAll<RepositoryTrafficReferrer>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/traffic/popular/referrers"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryTrafficClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetReferrers(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetReferrers("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetReferrers("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetReferrers("owner", ""));
}
}
public class TheGetAllPathsMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
await client.GetPaths("fake", "repo");
connection.Received().GetAll<RepositoryTrafficPath>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/traffic/popular/paths"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
await client.GetPaths(1);
connection.Received().GetAll<RepositoryTrafficPath>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/traffic/popular/paths"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryTrafficClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPaths(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPaths("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetPaths("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetPaths("owner", ""));
}
}
public class TheGetClonesMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
var per = new RepositoryTrafficRequest(TrafficDayOrWeek.Day);
await client.GetClones("fake", "repo", per);
connection.Received().Get<RepositoryTrafficCloneSummary>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/traffic/clones"), Arg.Is<Dictionary<string, string>>(s => s["per"] == "day"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
var per = new RepositoryTrafficRequest(TrafficDayOrWeek.Day);
await client.GetClones(1, per);
connection.Received().Get<RepositoryTrafficCloneSummary>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/traffic/clones"), Arg.Is<Dictionary<string, string>>(s => s["per"] == "day"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryTrafficClient(Substitute.For<IApiConnection>());
var per = new RepositoryTrafficRequest(TrafficDayOrWeek.Day);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetClones(null, "name", per));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetClones("owner", null, per));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetClones("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetClones("", "name", per));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetClones("owner", "", per));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetClones(1, null));
}
}
public class TheGetViewsMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
var per = new RepositoryTrafficRequest(TrafficDayOrWeek.Day);
await client.GetViews("fake", "repo", per);
connection.Received().Get<RepositoryTrafficViewSummary>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/traffic/views"), Arg.Is<Dictionary<string, string>>(s => s["per"] == "day"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryTrafficClient(connection);
var per = new RepositoryTrafficRequest(TrafficDayOrWeek.Day);
await client.GetViews(1, per);
connection.Received().Get<RepositoryTrafficViewSummary>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/traffic/views"), Arg.Is<Dictionary<string, string>>(s => s["per"] == "day"), "application/vnd.github.spiderman-preview");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryTrafficClient(Substitute.For<IApiConnection>());
var per = new RepositoryTrafficRequest(TrafficDayOrWeek.Day);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetViews(null, "name", per));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetViews("owner", null, per));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetViews("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetViews("", "name", per));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetViews("owner", "", per));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetViews(1, null));
}
}
}
}