Radarr/NzbDrone.Common.Test/PathExtensionFixture.cs

152 lines
4.9 KiB
C#
Raw Normal View History

2013-04-30 00:04:14 +00:00
using System;
using System.Diagnostics;
using System.IO;
2013-04-30 00:04:14 +00:00
using FluentAssertions;
using Moq;
using NUnit.Framework;
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
{
private IAppFolderInfo GetIAppDirectoryInfo()
2013-04-30 00:04:14 +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);
}
[Test]
public void get_actual_casing_for_none_existing_file_should_throw()
{
WindowsOnly();
Assert.Throws<DirectoryNotFoundException>(() => "C:\\InValidFolder\\invalidfile.exe".GetActualCasing());
}
[Test]
public void get_actual_casing_should_return_actual_casing_for_local_file()
{
var path = Process.GetCurrentProcess().MainModule.FileName;
path.ToUpper().GetActualCasing().Should().Be(path);
path.ToLower().GetActualCasing().Should().Be(path);
}
[Test]
public void get_actual_casing_should_return_actual_casing_for_local_dir()
{
var path = Directory.GetCurrentDirectory();
path.ToUpper().GetActualCasing().Should().Be(path);
path.ToLower().GetActualCasing().Should().Be(path);
}
[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
}
}
}