2013-04-30 00:04:14 +00:00
|
|
|
|
using System;
|
2013-07-24 06:26:10 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2013-04-30 00:04:14 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-06-28 00:04:52 +00:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-04-30 00:04:14 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class PathExtensionFixture : TestBase
|
|
|
|
|
{
|
|
|
|
|
|
2013-07-05 04:43:28 +00:00
|
|
|
|
private IAppFolderInfo GetIAppDirectoryInfo()
|
2013-04-30 00:04:14 +00:00
|
|
|
|
{
|
2013-07-05 04:43:28 +00:00
|
|
|
|
var fakeEnvironment = new Mock<IAppFolderInfo>();
|
2013-04-30 00:04:14 +00:00
|
|
|
|
|
2013-07-26 05:22:22 +00:00
|
|
|
|
fakeEnvironment.SetupGet(c => c.AppDataFolder).Returns(@"C:\NzbDrone\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
|
2013-07-26 05:22:22 +00:00
|
|
|
|
fakeEnvironment.SetupGet(c => c.TempFolder).Returns(@"C:\Temp\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
|
|
|
|
|
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")]
|
2013-07-26 05:22:22 +00:00
|
|
|
|
public void Clean_Path_Windows(string dirty, string clean)
|
2013-04-30 00:04:14 +00:00
|
|
|
|
{
|
2013-04-30 00:39:25 +00:00
|
|
|
|
WindowsOnly();
|
|
|
|
|
|
2013-07-26 05:22:22 +00:00
|
|
|
|
var result = dirty.CleanFilePath();
|
2013-04-30 00:04:14 +00:00
|
|
|
|
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")]
|
2013-07-26 05:22:22 +00:00
|
|
|
|
public void Clean_Path_Linux(string dirty, string clean)
|
2013-04-30 00:04:14 +00:00
|
|
|
|
{
|
2013-04-30 00:39:25 +00:00
|
|
|
|
LinuxOnly();
|
|
|
|
|
|
2013-07-26 05:22:22 +00:00
|
|
|
|
var result = dirty.CleanFilePath();
|
2013-04-30 00:04:14 +00:00
|
|
|
|
result.Should().Be(clean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void normalize_path_exception_empty()
|
|
|
|
|
{
|
2013-07-26 05:22:22 +00:00
|
|
|
|
Assert.Throws<ArgumentException>(() => "".CleanFilePath());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void normalize_path_exception_null()
|
|
|
|
|
{
|
|
|
|
|
string nullPath = null;
|
2013-07-26 05:22:22 +00:00
|
|
|
|
Assert.Throws<ArgumentException>(() => nullPath.CleanFilePath());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 06:26:10 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void get_actual_casing_for_none_existing_file_should_throw()
|
|
|
|
|
{
|
|
|
|
|
WindowsOnly();
|
|
|
|
|
Assert.Throws<DirectoryNotFoundException>(() => "C:\\InValidFolder\\invalidfile.exe".GetActualCasing());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-07-26 06:25:03 +00:00
|
|
|
|
public void get_actual_casing_should_return_actual_casing_for_local_file_in_windows()
|
2013-07-24 06:26:10 +00:00
|
|
|
|
{
|
|
|
|
|
var path = Process.GetCurrentProcess().MainModule.FileName;
|
|
|
|
|
path.ToUpper().GetActualCasing().Should().Be(path);
|
|
|
|
|
path.ToLower().GetActualCasing().Should().Be(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-07-26 06:25:03 +00:00
|
|
|
|
public void get_actual_casing_should_return_origibal_value_in_linux()
|
2013-07-24 06:26:10 +00:00
|
|
|
|
{
|
2013-07-26 06:25:03 +00:00
|
|
|
|
var path = Process.GetCurrentProcess().MainModule.FileName;
|
|
|
|
|
path.GetActualCasing().Should().Be(path);
|
|
|
|
|
path.GetActualCasing().Should().Be(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void get_actual_casing_should_return_actual_casing_for_local_dir_in_windows()
|
|
|
|
|
{
|
|
|
|
|
WindowsOnly();
|
2013-07-24 06:26:10 +00:00
|
|
|
|
var path = Directory.GetCurrentDirectory();
|
|
|
|
|
path.ToUpper().GetActualCasing().Should().Be(path);
|
|
|
|
|
path.ToLower().GetActualCasing().Should().Be(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-26 06:25:03 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void get_actual_casing_should_return_original_value_in_linux()
|
|
|
|
|
{
|
|
|
|
|
WindowsOnly();
|
|
|
|
|
var path = Directory.GetCurrentDirectory();
|
|
|
|
|
path.GetActualCasing().Should().Be(path);
|
|
|
|
|
path.GetActualCasing().Should().Be(path);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 06:26:10 +00:00
|
|
|
|
[Test]
|
|
|
|
|
[Explicit]
|
|
|
|
|
public void get_actual_casing_should_return_original_casing_for_shares()
|
|
|
|
|
{
|
|
|
|
|
var path = @"\\server\Pool\Apps";
|
|
|
|
|
path.GetActualCasing().Should().Be(path);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-30 00:04:14 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void AppDataDirectory_path_test()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Config_path_test()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Sanbox()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdatePackageFolder()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdateClientFolder()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdateClientExePath()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetUpdateLogFolder()
|
|
|
|
|
{
|
2013-07-26 05:41:38 +00:00
|
|
|
|
GetIAppDirectoryInfo().GetUpdateLogFolder().Should().BeEquivalentTo(@"C:\NzbDrone\UpdateLogs\".AsOsAgnostic());
|
2013-04-30 00:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|