Skip to content
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
61 changes: 61 additions & 0 deletions Octokit.Tests/Clients/AuditOrganizationsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;

namespace Octokit.Tests.Clients
{
public class AuditOrganizationsClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new AuditOrganizationsClient(null));
}
}

public class TheAuditLogQueryMethods
{
private static AuditOrganizationsClient CreateClientReturningNullResponse()
{
var connection = Substitute.For<IApiConnection>();
connection.Get<List<AuditLogEvent>>(Arg.Any<Uri>(), Arg.Any<IDictionary<string, string>>())
.Returns(Task.FromResult<List<AuditLogEvent>>(null));
return new AuditOrganizationsClient(connection);
}

[Fact]
public async Task GetRepositoryVisibilityChangeLastEventReturnsNullWhenResponseIsNull()
{
var client = CreateClientReturningNullResponse();

var result = await client.GetRepositoryVisibilityChangeLastEvent("org", new AuditLogPhraseOptions { Repository = "repo" });

Assert.Null(result);
}

[Fact]
public async Task GetRepositoryCreatedLastEventReturnsNullWhenResponseIsNull()
{
var client = CreateClientReturningNullResponse();

var result = await client.GetRepositoryCreatedLastEvent("org", new AuditLogPhraseOptions { Repository = "repo" });

Assert.Null(result);
}

[Fact]
public async Task GetUserLastActivityForRepositoryDateReturnsNullWhenResponseIsNull()
{
var client = CreateClientReturningNullResponse();

var result = await client.GetUserLastActivityForRepositoryDate("org", new AuditLogPhraseOptions { Repository = "repo", User = "user" });

Assert.Null(result);
}
}
}
}
6 changes: 3 additions & 3 deletions Octokit/Clients/AuditOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AuditOrganizationsClient(IApiConnection apiConnection) : base(apiConnecti
var phrase = auditLogPhraseOptions.BuildPhrase(organization, "repo.access");
var auditLogs = await ApiConnection.Get<List<AuditLogEvent>>(ApiUrls.AuditLog(organization, phrase), parameters);

if (!auditLogs.Any())
if (auditLogs is null || !auditLogs.Any())
{
return null;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public AuditOrganizationsClient(IApiConnection apiConnection) : base(apiConnecti
var phrase = auditLogPhraseOptions.BuildPhrase(organization, "repo.create");
var auditLogs = await ApiConnection.Get<List<AuditLogEvent>>(ApiUrls.AuditLog(organization, phrase), parameters);

if (!auditLogs.Any())
if (auditLogs is null || !auditLogs.Any())
{
return null;
}
Expand All @@ -120,7 +120,7 @@ public AuditOrganizationsClient(IApiConnection apiConnection) : base(apiConnecti
var phrase = auditLogPhraseOptions?.BuildPhrase(organization);
var auditLogs = await ApiConnection.Get<List<AuditLogEvent>>(ApiUrls.AuditLog(organization, phrase), parameters);

if (!auditLogs.Any())
if (auditLogs is null || !auditLogs.Any())
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>An async-based GitHub API client library for .NET and .NET Core</Description>
<AssemblyTitle>Octokit</AssemblyTitle>
<Authors>GitHub</Authors>
<Version>1.0.27</Version>
<Version>1.0.28</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Octokit</AssemblyName>
<PackageId>Apiiro.Octokit</PackageId>
Expand Down
Loading