Skip to content

Commit

Permalink
Fix xUnit Warnings (#2906)
Browse files Browse the repository at this point in the history
* Fix xUnit Warnings

* Fix

* Fix formatting in AsyncPaginationExtensionGenerator.cs

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
thomhurst and kfcampbell committed Apr 15, 2024
1 parent 4ca8f1c commit cd18353
Show file tree
Hide file tree
Showing 83 changed files with 543 additions and 538 deletions.
34 changes: 19 additions & 15 deletions Octokit.Generators/AsyncPaginationExtensionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace Octokit.Generators
class AsyncPaginationExtensionsGenerator
{

private const string HEADER = (
@"using System;
private const string HEADER = (
@"using System;
using System.Collections.Generic;
namespace Octokit.AsyncPaginationExtension
Expand All @@ -44,8 +44,8 @@ public static class Extensions
private const int DEFAULT_PAGE_SIZE = 30;
");

private const string FOOTER = (
@"
private const string FOOTER = (
@"
}
}");

Expand All @@ -63,15 +63,17 @@ public static async Task GenerateAsync(string root = "./")
var enumOptions = new EnumerationOptions { RecurseSubdirectories = true };
var paginatedCallRegex = new Regex(@".*Task<IReadOnlyList<(?<returnType>\w+)>>\s*(?<name>\w+)(?<template><.*>)?\((?<arg>.*?)(, )?ApiOptions \w*\);");

foreach (var file in Directory.EnumerateFiles(root, "I*.cs", enumOptions)) {
var type = Path.GetFileNameWithoutExtension(file);
foreach (var file in Directory.EnumerateFiles(root, "I*.cs", enumOptions))
{
var type = Path.GetFileNameWithoutExtension(file);

foreach (var line in File.ReadAllLines(file)) {
var match = paginatedCallRegex.Match(line);
foreach (var line in File.ReadAllLines(file))
{
var match = paginatedCallRegex.Match(line);

if (!match.Success) { continue; }
sb.Append(BuildBodyFromTemplate(match, type));
}
if (!match.Success) { continue; }
sb.Append(BuildBodyFromTemplate(match, type));
}
}

sb.Append(FOOTER);
Expand Down Expand Up @@ -101,12 +103,14 @@ private static string BuildBodyFromTemplate(Match match, string type)
: $"options => t.{name}{templateStr}({string.Join(' ', splitArgs.Where((_, i) => i % 2 == 1))}, options)";

var docArgs = string.Join(", ", splitArgs.Where((_, i) => i % 2 == 0)).Replace('<', '{').Replace('>', '}');
if (docArgs.Length != 0) {
docArgs += ", ";
if (docArgs.Length != 0)
{
docArgs += ", ";
}

if (arg.Length != 0) {
arg += ", ";
if (arg.Length != 0)
{
arg += ", ";
}

return ($@"
Expand Down
4 changes: 2 additions & 2 deletions Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public async Task GetsAllAnnotations()
var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id);

// Check result
Assert.Equal(1, annotations.Count);
Assert.Single(annotations);
Assert.Equal("this is a warning", annotations.First().Message);
Assert.Equal(CheckAnnotationLevel.Warning, annotations.First().AnnotationLevel);
}
Expand Down Expand Up @@ -454,7 +454,7 @@ public async Task GetsAllAnnotationsWithRepositoryId()
var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryId, created.Id);

// Check result
Assert.Equal(1, annotations.Count);
Assert.Single(annotations);
Assert.Equal("this is a warning", annotations.First().Message);
Assert.Equal(CheckAnnotationLevel.Warning, annotations.First().AnnotationLevel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task ReturnsCorrectCountOfReactionsWithoutStart()
};
var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, options);

Assert.Equal(1, reactions.Count);
Assert.Single(reactions);

Assert.Equal(reaction.Id, reactions[0].Id);
Assert.Equal(reaction.Content, reactions[0].Content);
Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task ReturnsCorrectCountOfReactionsWithStart()
};
var reactionsInfo = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, options);

Assert.Equal(1, reactionsInfo.Count);
Assert.Single(reactionsInfo);

Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id);
Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content);
Expand Down Expand Up @@ -173,8 +173,8 @@ public async Task ReturnsDistinctReactionsBasedOnStartPage()
};
var secondPage = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, skipStartOptions);

Assert.Equal(1, firstPage.Count);
Assert.Equal(1, secondPage.Count);
Assert.Single(firstPage);
Assert.Single(secondPage);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
Assert.NotEqual(firstPage[0].Content, secondPage[0].Content);
}
Expand Down Expand Up @@ -225,7 +225,7 @@ public async Task ReturnsCorrectCountOfReactionsWithoutStartWithRepositoryId()
};
var reactions = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, options);

Assert.Equal(1, reactions.Count);
Assert.Single(reactions);

Assert.Equal(reaction.Id, reactions[0].Id);
Assert.Equal(reaction.Content, reactions[0].Content);
Expand Down Expand Up @@ -260,7 +260,7 @@ public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId()
};
var reactionsInfo = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, options);

Assert.Equal(1, reactionsInfo.Count);
Assert.Single(reactionsInfo);

Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id);
Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content);
Expand Down Expand Up @@ -301,8 +301,8 @@ public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId()
};
var secondPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, skipStartOptions);

Assert.Equal(1, firstPage.Count);
Assert.Equal(1, secondPage.Count);
Assert.Single(firstPage);
Assert.Single(secondPage);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
Assert.NotEqual(firstPage[0].Content, secondPage[0].Content);
}
Expand Down
20 changes: 10 additions & 10 deletions Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task ReturnsCorrectCountOfStatusesWithoutStart()
var statuses = await github.Repository.Status.GetAll("rails", "rails",
"94b857899506612956bb542e28e292308accb908", options);

Assert.Equal(1, statuses.Count);
Assert.Single(statuses);
}

[IntegrationTest]
Expand All @@ -75,7 +75,7 @@ public async Task ReturnsCorrectCountOfStatusesWithStart()
var statuses = await github.Repository.Status.GetAll("rails", "rails",
"94b857899506612956bb542e28e292308accb908", options);

Assert.Equal(1, statuses.Count);
Assert.Single(statuses);
}

[IntegrationTest]
Expand All @@ -101,8 +101,8 @@ public async Task ReturnsDistinctStatusesBasedOnStartPage()

var secondPage = await github.Repository.Status.GetAll("rails", "rails", "94b857899506612956bb542e28e292308accb908", skipStartOptions);

Assert.Equal(1, firstPage.Count);
Assert.Equal(1, secondPage.Count);
Assert.Single(firstPage);
Assert.Single(secondPage);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
}

Expand All @@ -120,7 +120,7 @@ public async Task ReturnsCorrectCountOfStatusesWithRepositoryIdWithoutStart()
var statuses = await github.Repository.Status.GetAll(8514,
"94b857899506612956bb542e28e292308accb908", options);

Assert.Equal(1, statuses.Count);
Assert.Single(statuses);
}

[IntegrationTest]
Expand All @@ -138,7 +138,7 @@ public async Task ReturnsCorrectCountOfStatusesWithRepositoryIdWithStart()
var statuses = await github.Repository.Status.GetAll(8514,
"94b857899506612956bb542e28e292308accb908", options);

Assert.Equal(1, statuses.Count);
Assert.Single(statuses);
}

[IntegrationTest]
Expand All @@ -164,8 +164,8 @@ public async Task ReturnsDistinctStatusesBasedOnStartPageWithRepositoryId()

var secondPage = await github.Repository.Status.GetAll(8514, "94b857899506612956bb542e28e292308accb908", skipStartOptions);

Assert.Equal(1, firstPage.Count);
Assert.Equal(1, secondPage.Count);
Assert.Single(firstPage);
Assert.Single(secondPage);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public async Task CanRetrievePendingStatus()

var statuses = await _github.Repository.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha);

Assert.Equal(1, statuses.Count);
Assert.Single(statuses);
Assert.Equal(CommitState.Pending, statuses[0].State);
}

Expand Down Expand Up @@ -289,7 +289,7 @@ public async Task CanProvideACommitStatusWithoutRequiringAContext()

var statuses = await _github.Repository.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha);

Assert.Equal(1, statuses.Count);
Assert.Single(statuses);
Assert.Equal("default", statuses[0].Context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public async Task ReturnsCorrectCountOfDeploymentStatusesWithStart()

var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, options);

Assert.Equal(1, deploymentStatuses.Count);
Assert.Single(deploymentStatuses);
}

[IntegrationTest]
Expand All @@ -190,7 +190,7 @@ public async Task ReturnsCorrectCountOfDeploymentStatusesWithStartWithRepository

var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, options);

Assert.Equal(1, deploymentStatuses.Count);
Assert.Single(deploymentStatuses);
}

[IntegrationTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task CanQueueSyncUserMapping()
// Check response message indicates LDAP sync was queued
Assert.NotNull(response);
Assert.NotNull(response.Status);
Assert.True(response.Status == "queued");
Assert.Equal("queued", response.Status);
}

[GitHubEnterpriseTest]
Expand Down Expand Up @@ -79,7 +79,7 @@ public async Task CanQueueSyncTeamMapping()
// Check response message indicates LDAP sync was queued
Assert.NotNull(response);
Assert.NotNull(response.Status);
Assert.True(response.Status == "queued");
Assert.Equal("queued", response.Status);
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task ReturnsCorrectCountOfPreReceiveEnvironmentsWithoutStart()

var preReceiveEnvironments = await _preReceiveEnvironmentsClient.GetAll(options);

Assert.Equal(1, preReceiveEnvironments.Count);
Assert.Single(preReceiveEnvironments);
}

[GitHubEnterpriseTest]
Expand All @@ -69,7 +69,7 @@ public async Task ReturnsCorrectCountOfPreReceiveEnvironmentsWithStart()

var preReceiveEnvironments = await _preReceiveEnvironmentsClient.GetAll(options);

Assert.Equal(1, preReceiveEnvironments.Count);
Assert.Single(preReceiveEnvironments);
}

[GitHubEnterpriseTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task ReturnsCorrectCountOfPreReceiveHooksWithoutStart()

var preReceiveHooks = await _preReceiveHooksClient.GetAll(options);

Assert.Equal(1, preReceiveHooks.Count);
Assert.Single(preReceiveHooks);
}

[GitHubEnterpriseTest]
Expand All @@ -69,7 +69,7 @@ public async Task ReturnsCorrectCountOfPreReceiveHooksWithStart()

var preReceiveHooks = await _preReceiveHooksClient.GetAll(options);

Assert.Equal(1, preReceiveHooks.Count);
Assert.Single(preReceiveHooks);
}

[GitHubEnterpriseTest]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/Clients/EventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void PushEventPayloadDeserializesCorrectly()
var pushPayload = pushEvent.Payload as PushEventPayload;
Assert.NotNull(pushPayload);
Assert.NotNull(pushPayload.Commits);
Assert.Equal(1, pushPayload.Commits.Count);
Assert.Single(pushPayload.Commits);
Assert.Equal("3cdcba0ccbea0e6d13ae94249fbb294d71648321", pushPayload.Commits.FirstOrDefault().Sha);
Assert.Equal("3cdcba0ccbea0e6d13ae94249fbb294d71648321", pushPayload.Head);
Assert.Equal("refs/heads/release-candidate", pushPayload.Ref);
Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests.Integration/Clients/GitHubClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task CanRetrieveLastApiInfoWithEtag()

var result = github.GetLastApiInfo();

Assert.True(result.Links.Count == 0);
Assert.Equal(0, result.Links.Count);
Assert.True(result.AcceptedOauthScopes.Count > -1);
Assert.True(result.OauthScopes.Count > -1);
Assert.False(string.IsNullOrEmpty(result.Etag));
Expand Down Expand Up @@ -67,8 +67,8 @@ public async Task CanRetrieveLastApiInfoAcceptedOauth()

var result = github.GetLastApiInfo();

Assert.True(result.Links.Count == 0);
Assert.True(result.AcceptedOauthScopes.Count == 0);
Assert.Equal(0, result.Links.Count);
Assert.Equal(0, result.AcceptedOauthScopes.Count);
Assert.True(result.OauthScopes.Count > 0);
Assert.False(string.IsNullOrEmpty(result.Etag));
Assert.True(result.RateLimit.Limit > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task ReturnsCorrectCountOfReactionsWithoutStart()

var reactions = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, options);

Assert.Equal(1, reactions.Count);
Assert.Single(reactions);

Assert.Equal(reactions[0].Id, issueCommentReaction.Id);
Assert.Equal(reactions[0].Content, issueCommentReaction.Content);
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task ReturnsCorrectCountOfReactionsWithStart()

var reactionsInfo = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, options);

Assert.Equal(1, reactionsInfo.Count);
Assert.Single(reactionsInfo);

Assert.Equal(reactionsInfo[0].Id, reactions.Last().Id);
Assert.Equal(reactionsInfo[0].Content, reactions.Last().Content);
Expand Down Expand Up @@ -143,8 +143,8 @@ public async Task ReturnsDistinctReactionsBasedOnStartPage()
};
var secondPage = await _github.Reaction.IssueComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, issueComment.Id, skipStartOptions);

Assert.Equal(1, firstPage.Count);
Assert.Equal(1, secondPage.Count);
Assert.Single(firstPage);
Assert.Single(secondPage);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
Assert.NotEqual(firstPage[0].Content, secondPage[0].Content);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task ReturnsCorrectCountOfReactionsWithoutStartWithRepositoryId()

var reactions = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, options);

Assert.Equal(1, reactions.Count);
Assert.Single(reactions);

Assert.Equal(reactions[0].Id, issueCommentReaction.Id);
Assert.Equal(reactions[0].Content, issueCommentReaction.Content);
Expand Down Expand Up @@ -229,7 +229,7 @@ public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId()

var reactionsInfo = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, options);

Assert.Equal(1, reactionsInfo.Count);
Assert.Single(reactionsInfo);

Assert.Equal(reactionsInfo[0].Id, reactions.Last().Id);
Assert.Equal(reactionsInfo[0].Content, reactions.Last().Content);
Expand Down Expand Up @@ -269,8 +269,8 @@ public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId()
};
var secondPage = await _github.Reaction.IssueComment.GetAll(_context.Repository.Id, issueComment.Id, skipStartOptions);

Assert.Equal(1, firstPage.Count);
Assert.Equal(1, secondPage.Count);
Assert.Single(firstPage);
Assert.Single(secondPage);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
Assert.NotEqual(firstPage[0].Content, secondPage[0].Content);
}
Expand Down
Loading

0 comments on commit cd18353

Please sign in to comment.