Spotify.NET/SpotifyAPI.Web.Tests/Clients/SpotifyClientConfigTest.cs

60 lines
2.1 KiB
C#
Raw Normal View History

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);
Assert.IsInstanceOf(typeof(TextJsonSerializer), 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);
Assert.IsInstanceOf(typeof(TextJsonSerializer), 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);
Assert.IsInstanceOf(typeof(TokenAuthenticator), defaultConfig.Authenticator);
2020-05-12 15:35:59 +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);
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);
}
}
}