mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-21 06:35:11 +00:00
The storage mechanism for credentials is very likely to be an async data store. So might as well play it safe and make it awaitable.
84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using NSubstitute;
|
|
using Octokit.Internal;
|
|
using Xunit;
|
|
|
|
namespace Octokit.Tests
|
|
{
|
|
public class GitHubClientTests
|
|
{
|
|
public class TheConstructor
|
|
{
|
|
[Fact]
|
|
public void CreatesAnonymousClientByDefault()
|
|
{
|
|
var client = new GitHubClient("Test Runner User Agent");
|
|
|
|
Assert.Equal(AuthenticationType.Anonymous, client.Credentials.AuthenticationType);
|
|
}
|
|
|
|
[Fact]
|
|
public void CanCreateBasicAuthClient()
|
|
{
|
|
var client = new GitHubClient("Test Runner") { Credentials = new Credentials("tclem", "pwd") };
|
|
|
|
Assert.Equal(AuthenticationType.Basic, client.Credentials.AuthenticationType);
|
|
}
|
|
|
|
[Fact]
|
|
public void CanCreateOauthClient()
|
|
{
|
|
var client = new GitHubClient("Test Runner") { Credentials = new Credentials("token") };
|
|
|
|
Assert.Equal(AuthenticationType.Oauth, client.Credentials.AuthenticationType);
|
|
}
|
|
}
|
|
|
|
public class TheBaseAddressProperty
|
|
{
|
|
[Fact]
|
|
public void IsSetToGitHubApiV3()
|
|
{
|
|
var client = new GitHubClient("Test Runner");
|
|
|
|
Assert.Equal(new Uri("https://api.github.com"), client.BaseAddress);
|
|
}
|
|
}
|
|
|
|
public class TheCredentialsProperty
|
|
{
|
|
[Fact]
|
|
public void DefaultsToAnonymous()
|
|
{
|
|
var client = new GitHubClient("Test Runner");
|
|
Assert.Same(Credentials.Anonymous, client.Credentials);
|
|
}
|
|
|
|
[Fact]
|
|
public void WhenSetCreatesInMemoryStoreThatReturnsSpecifiedCredentials()
|
|
{
|
|
var credentials = new Credentials("Peter", "Griffin");
|
|
var client = new GitHubClient("Test Runner", Substitute.For<ICredentialStore>())
|
|
{
|
|
Credentials = credentials
|
|
};
|
|
|
|
Assert.IsType<InMemoryCredentialStore>(client.Connection.CredentialStore);
|
|
Assert.Same(credentials, client.Credentials);
|
|
}
|
|
|
|
[Fact]
|
|
public void IsRetrievedFromCredentialStore()
|
|
{
|
|
var credentialStore = Substitute.For<ICredentialStore>();
|
|
credentialStore.GetCredentials().Returns(Task.Factory.StartNew(() => new Credentials("foo", "bar")));
|
|
var client = new GitHubClient("Test Runner", credentialStore);
|
|
|
|
Assert.Equal("foo", client.Credentials.Login);
|
|
Assert.Equal("bar", client.Credentials.Password);
|
|
}
|
|
}
|
|
}
|
|
}
|