-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ObservableGitHubAppsClientTests.cs
236 lines (193 loc) · 8.63 KB
/
ObservableGitHubAppsClientTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Integration.Clients
{
public class ObservableGitHubAppsClientTests
{
public class TheGetMethod
{
readonly IObservableGitHubClient _github;
public TheGetMethod()
{
// Regular authentication
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
}
[GitHubAppsTest]
public async Task GetsApp()
{
var result = await _github.GitHubApps.Get(Helper.GitHubAppSlug);
Assert.Equal(Helper.GitHubAppId, result.Id);
Assert.Equal(Helper.GitHubAppSlug, result.Slug);
Assert.False(string.IsNullOrEmpty(result.Name));
Assert.NotNull(result.Owner);
}
}
public class TheGetCurrentMethod
{
readonly IObservableGitHubClient _github;
public TheGetCurrentMethod()
{
// Authenticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
}
[GitHubAppsTest]
public async Task GetsCurrentApp()
{
var result = await _github.GitHubApps.GetCurrent();
Assert.Equal(Helper.GitHubAppId, result.Id);
Assert.Equal(Helper.GitHubAppSlug, result.Slug);
Assert.False(string.IsNullOrEmpty(result.Name));
Assert.NotNull(result.Owner);
}
}
public class TheGetAllInstallationsForCurrentMethod
{
readonly IObservableGitHubClient _github;
public TheGetAllInstallationsForCurrentMethod()
{
// Authenticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
}
[GitHubAppsTest]
public async Task GetsAllInstallations()
{
var result = await _github.GitHubApps.GetAllInstallationsForCurrent().ToList();
foreach (var installation in result)
{
Assert.Equal(Helper.GitHubAppId, installation.AppId);
Assert.NotNull(installation.Account);
Assert.NotNull(installation.Permissions);
Assert.Equal(InstallationReadWritePermissionLevel.Read, installation.Permissions.Metadata);
Assert.False(string.IsNullOrEmpty(installation.HtmlUrl));
Assert.NotEqual(0, installation.TargetId);
}
}
}
public class TheGetInstallationForCurrentMethod
{
readonly IObservableGitHubClient _github;
public TheGetInstallationForCurrentMethod()
{
// Authenticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
}
[GitHubAppsTest]
public async Task GetsInstallation()
{
// Get the installation Id
var installationId = Helper.GetGitHubAppInstallationForOwner(Helper.UserName).Id;
// Get the installation by Id
var result = await _github.GitHubApps.GetInstallationForCurrent(installationId);
Assert.True(result.AppId == Helper.GitHubAppId);
Assert.Equal(Helper.GitHubAppId, result.AppId);
Assert.NotNull(result.Account);
Assert.NotNull(result.Permissions);
Assert.Equal(InstallationReadWritePermissionLevel.Read, result.Permissions.Metadata);
Assert.False(string.IsNullOrEmpty(result.HtmlUrl));
Assert.NotEqual(0, result.TargetId);
}
}
public class TheGetAllInstallationsForCurrentUserMethod
{
readonly IObservableGitHubClient _github;
public TheGetAllInstallationsForCurrentUserMethod()
{
// Need to Authenticate as User to Server but not possible without receiving redirect from github.com
//_github = new ObservableGitHubClient(Helper.GetAuthenticatedUserToServer());
_github = null;
}
[GitHubAppsTest(Skip = "Not possible to authenticate with User to Server auth")]
public async Task GetsAllInstallationsForCurrentUser()
{
var result = await _github.GitHubApps.GetAllInstallationsForCurrentUser();
Assert.NotNull(result);
Assert.True(result.TotalCount > 0);
}
}
public class TheCreateInstallationTokenMethod
{
readonly IObservableGitHubClient _github;
public TheCreateInstallationTokenMethod()
{
// Authenticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
}
[GitHubAppsTest]
public async Task CreatesInstallationToken()
{
// Get the installation Id
var installationId = Helper.GetGitHubAppInstallationForOwner(Helper.UserName).Id;
// Create installation token
var result = await _github.GitHubApps.CreateInstallationToken(installationId);
Assert.NotNull(result.Token);
Assert.True(DateTimeOffset.Now < result.ExpiresAt);
}
}
public class TheGetOrganizationInstallationForCurrentMethod
{
readonly IObservableGitHubClient _github;
public TheGetOrganizationInstallationForCurrentMethod()
{
// Authenticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
}
[GitHubAppsTest]
public async Task GetsOrganizationInstallations()
{
var result = await _github.GitHubApps.GetOrganizationInstallationForCurrent(Helper.Organization);
Assert.NotNull(result);
}
}
public class TheGetRepositoryInstallationForCurrentMethod
{
readonly IObservableGitHubClient _github;
readonly IObservableGitHubClient _githubAppInstallation;
public TheGetRepositoryInstallationForCurrentMethod()
{
// Autheticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsRepositoryInstallations()
{
// Find a repo under the installation
var repos = await _githubAppInstallation.GitHubApps.Installation.GetAllRepositoriesForCurrent();
var repo = repos.Repositories.First();
// Now, using the GitHub App auth, find this repository installation
var result = await _github.GitHubApps.GetRepositoryInstallationForCurrent(repo.Owner.Login, repo.Name);
Assert.NotNull(result);
}
[GitHubAppsTest]
public async Task GetsRepositoryInstallationsWithRepositoryId()
{
// Find a repo under the installation
var repos = await _githubAppInstallation.GitHubApps.Installation.GetAllRepositoriesForCurrent();
var repo = repos.Repositories.First();
// Now, using the GitHub App auth, find this repository installation
var result = await _github.GitHubApps.GetRepositoryInstallationForCurrent(repo.Id);
Assert.NotNull(result);
}
}
public class TheGetUserInstallationForCurrentMethod
{
readonly IObservableGitHubClient _github;
public TheGetUserInstallationForCurrentMethod()
{
// Authenticate as a GitHubApp
_github = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppsClient());
}
[GitHubAppsTest]
public async Task GetsUserInstallations()
{
var result = await _github.GitHubApps.GetUserInstallationForCurrent(Helper.UserName);
Assert.NotNull(result);
}
}
}
}