1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 10:07:10 +00:00
Lidarr/NzbDrone.Common.Test/PathExtensionFixture.cs

200 lines
6.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);
}
[TestCase(@"C:\", @"C:\")]
[TestCase(@"C:\\", @"C:\")]
[TestCase(@"C:\Test", @"C:\Test\\")]
[TestCase(@"C:\\\\\Test", @"C:\Test\\")]
[TestCase(@"C:\Test\\\\", @"C:\Test\\")]
[TestCase(@"C:\Test", @"C:\Test\\")]
[TestCase(@"\\Server\pool", @"\\Server\pool")]
[TestCase(@"\\Server\pool\", @"\\Server\pool")]
[TestCase(@"\\Server\pool", @"\\Server\pool\")]
[TestCase(@"\\Server\pool\", @"\\Server\pool\")]
[TestCase(@"\\smallcheese\DRIVE_G\TV-C\Simspsons", @"\\smallcheese\DRIVE_G\TV-C\Simspsons")]
public void paths_should_be_equal(string first, string second)
{
first.AsOsAgnostic().PathEquals(second.AsOsAgnostic()).Should().BeTrue();
}
[TestCase(@"c:\", @"C:\")]
public void should_be_equal_windows_only(string first, string second)
{
WindowsOnly();
first.PathEquals(second.AsOsAgnostic()).Should().BeTrue();
}
[TestCase(@"C:\Test", @"C:\Test2\")]
[TestCase(@"C:\Test\Test", @"C:\TestTest\")]
public void paths_should_not_be_equal(string first, string second)
{
first.AsOsAgnostic().PathEquals(second.AsOsAgnostic()).Should().BeFalse();
}
2013-04-30 00:04:14 +00:00
[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_return_partially_fixed_result()
{
WindowsOnly();
"C:\\WINDOWS\\invalidfile.exe".GetActualCasing().Should().Be("C:\\Windows\\invalidfile.exe");
}
[Test]
public void get_actual_casing_for_none_existing_folder_return_partially_fixed_result()
{
2013-07-26 06:32:41 +00:00
WindowsOnly();
"C:\\WINDOWS\\SYSTEM32\\FAKEFOLDER\\invalidfile.exe".GetActualCasing().Should().Be("C:\\Windows\\System32\\FAKEFOLDER\\invalidfile.exe");
}
[Test]
public void get_actual_casing_should_return_actual_casing_for_local_file_in_windows()
{
WindowsOnly();
2013-07-26 06:25:03 +00:00
var path = Process.GetCurrentProcess().MainModule.FileName;
path.ToUpper().GetActualCasing().Should().Be(path);
path.ToLower().GetActualCasing().Should().Be(path);
2013-07-26 06:25:03 +00:00
}
2013-07-26 06:25:03 +00:00
[Test]
public void get_actual_casing_should_return_actual_casing_for_local_dir_in_windows()
{
WindowsOnly();
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()
{
2013-07-26 06:32:41 +00:00
LinuxOnly();
2013-07-26 06:25:03 +00:00
var path = Directory.GetCurrentDirectory();
path.GetActualCasing().Should().Be(path);
path.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
}
}
}