Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for GithubClient #176

Merged
merged 5 commits into from
Dec 15, 2021
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
38 changes: 19 additions & 19 deletions src/OctoshiftCLI.Tests/GithubApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task AddAutoLink_Calls_The_Right_Endpoint_With_Payload()
var payload =
$"{{ \"key_prefix\": \"AB#\", \"url_template\": \"https://dev.azure.com/{adoOrg}/{adoTeamProject}/_workitems/edit/<num>/\" }}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");

// Act
using var githubApi = new GithubApi(githubClientMock.Object);
Expand All @@ -45,7 +45,7 @@ public async Task CreateTeam_Returns_Created_Team_Id()
const string teamId = "TEAM_ID";
var response = $"{{\"id\": \"{teamId}\"}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task GetTeamMembers_Returns_Team_Members()
}}
]";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.GetAsync(url))
.ReturnsAsync(response);
Expand All @@ -103,7 +103,7 @@ public async Task RemoveTeamMember_Calls_The_Right_Endpoint()

var url = $"https://api.github.com/orgs/{org}/teams/{teamName}/memberships/{member}";

var githubClinetMock = new Mock<GithubClient>(null, null);
var githubClinetMock = new Mock<GithubClient>(null, "");
githubClinetMock.Setup(m => m.DeleteAsync(url));

// Act
Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task GetIdpGroup_Returns_Id_Name_And_Description_Of_Idp_Group()
]
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.GetAsync(url))
.ReturnsAsync(response);
Expand Down Expand Up @@ -169,7 +169,7 @@ public async Task AddTeamSync_Calls_The_Right_Endpoint_With_Payload()
var payload =
$"{{ \"groups\": [{{ \"group_id\":\"{groupId}\", \"group_name\":\"{groupName}\", \"group_description\":\"{groupDesc}\" }}] }}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");

// Act
using var githubApi = new GithubApi(githubClientMock.Object);
Expand All @@ -191,7 +191,7 @@ public async Task AddTeamToRepo_Calls_The_Right_Endpoint_With_Payload()
var url = $"https://api.github.com/orgs/{org}/teams/{teamName}/repos/{org}/{repo}";
var payload = $"{{ \"permission\":\"{role}\" }}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");

// Act
using var githubApi = new GithubApi(githubClientMock.Object);
Expand Down Expand Up @@ -224,7 +224,7 @@ public async Task GetOrganizationId_Returns_The_Org_Id()
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -264,7 +264,7 @@ public async Task CreateMigrationSource_Returns_New_Migration_Source_Id()
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -313,7 +313,7 @@ public async Task StartMigration_Returns_New_Repository_Migration_Id()
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -353,7 +353,7 @@ public async Task GetMigrationState_Returns_The_Migration_State()
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -392,7 +392,7 @@ public async Task GetMigrationFailureReason_Returns_The_Migration_Failure_Reason
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -430,7 +430,7 @@ public async Task GetIdpGroupId_Returns_The_Idp_Group_Id()
]
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.GetAsync(url))
.ReturnsAsync(response);
Expand Down Expand Up @@ -470,7 +470,7 @@ public async Task GetTeamSlug_Returns_The_Team_Slug()
}}
]";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.GetAsync(url))
.ReturnsAsync(response);
Expand All @@ -494,7 +494,7 @@ public async Task AddEmuGroupToTeam_Calls_The_Right_Endpoint_With_Payload()
var url = $"https://api.github.com/orgs/{org}/teams/{teamSlug}/external-groups";
var payload = $"{{ \"group_id\": {groupId} }}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");

// Act
using var githubApi = new GithubApi(githubClientMock.Object);
Expand Down Expand Up @@ -528,7 +528,7 @@ public async Task GrantMigratorRole_Returns_True_On_Success()
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -556,7 +556,7 @@ public async Task GrantMigratorRole_Returns_False_On_HttpRequestException()
$",\"variables\":{{\"organizationId\":\"{org}\", \"actor\":\"{actor}\", \"actor_type\":\"{actorType}\"}}," +
"\"operationName\":\"grantMigratorRole\"}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.Throws<HttpRequestException>();
Expand Down Expand Up @@ -593,7 +593,7 @@ public async Task RevokeMigratorRole_Returns_True_On_Success()
}}
}}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.ReturnsAsync(response);
Expand Down Expand Up @@ -621,7 +621,7 @@ public async Task RevokeMigratorRole_Returns_False_On_HttpRequestException()
$",\"variables\":{{\"organizationId\":\"{org}\", \"actor\":\"{actor}\", \"actor_type\":\"{actorType}\"}}," +
"\"operationName\":\"revokeMigratorRole\"}";

var githubClientMock = new Mock<GithubClient>(null, null);
var githubClientMock = new Mock<GithubClient>(null, "");
githubClientMock
.Setup(m => m.PostAsync(url, payload))
.Throws<HttpRequestException>();
Expand Down
Loading