mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
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<InvalidOperationException>(() =>
|
|
authenticator.Authenticate(request, new Credentials("login", "password")));
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsuresArgumentsNotNull()
|
|
{
|
|
var authenticator = new TokenAuthenticator();
|
|
Assert.Throws<ArgumentNullException>(() => authenticator.Authenticate(null, Credentials.Anonymous));
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
authenticator.Authenticate(Substitute.For<IRequest>(), null));
|
|
}
|
|
}
|
|
}
|
|
}
|