Exemple #1
0
        public async Task TestAuthenticatePrivateRepositoryReadWriteSuccessful()
        {
            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, true, true));

            var authenticator = new GitHubAuthenticator(new GitHubAuthenticatorConfig
            {
                Organisation = "organisation",
                Repository   = "repository",
                BaseAddress  = new Uri("https://www.example.com/")
            }, factory.Object);

            await authenticator.Authenticate("username", "password", LfsPermission.Read, CancellationToken.None);

            await authenticator.Authenticate("username", "password", LfsPermission.Write, CancellationToken.None);
        }
Exemple #2
0
        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));
        }