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