TMDbLib/TMDbLibTests/ClientTests.cs

109 lines
3.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using TMDbLib.Client;
2015-05-30 15:21:23 +00:00
using TMDbLib.Objects.Exceptions;
using TMDbLib.Objects.General;
using TMDbLibTests.Helpers;
using TMDbLibTests.JsonHelpers;
namespace TMDbLibTests
{
public class ClientTests : TestBase
{
[Fact]
public void GetConfigTest()
{
Assert.False(Config.Client.HasConfig);
2018-01-21 12:38:01 +00:00
Config.Client.GetConfigAsync().Sync();
Assert.True(Config.Client.HasConfig);
Assert.NotNull(Config.Client.Config);
}
[Fact]
public void GetConfigSslTest()
{
2016-07-20 20:14:41 +00:00
TestConfig config = new TestConfig(true);
2016-07-20 20:14:41 +00:00
Assert.False(config.Client.HasConfig);
2018-01-21 12:38:01 +00:00
config.Client.GetConfigAsync().Sync();
2016-07-20 20:14:41 +00:00
Assert.True(config.Client.HasConfig);
2016-07-20 20:14:41 +00:00
Assert.NotNull(config.Client.Config);
}
[Fact]
public void GetConfigFailTest()
{
Assert.Throws<InvalidOperationException>(() => Config.Client.Config);
}
[Fact]
public void SetConfigTest()
{
TMDbConfig config = new TMDbConfig();
config.ChangeKeys = new List<string>();
config.ChangeKeys.Add("a");
config.Images = new ConfigImageTypes();
config.Images.BaseUrl = " ..";
Assert.False(Config.Client.HasConfig);
Config.Client.SetConfig(config);
Assert.True(Config.Client.HasConfig);
Assert.Same(config, Config.Client.Config);
}
[Fact]
public void ClientConstructorUrlTest()
{
2016-08-09 21:46:18 +00:00
TMDbClient clientA = new TMDbClient(TestConfig.APIKey, false, "http://api.themoviedb.org") { MaxRetryCount = 2 };
2018-01-21 12:38:01 +00:00
clientA.GetConfigAsync().Sync();
2016-08-09 21:46:18 +00:00
TMDbClient clientB = new TMDbClient(TestConfig.APIKey, true, "http://api.themoviedb.org") { MaxRetryCount = 2 };
2018-01-21 12:38:01 +00:00
clientB.GetConfigAsync().Sync();
2016-08-09 21:46:18 +00:00
TMDbClient clientC = new TMDbClient(TestConfig.APIKey, false, "https://api.themoviedb.org") { MaxRetryCount = 2 };
2018-01-21 12:38:01 +00:00
clientC.GetConfigAsync().Sync();
2016-08-09 21:46:18 +00:00
TMDbClient clientD = new TMDbClient(TestConfig.APIKey, true, "https://api.themoviedb.org") { MaxRetryCount = 2 };
2018-01-21 12:38:01 +00:00
clientD.GetConfigAsync().Sync();
}
2015-05-30 15:21:23 +00:00
[Fact]
public void ClientSetBadMaxRetryValue()
{
TMDbClient client = new TMDbClient(TestConfig.APIKey);
Assert.Throws<ArgumentOutOfRangeException>(() => client.MaxRetryCount = -1);
}
[Fact]
2015-05-30 15:21:23 +00:00
public void ClientRateLimitTest()
{
const int id = IdHelper.AGoodDayToDieHard;
2015-05-30 21:57:31 +00:00
2015-05-30 15:21:23 +00:00
TMDbClient client = new TMDbClient(TestConfig.APIKey);
client.MaxRetryCount = 0;
2015-05-30 15:21:23 +00:00
Assert.Throws<RequestLimitExceededException>(() =>
2015-05-30 15:21:23 +00:00
{
try
{
Parallel.For(0, 100, i =>
{
client.GetMovieAsync(id).Sync();
});
}
catch (AggregateException ex)
{
// Unpack the InnerException
throw ex.InnerException;
}
});
2015-05-30 15:21:23 +00:00
}
}
}