2013-04-30 02:04:14 +02:00
|
|
|
|
using System;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-06-28 02:04:52 +02:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-04-30 02:04:14 +02:00
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
using NzbDrone.Test.Common.Categories;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class PathExtensionFixture : TestBase
|
|
|
|
|
{
|
|
|
|
|
|
2013-06-28 02:04:52 +02:00
|
|
|
|
private IAppDirectoryInfo GetIAppDirectoryInfo()
|
2013-04-30 02:04:14 +02:00
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
var fakeEnvironment = new Mock<IAppDirectoryInfo>();
|
2013-04-30 02:04:14 +02:00
|
|
|
|
|
|
|
|
|
fakeEnvironment.SetupGet(c => c.WorkingDirectory).Returns(@"C:\NzbDrone\");
|
|
|
|
|
|
|
|
|
|
fakeEnvironment.SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\");
|
|
|
|
|
|
|
|
|
|
return fakeEnvironment.Object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(@"c:\test\", @"c:\test")]
|
|
|
|
|
[TestCase(@"c:\\test\\", @"c:\test")]
|
|
|
|
|
[TestCase(@"C:\\Test\\", @"C:\Test")]
|
|
|
|
|
[TestCase(@"C:\\Test\\Test\", @"C:\Test\Test")]
|
|
|
|
|
[TestCase(@"\\Testserver\Test\", @"\\Testserver\Test")]
|
|
|
|
|
[TestCase(@"\\Testserver\\Test\", @"\\Testserver\Test")]
|
|
|
|
|
[TestCase(@"\\Testserver\Test\file.ext", @"\\Testserver\Test\file.ext")]
|
|
|
|
|
[TestCase(@"\\Testserver\Test\file.ext\\", @"\\Testserver\Test\file.ext")]
|
|
|
|
|
[TestCase(@"\\Testserver\Test\file.ext \\", @"\\Testserver\Test\file.ext")]
|
|
|
|
|
public void Normalize_Path_Windows(string dirty, string clean)
|
|
|
|
|
{
|
2013-04-30 02:39:25 +02:00
|
|
|
|
WindowsOnly();
|
|
|
|
|
|
2013-04-30 02:04:14 +02:00
|
|
|
|
var result = dirty.CleanPath();
|
|
|
|
|
result.Should().Be(clean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(@"/test/", @"/test")]
|
|
|
|
|
[TestCase(@"//test/", @"/test")]
|
|
|
|
|
[TestCase(@"//test//", @"/test")]
|
|
|
|
|
[TestCase(@"//test// ", @"/test")]
|
|
|
|
|
[TestCase(@"//test//other// ", @"/test/other")]
|
|
|
|
|
[TestCase(@"//test//other//file.ext ", @"/test/other/file.ext")]
|
|
|
|
|
[TestCase(@"//CAPITAL//lower// ", @"/CAPITAL/lower")]
|
|
|
|
|
public void Normalize_Path_Linux(string dirty, string clean)
|
|
|
|
|
{
|
2013-04-30 02:39:25 +02:00
|
|
|
|
LinuxOnly();
|
|
|
|
|
|
2013-04-30 02:04:14 +02:00
|
|
|
|
var result = dirty.CleanPath();
|
|
|
|
|
result.Should().Be(clean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void normalize_path_exception_empty()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<ArgumentException>(() => "".CleanPath());
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void normalize_path_exception_null()
|
|
|
|
|
{
|
|
|
|
|
string nullPath = null;
|
|
|
|
|
Assert.Throws<ArgumentException>(() => nullPath.CleanPath());
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AppDataDirectory_path_test()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Config_path_test()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Sanbox()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdatePackageFolder()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdateClientFolder()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdateClientExePath()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdateLogFolder()
|
|
|
|
|
{
|
2013-06-28 02:04:52 +02:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateLogFolder().Should().BeEquivalentTo(@"C:\NzbDrone\UpdateLogs\");
|
2013-04-30 02:04:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|