2013-02-13 19:57:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-01-20 23:01:42 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-07-18 21:23:38 +00:00
|
|
|
|
using Xunit;
|
2014-08-24 19:23:18 +00:00
|
|
|
|
using TMDbLib.Client;
|
2015-05-30 15:21:23 +00:00
|
|
|
|
using TMDbLib.Objects.Exceptions;
|
2013-02-13 16:25:53 +00:00
|
|
|
|
using TMDbLib.Objects.General;
|
2016-01-18 20:22:57 +00:00
|
|
|
|
using TMDbLibTests.Helpers;
|
2016-05-22 12:10:30 +00:00
|
|
|
|
using TMDbLibTests.JsonHelpers;
|
2013-02-13 16:25:53 +00:00
|
|
|
|
|
|
|
|
|
namespace TMDbLibTests
|
|
|
|
|
{
|
2016-05-22 12:10:30 +00:00
|
|
|
|
public class ClientTests : TestBase
|
2013-02-13 16:25:53 +00:00
|
|
|
|
{
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2013-02-13 16:25:53 +00:00
|
|
|
|
public void GetConfigTest()
|
|
|
|
|
{
|
2016-07-18 21:26:27 +00:00
|
|
|
|
Assert.False(Config.Client.HasConfig);
|
2018-01-21 12:38:01 +00:00
|
|
|
|
Config.Client.GetConfigAsync().Sync();
|
2016-07-18 21:26:27 +00:00
|
|
|
|
Assert.True(Config.Client.HasConfig);
|
2013-02-13 16:25:53 +00:00
|
|
|
|
|
2016-07-18 21:26:27 +00:00
|
|
|
|
Assert.NotNull(Config.Client.Config);
|
2013-02-13 16:25:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2013-02-13 19:57:04 +00:00
|
|
|
|
public void GetConfigSslTest()
|
|
|
|
|
{
|
2016-07-20 20:14:41 +00:00
|
|
|
|
TestConfig config = new TestConfig(true);
|
2013-02-13 19:57:04 +00:00
|
|
|
|
|
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);
|
2013-02-13 19:57:04 +00:00
|
|
|
|
|
2016-07-20 20:14:41 +00:00
|
|
|
|
Assert.NotNull(config.Client.Config);
|
2013-02-13 19:57:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2013-02-13 19:57:04 +00:00
|
|
|
|
public void GetConfigFailTest()
|
|
|
|
|
{
|
2016-07-18 21:26:27 +00:00
|
|
|
|
Assert.Throws<InvalidOperationException>(() => Config.Client.Config);
|
2013-02-13 19:57:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2013-02-13 16:25:53 +00:00
|
|
|
|
public void SetConfigTest()
|
|
|
|
|
{
|
|
|
|
|
TMDbConfig config = new TMDbConfig();
|
|
|
|
|
config.ChangeKeys = new List<string>();
|
|
|
|
|
config.ChangeKeys.Add("a");
|
|
|
|
|
config.Images = new ConfigImageTypes();
|
|
|
|
|
config.Images.BaseUrl = " ..";
|
|
|
|
|
|
2016-07-18 21:26:27 +00:00
|
|
|
|
Assert.False(Config.Client.HasConfig);
|
|
|
|
|
Config.Client.SetConfig(config);
|
|
|
|
|
Assert.True(Config.Client.HasConfig);
|
2013-02-13 16:25:53 +00:00
|
|
|
|
|
2016-07-18 21:26:27 +00:00
|
|
|
|
Assert.Same(config, Config.Client.Config);
|
2013-02-13 16:25:53 +00:00
|
|
|
|
}
|
2014-08-24 19:23:18 +00:00
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2014-08-24 19:23:18 +00:00
|
|
|
|
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();
|
2014-08-24 19:23:18 +00:00
|
|
|
|
|
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();
|
2014-08-24 19:23:18 +00:00
|
|
|
|
|
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();
|
2014-08-24 19:23:18 +00:00
|
|
|
|
|
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();
|
2014-08-24 19:23:18 +00:00
|
|
|
|
}
|
2015-05-30 15:21:23 +00:00
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2016-01-18 20:22:57 +00:00
|
|
|
|
public void ClientSetBadMaxRetryValue()
|
2016-05-22 12:10:30 +00:00
|
|
|
|
{
|
2016-01-18 20:22:57 +00:00
|
|
|
|
TMDbClient client = new TMDbClient(TestConfig.APIKey);
|
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => client.MaxRetryCount = -1);
|
2016-01-18 20:22:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
[Fact]
|
2015-05-30 15:21:23 +00:00
|
|
|
|
public void ClientRateLimitTest()
|
|
|
|
|
{
|
2016-01-18 20:22:57 +00:00
|
|
|
|
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);
|
2016-01-18 20:22:57 +00:00
|
|
|
|
client.MaxRetryCount = 0;
|
2015-05-30 15:21:23 +00:00
|
|
|
|
|
2016-07-18 21:23:38 +00:00
|
|
|
|
Assert.Throws<RequestLimitExceededException>(() =>
|
2015-05-30 15:21:23 +00:00
|
|
|
|
{
|
2016-07-18 21:23:38 +00:00
|
|
|
|
try
|
2015-05-31 13:35:19 +00:00
|
|
|
|
{
|
2016-07-18 21:23:38 +00:00
|
|
|
|
Parallel.For(0, 100, i =>
|
2016-01-20 23:01:42 +00:00
|
|
|
|
{
|
2016-07-18 21:23:38 +00:00
|
|
|
|
client.GetMovieAsync(id).Sync();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (AggregateException ex)
|
|
|
|
|
{
|
|
|
|
|
// Unpack the InnerException
|
|
|
|
|
throw ex.InnerException;
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-05-30 15:21:23 +00:00
|
|
|
|
}
|
2013-02-13 16:25:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|