public async Task TestAuthenticateInvalidRepository() { var factory = mockRepository.Create <IGitHubClientFactory>(); var client = mockRepository.Create <IRepositoriesClient>(); factory.Setup(x => x.CreateClient(new Uri("https://www.example.com/"), "username", "password")) .Returns(client.Object); client.Setup(x => x.Get("organisation", "repository")) .ThrowsAsync(new NotFoundException("message", HttpStatusCode.NotFound)); var authenticator = new GitHubAuthenticator(new GitHubAuthenticatorConfig { Organisation = "organisation", Repository = "repository", BaseAddress = new Uri("https://www.example.com/") }, factory.Object); await Assert.ThrowsAsync <NotFoundException>(() => authenticator.Authenticate("username", "password", LfsPermission.Write, CancellationToken.None)); }
public async Task TestAuthenticatePublicRepositoryWriteUnsuccessful() { var factory = mockRepository.Create <IGitHubClientFactory>(); var client = mockRepository.Create <IRepositoriesClient>(); factory.Setup(x => x.CreateClient(new Uri("https://www.example.com/"), "username", "password")) .Returns(client.Object); client.Setup(x => x.Get("organisation", "repository")) .ReturnsAsync(new MockGitHubRepository(false, false, true)); var authenticator = new GitHubAuthenticator(new GitHubAuthenticatorConfig { Organisation = "organisation", Repository = "repository", BaseAddress = new Uri("https://www.example.com/") }, factory.Object); await Assert.ThrowsAsync <InvalidOperationException>(() => authenticator.Authenticate("username", "password", LfsPermission.Write, CancellationToken.None)); }