added new unit tests

This commit is contained in:
Alexander Efremov
2016-06-13 13:06:31 +07:00
parent dcac7b9305
commit ce5388eef5
2 changed files with 519 additions and 59 deletions
+351 -46
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Helpers;
@@ -22,32 +23,87 @@ namespace Octokit.Tests.Clients
public class TheGetContributorsMethod
{
[Fact]
public async Task RetrievesContributorsForCorrectUrl()
public async Task RequestsCorrectUrl()
{
var expectedEndPoint = new Uri("repos/username/repositoryName/stats/contributors", UriKind.Relative);
var client = Substitute.For<IApiConnection>();
var expectedEndPoint = new Uri("repos/owner/name/stats/contributors", UriKind.Relative);
IReadOnlyList<Contributor> contributors = new ReadOnlyCollection<Contributor>(new[] { new Contributor() });
client.GetQueuedOperation<Contributor>(expectedEndPoint, Args.CancellationToken)
.Returns(Task.FromResult(contributors));
var statisticsClient = new StatisticsClient(client);
var result = await statisticsClient.GetContributors("username", "repositoryName");
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<Contributor>(expectedEndPoint, Args.CancellationToken)
.Returns(Task.FromResult(contributors));
var client = new StatisticsClient(connection);
var result = await client.GetContributors("owner", "name");
Assert.Equal(1, result.Count);
}
[Fact]
public async Task ThrowsIfGivenNullOwner()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetContributors(null, "repositoryName"));
var expectedEndPoint = new Uri("repositories/1/stats/contributors", UriKind.Relative);
IReadOnlyList<Contributor> contributors = new ReadOnlyCollection<Contributor>(new[] { new Contributor() });
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<Contributor>(expectedEndPoint, Args.CancellationToken)
.Returns(Task.FromResult(contributors));
var client = new StatisticsClient(connection);
var result = await client.GetContributors(1);
Assert.Equal(1, result.Count);
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
public async Task RequestsCorrectUrlWithCancellactionToken()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetContributors("owner", null));
var expectedEndPoint = new Uri("repos/owner/name/stats/contributors", UriKind.Relative);
IReadOnlyList<Contributor> contributors = new ReadOnlyCollection<Contributor>(new[] { new Contributor() });
var cancellationToken = new CancellationToken(true);
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<Contributor>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(contributors));
var client = new StatisticsClient(connection);
var result = await client.GetContributors("owner", "name", cancellationToken);
Assert.Equal(1, result.Count);
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryIdWithCancellactionToken()
{
var expectedEndPoint = new Uri("repositories/1/stats/contributors", UriKind.Relative);
IReadOnlyList<Contributor> contributors = new ReadOnlyCollection<Contributor>(new[] { new Contributor() });
var cancellationToken = new CancellationToken(true);
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<Contributor>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(contributors));
var client = new StatisticsClient(connection);
var result = await client.GetContributors(1, cancellationToken);
Assert.Equal(1, result.Count);
}
[Fact]
public async Task EnsureNonNullArguments()
{
var client = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetContributors(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetContributors("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetContributors("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetContributors("owner", ""));
}
}
@@ -56,7 +112,7 @@ namespace Octokit.Tests.Clients
[Fact]
public async Task RequestsCorrectUrl()
{
var expectedEndPoint = new Uri("repos/username/repositoryName/stats/commit_activity", UriKind.Relative);
var expectedEndPoint = new Uri("repos/owner/name/stats/commit_activity", UriKind.Relative);
var data = new WeeklyCommitActivity(new[] { 1, 2 }, 100, 42);
IReadOnlyList<WeeklyCommitActivity> response = new ReadOnlyCollection<WeeklyCommitActivity>(new[] { data });
@@ -65,7 +121,7 @@ namespace Octokit.Tests.Clients
.Returns(Task.FromResult(response));
var statisticsClient = new StatisticsClient(client);
var result = await statisticsClient.GetCommitActivity("username", "repositoryName");
var result = await statisticsClient.GetCommitActivity("owner", "name");
Assert.Equal(2, result.Activity[0].Days.Count);
Assert.Equal(1, result.Activity[0].Days[0]);
@@ -75,17 +131,82 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task ThrowsIfGivenNullOwner()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetCommitActivity(null, "repositoryName"));
var expectedEndPoint = new Uri("repositories/1/stats/commit_activity", UriKind.Relative);
var data = new WeeklyCommitActivity(new[] { 1, 2 }, 100, 42);
IReadOnlyList<WeeklyCommitActivity> response = new ReadOnlyCollection<WeeklyCommitActivity>(new[] { data });
var client = Substitute.For<IApiConnection>();
client.GetQueuedOperation<WeeklyCommitActivity>(expectedEndPoint, Args.CancellationToken)
.Returns(Task.FromResult(response));
var statisticsClient = new StatisticsClient(client);
var result = await statisticsClient.GetCommitActivity(1);
Assert.Equal(2, result.Activity[0].Days.Count);
Assert.Equal(1, result.Activity[0].Days[0]);
Assert.Equal(2, result.Activity[0].Days[1]);
Assert.Equal(100, result.Activity[0].Total);
Assert.Equal(42, result.Activity[0].Week);
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
public async Task RequestsCorrectUrlWithCancellationToken()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetCommitActivity("owner", null));
var expectedEndPoint = new Uri("repos/owner/name/stats/commit_activity", UriKind.Relative);
var cancellationToken = new CancellationToken();
var data = new WeeklyCommitActivity(new[] { 1, 2 }, 100, 42);
IReadOnlyList<WeeklyCommitActivity> response = new ReadOnlyCollection<WeeklyCommitActivity>(new[] { data });
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<WeeklyCommitActivity>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(response));
var client = new StatisticsClient(connection);
var result = await client.GetCommitActivity("owner", "name", cancellationToken);
Assert.Equal(2, result.Activity[0].Days.Count);
Assert.Equal(1, result.Activity[0].Days[0]);
Assert.Equal(2, result.Activity[0].Days[1]);
Assert.Equal(100, result.Activity[0].Total);
Assert.Equal(42, result.Activity[0].Week);
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
{
var expectedEndPoint = new Uri("repositories/1/stats/commit_activity", UriKind.Relative);
var cancellationToken = new CancellationToken();
var data = new WeeklyCommitActivity(new[] { 1, 2 }, 100, 42);
IReadOnlyList<WeeklyCommitActivity> response = new ReadOnlyCollection<WeeklyCommitActivity>(new[] { data });
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<WeeklyCommitActivity>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(response));
var client = new StatisticsClient(connection);
var result = await client.GetCommitActivity(1, cancellationToken);
Assert.Equal(2, result.Activity[0].Days.Count);
Assert.Equal(1, result.Activity[0].Days[0]);
Assert.Equal(2, result.Activity[0].Days[1]);
Assert.Equal(100, result.Activity[0].Total);
Assert.Equal(42, result.Activity[0].Week);
}
[Fact]
public async Task EnsureNonNullArguments()
{
var client = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCommitActivity(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCommitActivity("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCommitActivity("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCommitActivity("owner", ""));
}
}
@@ -94,7 +215,7 @@ namespace Octokit.Tests.Clients
[Fact]
public async Task RequestsCorrectUrl()
{
var expectedEndPoint = new Uri("repos/username/repositoryName/stats/code_frequency", UriKind.Relative);
var expectedEndPoint = new Uri("repos/owner/name/stats/code_frequency", UriKind.Relative);
long firstTimestamp = 159670861;
long secondTimestamp = 0;
@@ -108,7 +229,7 @@ namespace Octokit.Tests.Clients
.Returns(Task.FromResult(data));
var statisticsClient = new StatisticsClient(client);
var codeFrequency = await statisticsClient.GetCodeFrequency("username", "repositoryName");
var codeFrequency = await statisticsClient.GetCodeFrequency("owner", "name");
Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count);
Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp);
@@ -120,17 +241,103 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task ThrowsIfGivenNullOwner()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetCodeFrequency(null, "repositoryName"));
var expectedEndPoint = new Uri("repositories/1/stats/code_frequency", UriKind.Relative);
long firstTimestamp = 159670861;
long secondTimestamp = 0;
IReadOnlyList<long[]> data = new ReadOnlyCollection<long[]>(new[]
{
new[] { firstTimestamp, 10, 52 },
new[] { secondTimestamp, 0, 9 }
});
var client = Substitute.For<IApiConnection>();
client.GetQueuedOperation<long[]>(expectedEndPoint, Args.CancellationToken)
.Returns(Task.FromResult(data));
var statisticsClient = new StatisticsClient(client);
var codeFrequency = await statisticsClient.GetCodeFrequency(1);
Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count);
Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp);
Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions);
Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions);
Assert.Equal(secondTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp);
Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions);
Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions);
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
public async Task RequestsCorrectUrlWithCancellationToken()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetCodeFrequency("owner", null));
var expectedEndPoint = new Uri("repos/owner/name/stats/code_frequency", UriKind.Relative);
var cancellationToken = new CancellationToken();
long firstTimestamp = 159670861;
long secondTimestamp = 0;
IReadOnlyList<long[]> data = new ReadOnlyCollection<long[]>(new[]
{
new[] { firstTimestamp, 10, 52 },
new[] { secondTimestamp, 0, 9 }
});
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<long[]>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(data));
var client = new StatisticsClient(connection);
var codeFrequency = await client.GetCodeFrequency("owner", "name", cancellationToken);
Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count);
Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp);
Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions);
Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions);
Assert.Equal(secondTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp);
Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions);
Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions);
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
{
var expectedEndPoint = new Uri("repositories/1/stats/code_frequency", UriKind.Relative);
var cancellationToken = new CancellationToken();
long firstTimestamp = 159670861;
long secondTimestamp = 0;
IReadOnlyList<long[]> data = new ReadOnlyCollection<long[]>(new[]
{
new[] { firstTimestamp, 10, 52 },
new[] { secondTimestamp, 0, 9 }
});
var connection = Substitute.For<IApiConnection>();
connection.GetQueuedOperation<long[]>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(data));
var client = new StatisticsClient(connection);
var codeFrequency = await client.GetCodeFrequency(1, cancellationToken);
Assert.Equal(2, codeFrequency.AdditionsAndDeletionsByWeek.Count);
Assert.Equal(firstTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[0].Timestamp);
Assert.Equal(10, codeFrequency.AdditionsAndDeletionsByWeek[0].Additions);
Assert.Equal(52, codeFrequency.AdditionsAndDeletionsByWeek[0].Deletions);
Assert.Equal(secondTimestamp.FromUnixTime(), codeFrequency.AdditionsAndDeletionsByWeek[1].Timestamp);
Assert.Equal(0, codeFrequency.AdditionsAndDeletionsByWeek[1].Additions);
Assert.Equal(9, codeFrequency.AdditionsAndDeletionsByWeek[1].Deletions);
}
[Fact]
public async Task EnsureNonNullArguments()
{
var client = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCodeFrequency(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCodeFrequency("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCodeFrequency("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCodeFrequency("owner", ""));
}
}
@@ -139,37 +346,76 @@ namespace Octokit.Tests.Clients
[Fact]
public void RequestsCorrectUrl()
{
var expectedEndPoint = new Uri("repos/username/repositoryName/stats/participation", UriKind.Relative);
var expectedEndPoint = new Uri("repos/owner/name/stats/participation", UriKind.Relative);
var client = Substitute.For<IApiConnection>();
var statisticsClient = new StatisticsClient(client);
statisticsClient.GetParticipation("username", "repositoryName");
statisticsClient.GetParticipation("owner", "name");
client.Received().GetQueuedOperation<Participation>(expectedEndPoint, Args.CancellationToken);
}
[Fact]
public async Task ThrowsIfGivenNullOwner()
public void RequestsCorrectUrlWithRepositoryId()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetParticipation(null, "repositoryName"));
var expectedEndPoint = new Uri("repositories/1/stats/participation", UriKind.Relative);
var client = Substitute.For<IApiConnection>();
var statisticsClient = new StatisticsClient(client);
statisticsClient.GetParticipation(1);
client.Received().GetQueuedOperation<Participation>(expectedEndPoint, Args.CancellationToken);
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
public void RequestsCorrectUrlWithCancellationToken()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetParticipation("owner", null));
var expectedEndPoint = new Uri("repos/owner/name/stats/participation", UriKind.Relative);
var cancellationToken = new CancellationToken();
var client = Substitute.For<IApiConnection>();
var statisticsClient = new StatisticsClient(client);
statisticsClient.GetParticipation("owner", "name", cancellationToken);
client.Received().GetQueuedOperation<Participation>(expectedEndPoint, cancellationToken);
}
[Fact]
public void RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
{
var expectedEndPoint = new Uri("repositories/1/stats/participation", UriKind.Relative);
var cancellationToken = new CancellationToken();
var client = Substitute.For<IApiConnection>();
var statisticsClient = new StatisticsClient(client);
statisticsClient.GetParticipation(1, cancellationToken);
client.Received().GetQueuedOperation<Participation>(expectedEndPoint, cancellationToken);
}
[Fact]
public async Task EnsureNonNullArguments()
{
var client = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetParticipation(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetParticipation("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetParticipation("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetParticipation("owner", ""));
}
}
public class TheGetHourlyCommitCountsMethod
{
[Fact]
public async Task RetrievesPunchCard()
public async Task RequestsCorrectUrl()
{
var expectedEndPoint = new Uri("repos/username/repositoryName/stats/punch_card", UriKind.Relative);
var expectedEndPoint = new Uri("repos/owner/name/stats/punch_card", UriKind.Relative);
var client = Substitute.For<IApiConnection>();
IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });
@@ -177,7 +423,7 @@ namespace Octokit.Tests.Clients
.Returns(Task.FromResult(data));
var statisticsClient = new StatisticsClient(client);
var result = await statisticsClient.GetPunchCard("username", "repositoryName");
var result = await statisticsClient.GetPunchCard("owner", "name");
Assert.Equal(1, result.PunchPoints.Count);
Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
@@ -186,17 +432,76 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task ThrowsIfGivenNullOwner()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetPunchCard(null, "repositoryName"));
var expectedEndPoint = new Uri("repositories/1/stats/punch_card", UriKind.Relative);
var client = Substitute.For<IApiConnection>();
IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });
client.GetQueuedOperation<int[]>(expectedEndPoint, Args.CancellationToken)
.Returns(Task.FromResult(data));
var statisticsClient = new StatisticsClient(client);
var result = await statisticsClient.GetPunchCard(1);
Assert.Equal(1, result.PunchPoints.Count);
Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
Assert.Equal(42, result.PunchPoints[0].CommitCount);
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
public async Task RequestsCorrectUrlWithCancellationToken()
{
var statisticsClient = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetPunchCard("owner", null));
var expectedEndPoint = new Uri("repos/owner/name/stats/punch_card", UriKind.Relative);
var cancellationToken = new CancellationToken();
var connection = Substitute.For<IApiConnection>();
IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });
connection.GetQueuedOperation<int[]>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(data));
var client = new StatisticsClient(connection);
var result = await client.GetPunchCard("owner", "name", cancellationToken);
Assert.Equal(1, result.PunchPoints.Count);
Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
Assert.Equal(42, result.PunchPoints[0].CommitCount);
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryIdWithCancellationToken()
{
var expectedEndPoint = new Uri("repositories/1/stats/punch_card", UriKind.Relative);
var cancellationToken = new CancellationToken();
var connection = Substitute.For<IApiConnection>();
IReadOnlyList<int[]> data = new ReadOnlyCollection<int[]>(new[] { new[] { 2, 8, 42 } });
connection.GetQueuedOperation<int[]>(expectedEndPoint, cancellationToken)
.Returns(Task.FromResult(data));
var client = new StatisticsClient(connection);
var result = await client.GetPunchCard(1, cancellationToken);
Assert.Equal(1, result.PunchPoints.Count);
Assert.Equal(DayOfWeek.Tuesday, result.PunchPoints[0].DayOfWeek);
Assert.Equal(8, result.PunchPoints[0].HourOfTheDay);
Assert.Equal(42, result.PunchPoints[0].CommitCount);
}
[Fact]
public async Task EnsureNonNullArguments()
{
var client = new StatisticsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPunchCard(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetPunchCard("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetPunchCard("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetPunchCard("owner", ""));
}
}
}
@@ -1,6 +1,4 @@
using System;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
@@ -18,32 +16,189 @@ namespace Octokit.Tests.Reactive
}
}
public class TheGetMethod
public class TheGetContributorsMethod
{
[Fact]
public void GetsFromClientIssueMilestone()
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetContributors("username", "repositoryName");
statisticsClient.GetContributors("owner", "name");
gitHubClient.Repository.Statistics.Received().GetContributors("username", "repositoryName");
gitHubClient.Repository.Statistics.Received().GetContributors("owner", "name");
}
[Fact]
public async Task ThrowsIfGivenNullRepositoryName()
public void RequestsCorrectUrlWithRepositoryId()
{
var statisticsClient = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetContributors("owner", null).ToTask());
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetContributors(1);
gitHubClient.Repository.Statistics.Received().GetContributors(1);
}
[Fact]
public async Task ThrowsIfGivenNullOwnerName()
public void EnsureNonNullArguments()
{
var statisticsClient = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => statisticsClient.GetContributors(null, "repositoryName").ToTask());
var client = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetContributors("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetContributors(null, "name"));
Assert.Throws<ArgumentException>(() => client.GetContributors("", "name"));
Assert.Throws<ArgumentException>(() => client.GetContributors("owner", ""));
}
}
public class TheGetCommitActivityMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetCommitActivity("owner", "name");
gitHubClient.Repository.Statistics.Received().GetCommitActivity("owner", "name");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetCommitActivity(1);
gitHubClient.Repository.Statistics.Received().GetCommitActivity(1);
}
[Fact]
public void EnsureNonNullArguments()
{
var client = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetCommitActivity("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetCommitActivity(null, "name"));
Assert.Throws<ArgumentException>(() => client.GetCommitActivity("", "name"));
Assert.Throws<ArgumentException>(() => client.GetCommitActivity("owner", ""));
}
}
public class TheGetCodeFrequencyMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetCodeFrequency("owner", "name");
gitHubClient.Repository.Statistics.Received().GetCodeFrequency("owner", "name");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetCodeFrequency(1);
gitHubClient.Repository.Statistics.Received().GetCodeFrequency(1);
}
[Fact]
public void EnsureNonNullArguments()
{
var client = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetCodeFrequency("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetCodeFrequency(null, "name"));
Assert.Throws<ArgumentException>(() => client.GetCodeFrequency("", "name"));
Assert.Throws<ArgumentException>(() => client.GetCodeFrequency("owner", ""));
}
}
public class TheGetParticipationMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetParticipation("owner", "name");
gitHubClient.Repository.Statistics.Received().GetParticipation("owner", "name");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetParticipation(1);
gitHubClient.Repository.Statistics.Received().GetParticipation(1);
}
[Fact]
public void EnsureNonNullArguments()
{
var client = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetParticipation("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetParticipation(null, "name"));
Assert.Throws<ArgumentException>(() => client.GetParticipation("", "name"));
Assert.Throws<ArgumentException>(() => client.GetParticipation("owner", ""));
}
}
public class TheGetPunchCardMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetPunchCard("owner", "name");
gitHubClient.Repository.Statistics.Received().GetPunchCard("owner", "name");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var statisticsClient = new ObservableStatisticsClient(gitHubClient);
statisticsClient.GetPunchCard(1);
gitHubClient.Repository.Statistics.Received().GetPunchCard(1);
}
[Fact]
public void EnsureNonNullArguments()
{
var client = new ObservableStatisticsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetPunchCard("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetPunchCard(null, "name"));
Assert.Throws<ArgumentException>(() => client.GetPunchCard("", "name"));
Assert.Throws<ArgumentException>(() => client.GetPunchCard("owner", ""));
}
}
}
}
}