mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-24 16:53:54 +00:00
Added ParentUriString to get the parent site URI from any URI.
This commit is contained in:
parent
95cdc4b78c
commit
f3f2691b4d
2 changed files with 85 additions and 1 deletions
|
@ -80,5 +80,89 @@ namespace NzbDrone.Core.Test
|
|||
Console.WriteLine(dateTime.DayOfWeek);
|
||||
dateTime.ToBestDateString().Should().Be(dateTime.ToShortDateString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParentUriString_should_return_self_if_already_parent()
|
||||
{
|
||||
//Setup
|
||||
var url = "http://www.nzbdrone.com";
|
||||
var uri = new Uri(url);
|
||||
|
||||
//Act
|
||||
var result = uri.ParentUriString();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be(url);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParentUriString_should_return_parent_url_when_path_is_passed()
|
||||
{
|
||||
//Setup
|
||||
var url = "http://www.nzbdrone.com/test/";
|
||||
var uri = new Uri(url);
|
||||
|
||||
//Act
|
||||
var result = uri.ParentUriString();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be("http://www.nzbdrone.com");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParentUriString_should_return_parent_url_when_multiple_paths_are_passed()
|
||||
{
|
||||
//Setup
|
||||
var url = "http://www.nzbdrone.com/test/test2";
|
||||
var uri = new Uri(url);
|
||||
|
||||
//Act
|
||||
var result = uri.ParentUriString();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be("http://www.nzbdrone.com");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParentUriString_should_return_parent_url_when_url_with_query_string_is_passed()
|
||||
{
|
||||
//Setup
|
||||
var url = "http://www.nzbdrone.com/test.aspx?test=10";
|
||||
var uri = new Uri(url);
|
||||
|
||||
//Act
|
||||
var result = uri.ParentUriString();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be("http://www.nzbdrone.com");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParentUriString_should_return_parent_url_when_url_with_path_and_query_strings_is_passed()
|
||||
{
|
||||
//Setup
|
||||
var url = "http://www.nzbdrone.com/tester/test.aspx?test=10";
|
||||
var uri = new Uri(url);
|
||||
|
||||
//Act
|
||||
var result = uri.ParentUriString();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be("http://www.nzbdrone.com");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParentUriString_should_return_parent_url_when_url_with_query_strings_is_passed()
|
||||
{
|
||||
//Setup
|
||||
var url = "http://www.nzbdrone.com/test.aspx?test=10&test2=5";
|
||||
var uri = new Uri(url);
|
||||
|
||||
//Act
|
||||
var result = uri.ParentUriString();
|
||||
|
||||
//Resolve
|
||||
result.Should().Be("http://www.nzbdrone.com");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace NzbDrone.Core
|
|||
|
||||
public static string ParentUriString(this Uri uri)
|
||||
{
|
||||
return uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - String.Join("", uri.Segments).Length);
|
||||
return uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - String.Join("", uri.Segments).Length - uri.Query.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue