2020-05-12 15:35:59 +01:00
|
|
|
using NUnit.Framework;
|
|
|
|
using SpotifyAPI.Web.Http;
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class SpotifyClientConfigTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void CreateDefault_CorrectDefaults()
|
|
|
|
{
|
|
|
|
var defaultConfig = SpotifyClientConfig.CreateDefault();
|
|
|
|
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That(defaultConfig.DefaultPaginator, Is.InstanceOf(typeof(SimplePaginator)));
|
|
|
|
Assert.That(defaultConfig.HTTPClient, Is.InstanceOf(typeof(NetHttpClient)));
|
|
|
|
Assert.That(defaultConfig.JSONSerializer, Is.InstanceOf(typeof(NewtonsoftJSONSerializer)));
|
|
|
|
Assert.That(SpotifyUrls.APIV1, Is.EqualTo(defaultConfig.BaseAddress));
|
|
|
|
Assert.That(null, Is.EqualTo(defaultConfig.Authenticator));
|
|
|
|
Assert.That(null, Is.EqualTo(defaultConfig.HTTPLogger));
|
|
|
|
Assert.That(null, Is.EqualTo(defaultConfig.RetryHandler));
|
2020-05-12 15:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CreateDefault_CorrectDefaultsWithToken()
|
|
|
|
{
|
|
|
|
var token = "my-token";
|
|
|
|
var tokenType = "Bearer";
|
|
|
|
|
|
|
|
var defaultConfig = SpotifyClientConfig.CreateDefault(token, tokenType);
|
|
|
|
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That(defaultConfig.DefaultPaginator, Is.InstanceOf(typeof(SimplePaginator)));
|
|
|
|
Assert.That(defaultConfig.HTTPClient, Is.InstanceOf(typeof(NetHttpClient)));
|
|
|
|
Assert.That(defaultConfig.JSONSerializer, Is.InstanceOf(typeof(NewtonsoftJSONSerializer)));
|
|
|
|
Assert.That(SpotifyUrls.APIV1, Is.EqualTo(defaultConfig.BaseAddress));
|
|
|
|
Assert.That(null, Is.EqualTo(defaultConfig.HTTPLogger));
|
|
|
|
Assert.That(null, Is.EqualTo(defaultConfig.RetryHandler));
|
2020-05-12 15:35:59 +01:00
|
|
|
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That(defaultConfig.Authenticator, Is.InstanceOf(typeof(TokenAuthenticator)));
|
2020-05-12 15:35:59 +01:00
|
|
|
|
2020-05-13 22:49:54 +01:00
|
|
|
var tokenHeaderAuth = defaultConfig.Authenticator as TokenAuthenticator;
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That(token, Is.EqualTo(tokenHeaderAuth.Token));
|
|
|
|
Assert.That(tokenType, Is.EqualTo(tokenHeaderAuth.TokenType));
|
2020-05-12 15:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void WithToken_CreatesNewInstance()
|
|
|
|
{
|
|
|
|
var token = "my-token";
|
|
|
|
var defaultConfig = SpotifyClientConfig.CreateDefault();
|
|
|
|
var tokenConfig = defaultConfig.WithToken(token);
|
|
|
|
|
2024-02-10 10:41:47 +00:00
|
|
|
Assert.That(token, Is.EqualTo((tokenConfig.Authenticator as TokenAuthenticator).Token));
|
|
|
|
Assert.That(defaultConfig, Is.Not.EqualTo(tokenConfig));
|
|
|
|
Assert.That(null, Is.EqualTo(defaultConfig.Authenticator));
|
2020-05-12 15:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|