mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Add tests for ActivityClient
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class ActivitiesClientTests
|
||||
{
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetAll();
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "events"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllForRepositoryMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetAllForRepository("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllForRepository(null, "name"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllForRepository("", "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllForRepository("owner", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllForRepository("owner", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllForRepositoryNetworkMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetAllForRepositoryNetwork("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "networks/fake/repo/events"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllForRepositoryNetwork(null, "name"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllForRepositoryNetwork("", "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllForRepositoryNetwork("owner", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllForRepositoryNetwork("owner", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllForOrganizationMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetAllForOrganization("fake");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "orgs/fake/events"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllForOrganization(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllForOrganization(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetUserReceivedMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetUserReceived("fake");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "users/fake/received_events"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetUserReceived(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetUserReceived(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetUserReceivedPublicMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetUserReceivedPublic("fake");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "users/fake/received_events/public"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetUserReceivedPublic(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetUserReceivedPublic(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetUserPerformedMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetUserPerformed("fake");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "users/fake/events"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetUserPerformed(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetUserPerformed(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetUserPerformedPublicMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetUserPerformedPublic("fake");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "users/fake/events/public"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetUserPerformedPublic(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetUserPerformedPublic(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForAnOrganizationMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
client.GetForAnOrganization("fake", "org");
|
||||
|
||||
connection.Received().GetAll<Activity>(Arg.Is<Uri>(u => u.ToString() == "users/fake/events/orgs/org"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ActivitiesClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForAnOrganization(null, "org"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForAnOrganization("", "org"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForAnOrganization("fake", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForAnOrganization("fake", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Clients\ActivitiesClientTests.cs" />
|
||||
<Compile Include="Clients\AssigneesClientTests.cs" />
|
||||
<Compile Include="Clients\CommitStatusClientTests.cs" />
|
||||
<Compile Include="Clients\GitDatabaseClientTests.cs" />
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return ApiConnection.GetAll<Activity>(ApiUrls.ReceivedEvents(user), null, "public");
|
||||
return ApiConnection.GetAll<Activity>(ApiUrls.ReceivedEvents(user, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +129,7 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return ApiConnection.GetAll<Activity>(ApiUrls.PerformedEvents(user), null, "public");
|
||||
return ApiConnection.GetAll<Activity>(ApiUrls.PerformedEvents(user, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Octokit
|
||||
/// http://developer.github.com/v3/activity/events/#list-public-events
|
||||
/// </remarks>
|
||||
/// <returns>All the public <see cref="Activity"/>s for the particular user.</returns>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
||||
Task<IReadOnlyList<Activity>> GetAll();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
public static Uri NetworkEvents(string owner, string name)
|
||||
{
|
||||
return "network/{0}/{1}/event".FormatUri(owner, name);
|
||||
return "networks/{0}/{1}/events".FormatUri(owner, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -377,7 +377,23 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
public static Uri ReceivedEvents(string user)
|
||||
{
|
||||
return "users/{0}/received_events".FormatUri(user);
|
||||
return ReceivedEvents(user, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for the received events for a user.
|
||||
/// </summary>
|
||||
/// <param name="user">The name of the user</param>
|
||||
/// <param name="isPublic">Whether to return public events or not</param>
|
||||
/// <returns></returns>
|
||||
public static Uri ReceivedEvents(string user, bool isPublic)
|
||||
{
|
||||
string usersReceivedEvents = "users/{0}/received_events";
|
||||
if (isPublic)
|
||||
{
|
||||
usersReceivedEvents += "/public";
|
||||
}
|
||||
return usersReceivedEvents.FormatUri(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -387,7 +403,23 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
public static Uri PerformedEvents(string user)
|
||||
{
|
||||
return "users/{0}/events".FormatUri(user);
|
||||
return PerformedEvents(user, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for events performed by a user.
|
||||
/// </summary>
|
||||
/// <param name="user">The name of the user</param>
|
||||
/// <param name="isPublic">Whether to return public events or not</param>
|
||||
/// <returns></returns>
|
||||
public static Uri PerformedEvents(string user, bool isPublic)
|
||||
{
|
||||
string usersEvents = "users/{0}/events";
|
||||
if (isPublic)
|
||||
{
|
||||
usersEvents += "/public";
|
||||
}
|
||||
return usersEvents.FormatUri(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Octokit
|
||||
/// <summary>
|
||||
/// The type of the activity.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user