2020-03-09 19:47:39 +00:00
|
|
|
using System;
|
2018-03-25 18:39:19 +01:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
2018-08-24 13:10:13 +01:00
|
|
|
namespace SpotifyAPI.Web.Tests
|
2018-03-25 18:39:19 +01:00
|
|
|
{
|
2020-03-09 19:47:39 +00:00
|
|
|
[TestFixture]
|
|
|
|
public class ProxyConfigTest
|
|
|
|
{
|
|
|
|
#region GetUri
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_HostNameWithScheme()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig { Host = "https://test-host.com" };
|
|
|
|
CheckUri(config.GetUri(), "https", "test-host.com", 80);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_HostNameWithoutScheme()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig { Host = "test-host.com" };
|
|
|
|
CheckUri(config.GetUri(), "http", "test-host.com", 80);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_HostNameWithSchemeAndPort()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig
|
|
|
|
{
|
|
|
|
Host = "https://test-host.com",
|
|
|
|
Port = 8080
|
|
|
|
};
|
|
|
|
CheckUri(config.GetUri(), "https", "test-host.com", 8080);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_HostAddressWithScheme()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig { Host = "https://192.168.0.1" };
|
|
|
|
CheckUri(config.GetUri(), "https", "192.168.0.1", 80);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_HostAddressWithoutScheme()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig { Host = "192.168.0.1" };
|
|
|
|
CheckUri(config.GetUri(), "http", "192.168.0.1", 80);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_HostAddressWithSchemeAndPort()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig
|
|
|
|
{
|
|
|
|
Host = "https://192.168.0.1",
|
|
|
|
Port = 8080
|
|
|
|
};
|
|
|
|
CheckUri(config.GetUri(), "https", "192.168.0.1", 8080);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_NullHost()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig { Host = null };
|
|
|
|
Assert.Throws<ArgumentNullException>(() => config.GetUri());
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_EmptyHost()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig { Host = string.Empty };
|
|
|
|
Assert.Throws<UriFormatException>(() => config.GetUri());
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void GetUri_NegativePort()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig
|
|
|
|
{
|
|
|
|
Host = "test-host.com",
|
|
|
|
Port = -10
|
|
|
|
};
|
|
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => config.GetUri());
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
#endregion GetUri
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
[Test]
|
|
|
|
public void Set_Null()
|
|
|
|
{
|
|
|
|
ProxyConfig config = new ProxyConfig
|
|
|
|
{
|
|
|
|
Host = "https://test-host.com",
|
|
|
|
Port = 1234,
|
|
|
|
Username = "admin",
|
|
|
|
Password = "password",
|
|
|
|
BypassProxyOnLocal = true
|
|
|
|
};
|
|
|
|
config.Set(null);
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
Assert.NotNull(config);
|
|
|
|
Assert.Null(config.Host);
|
|
|
|
Assert.AreEqual(80, config.Port);
|
|
|
|
Assert.Null(config.Username);
|
|
|
|
Assert.Null(config.Password);
|
|
|
|
Assert.False(config.BypassProxyOnLocal);
|
|
|
|
}
|
2018-03-25 18:39:19 +01:00
|
|
|
|
2020-03-09 19:47:39 +00:00
|
|
|
private static void CheckUri(Uri uri, string expectedScheme, string expectedHost, int expectedPort)
|
|
|
|
{
|
|
|
|
Assert.AreEqual(expectedScheme, uri.Scheme);
|
|
|
|
Assert.AreEqual(expectedHost, uri.Host);
|
|
|
|
Assert.AreEqual(expectedPort, uri.Port);
|
2018-03-25 18:39:19 +01:00
|
|
|
}
|
2020-03-09 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|