sonarr-repo-only/NzbDrone.Common.Test/PathExtensionFixture.cs

152 lines
4.8 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()
{
GetIAppDirectoryInfo().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\");
2013-04-30 00:04:14 +00:00
}
[Test]
public void Config_path_test()
{
GetIAppDirectoryInfo().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml");
2013-04-30 00:04:14 +00:00
}
[Test]
public void Sanbox()
{
GetIAppDirectoryInfo().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\");
2013-04-30 00:04:14 +00:00
}
[Test]
public void GetUpdatePackageFolder()
{
GetIAppDirectoryInfo().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\");
2013-04-30 00:04:14 +00:00
}
[Test]
public void GetUpdateClientFolder()
{
GetIAppDirectoryInfo().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\");
2013-04-30 00:04:14 +00:00
}
[Test]
public void GetUpdateClientExePath()
{
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe");
2013-04-30 00:04:14 +00:00
}
[Test]
public void GetUpdateLogFolder()
{
GetIAppDirectoryInfo().GetUpdateLogFolder().Should().BeEquivalentTo(@"C:\NzbDrone\UpdateLogs\");
2013-04-30 00:04:14 +00:00
}
}
}