using System; using NSubstitute; using Octokit.Internal; using Xunit; namespace Octokit.Tests { public class TokenAuthenticatorTests { public class TheAuthenticateMethod { [Fact] public void SetsRequestHeaderForToken() { var authenticator = new TokenAuthenticator(); var request = new Request(); authenticator.Authenticate(request, new Credentials("abcda1234a")); Assert.Contains("Authorization", request.Headers.Keys); Assert.Equal("Token abcda1234a", request.Headers["Authorization"]); } [Fact] public void EnsuresCredentialsAreOfTheRightType() { var authenticator = new TokenAuthenticator(); var request = new Request(); Assert.Throws(() => authenticator.Authenticate(request, new Credentials("login", "password"))); } [Fact] public void EnsuresArgumentsNotNull() { var authenticator = new TokenAuthenticator(); Assert.Throws(() => authenticator.Authenticate(null, Credentials.Anonymous)); Assert.Throws(() => authenticator.Authenticate(Substitute.For(), null)); } } } }