mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
Moved source code under src folder - massive change
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
||||
namespace NzbDrone.Common.Test.CacheTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CachedFixture
|
||||
{
|
||||
private Cached<string> _cachedString = new Cached<string>();
|
||||
private Worker _worker;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_cachedString = new Cached<string>();
|
||||
_worker = new Worker();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_function_once()
|
||||
{
|
||||
_cachedString.Get("Test", _worker.GetString);
|
||||
_cachedString.Get("Test", _worker.GetString);
|
||||
|
||||
_worker.HitCount.Should().Be(1);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void multiple_calls_should_return_same_result()
|
||||
{
|
||||
var first = _cachedString.Get("Test", _worker.GetString);
|
||||
var second = _cachedString.Get("Test", _worker.GetString);
|
||||
|
||||
first.Should().Be(second);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_update_key()
|
||||
{
|
||||
_cachedString.Set("Key", "Old");
|
||||
_cachedString.Set("Key", "New");
|
||||
|
||||
_cachedString.Find("Key").Should().Be("New");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_remove_key()
|
||||
{
|
||||
_cachedString.Set("Key", "Value");
|
||||
|
||||
_cachedString.Remove("Key");
|
||||
|
||||
_cachedString.Find("Key").Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_remove_non_existing_key()
|
||||
{
|
||||
_cachedString.Remove("Key");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_store_null()
|
||||
{
|
||||
int hitCount = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
_cachedString.Get("key", () =>
|
||||
{
|
||||
hitCount++;
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
hitCount.Should().Be(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_honor_ttl()
|
||||
{
|
||||
int hitCount = 0;
|
||||
_cachedString = new Cached<string>();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
_cachedString.Get("key", () =>
|
||||
{
|
||||
hitCount++;
|
||||
return null;
|
||||
}, TimeSpan.FromMilliseconds(300));
|
||||
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
hitCount.Should().BeInRange(3, 6);
|
||||
}
|
||||
}
|
||||
|
||||
public class Worker
|
||||
{
|
||||
public int HitCount { get; private set; }
|
||||
|
||||
public string GetString()
|
||||
{
|
||||
HitCount++;
|
||||
return "Hit count is " + HitCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.CacheTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CachedManagerFixture : TestBase<ICacheManger>
|
||||
{
|
||||
[Test]
|
||||
public void should_return_proper_type_of_cache()
|
||||
{
|
||||
var result = Subject.GetCache<DateTime>(typeof(string));
|
||||
|
||||
result.Should().BeOfType<Cached<DateTime>>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void multiple_calls_should_get_the_same_cache()
|
||||
{
|
||||
var result1 = Subject.GetCache<DateTime>(typeof(string));
|
||||
var result2 = Subject.GetCache<DateTime>(typeof(string));
|
||||
|
||||
result1.Should().BeSameAs(result2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class ConfigFileProviderTest : TestBase<ConfigFileProvider>
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
WithTempAsAppPath();
|
||||
|
||||
var configFile = Mocker.Resolve<IAppFolderInfo>().GetConfigPath();
|
||||
|
||||
if (File.Exists(configFile))
|
||||
File.Delete(configFile);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValue_Success()
|
||||
{
|
||||
const string key = "Port";
|
||||
const string value = "8989";
|
||||
|
||||
|
||||
var result = Subject.GetValue(key, value);
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetInt_Success()
|
||||
{
|
||||
const string key = "Port";
|
||||
const int value = 8989;
|
||||
|
||||
|
||||
var result = Subject.GetValueInt(key, value);
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBool_Success()
|
||||
{
|
||||
const string key = "LaunchBrowser";
|
||||
const bool value = true;
|
||||
|
||||
|
||||
var result = Subject.GetValueBoolean(key, value);
|
||||
|
||||
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLaunchBrowser_Success()
|
||||
{
|
||||
|
||||
var result = Subject.LaunchBrowser;
|
||||
|
||||
|
||||
result.Should().Be(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPort_Success()
|
||||
{
|
||||
const int value = 8989;
|
||||
|
||||
|
||||
var result = Subject.Port;
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetValue_bool()
|
||||
{
|
||||
const string key = "LaunchBrowser";
|
||||
const bool value = false;
|
||||
|
||||
|
||||
Subject.SetValue(key, value);
|
||||
|
||||
|
||||
var result = Subject.LaunchBrowser;
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SetValue_int()
|
||||
{
|
||||
const string key = "Port";
|
||||
const int value = 12345;
|
||||
|
||||
|
||||
Subject.SetValue(key, value);
|
||||
|
||||
|
||||
var result = Subject.Port;
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetValue_New_Key()
|
||||
{
|
||||
const string key = "Hello";
|
||||
const string value = "World";
|
||||
|
||||
|
||||
var result = Subject.GetValue(key, value);
|
||||
|
||||
|
||||
result.Should().Be(value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAuthenticationType_No_Existing_Value()
|
||||
{
|
||||
var result = Subject.AuthenticationEnabled;
|
||||
|
||||
result.Should().Be(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaveDictionary_should_save_proper_value()
|
||||
{
|
||||
int port = 20555;
|
||||
|
||||
var dic = Subject.GetConfigDictionary();
|
||||
dic["Port"] = 20555;
|
||||
|
||||
Subject.SaveConfigDictionary(dic);
|
||||
|
||||
|
||||
Subject.Port.Should().Be(port);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.DiskProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class DiskProviderFixture : TestBase<DiskProvider>
|
||||
{
|
||||
DirectoryInfo _binFolder;
|
||||
DirectoryInfo _binFolderCopy;
|
||||
DirectoryInfo _binFolderMove;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_binFolder = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
_binFolderCopy = new DirectoryInfo(Path.Combine(_binFolder.Parent.FullName, "bin_copy"));
|
||||
_binFolderMove = new DirectoryInfo(Path.Combine(_binFolder.Parent.FullName, "bin_move"));
|
||||
|
||||
if (_binFolderCopy.Exists)
|
||||
{
|
||||
foreach (var file in _binFolderCopy.GetFiles("*", SearchOption.AllDirectories))
|
||||
{
|
||||
file.Attributes = FileAttributes.Normal;
|
||||
}
|
||||
_binFolderCopy.Delete(true);
|
||||
}
|
||||
|
||||
if (_binFolderMove.Exists)
|
||||
{
|
||||
_binFolderMove.Delete(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void directory_exist_should_be_able_to_find_existing_folder()
|
||||
{
|
||||
Subject.FolderExists(TempFolder).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void directory_exist_should_be_able_to_find_existing_unc_share()
|
||||
{
|
||||
WindowsOnly();
|
||||
|
||||
Subject.FolderExists(@"\\localhost\c$").Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void directory_exist_should_not_be_able_to_find_none_existing_folder()
|
||||
{
|
||||
Subject.FolderExists(@"C:\ThisBetterNotExist\".AsOsAgnostic()).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void moveFile_should_overwrite_existing_file()
|
||||
{
|
||||
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
|
||||
|
||||
var targetPath = Path.Combine(_binFolderCopy.FullName, "file.move");
|
||||
|
||||
Subject.MoveFile(_binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath);
|
||||
Subject.MoveFile(_binFolderCopy.GetFiles("*.pdb", SearchOption.AllDirectories).First().FullName, targetPath);
|
||||
|
||||
File.Exists(targetPath).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void moveFile_should_not_move_overwrite_itself()
|
||||
{
|
||||
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
|
||||
|
||||
var targetPath = _binFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName;
|
||||
|
||||
Subject.MoveFile(targetPath, targetPath);
|
||||
|
||||
File.Exists(targetPath).Should().BeTrue();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyFolder_should_copy_folder()
|
||||
{
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
|
||||
VerifyCopy();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CopyFolder_should_overwrite_existing_folder()
|
||||
{
|
||||
|
||||
|
||||
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
|
||||
|
||||
//Delete Random File
|
||||
_binFolderCopy.Refresh();
|
||||
_binFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete();
|
||||
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
|
||||
|
||||
|
||||
VerifyCopy();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MoveFolder_should_overwrite_existing_folder()
|
||||
{
|
||||
|
||||
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderCopy.FullName);
|
||||
Subject.CopyFolder(_binFolder.FullName, _binFolderMove.FullName);
|
||||
VerifyCopy();
|
||||
|
||||
|
||||
Subject.MoveFolder(_binFolderCopy.FullName, _binFolderMove.FullName);
|
||||
|
||||
|
||||
VerifyMove();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void move_read_only_file()
|
||||
{
|
||||
var source = GetTestFilePath();
|
||||
var destination = GetTestFilePath();
|
||||
|
||||
Subject.WriteAllText(source, "SourceFile");
|
||||
Subject.WriteAllText(destination, "DestinationFile");
|
||||
|
||||
File.SetAttributes(source, FileAttributes.ReadOnly);
|
||||
File.SetAttributes(destination, FileAttributes.ReadOnly);
|
||||
|
||||
Subject.MoveFile(source, destination);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void empty_folder_should_return_folder_modified_date()
|
||||
{
|
||||
var tempfolder = new DirectoryInfo(TempFolder);
|
||||
Subject.GetLastFolderWrite(TempFolder).Should().Be(tempfolder.LastWriteTimeUtc);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void folder_should_return_correct_value_for_last_write()
|
||||
{
|
||||
var testFile = GetTestFilePath();
|
||||
|
||||
TestLogger.Info("Path is: {0}", testFile);
|
||||
|
||||
Subject.WriteAllText(testFile, "Test");
|
||||
|
||||
Subject.GetLastFolderWrite(SandboxFolder).Should().BeOnOrAfter(DateTime.UtcNow.AddMinutes(-1));
|
||||
Subject.GetLastFolderWrite(SandboxFolder).Should().BeBefore(DateTime.UtcNow);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_for_unlocked_file()
|
||||
{
|
||||
var testFile = GetTestFilePath();
|
||||
Subject.WriteAllText(testFile, new Guid().ToString());
|
||||
|
||||
Subject.IsFileLocked(testFile).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_for_unlocked_and_readonly_file()
|
||||
{
|
||||
var testFile = GetTestFilePath();
|
||||
Subject.WriteAllText(testFile, new Guid().ToString());
|
||||
|
||||
File.SetAttributes(testFile, FileAttributes.ReadOnly);
|
||||
|
||||
Subject.IsFileLocked(testFile).Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_true_for_unlocked_file()
|
||||
{
|
||||
var testFile = GetTestFilePath();
|
||||
Subject.WriteAllText(testFile, new Guid().ToString());
|
||||
|
||||
using (var file = File.OpenWrite(testFile))
|
||||
{
|
||||
Subject.IsFileLocked(testFile).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_set_permission_from_parrent()
|
||||
{
|
||||
var testFile = GetTestFilePath();
|
||||
Subject.WriteAllText(testFile, new Guid().ToString());
|
||||
|
||||
Subject.InheritFolderPermissions(testFile);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
public void check_last_write()
|
||||
{
|
||||
Console.WriteLine(Subject.GetLastFolderWrite(_binFolder.FullName));
|
||||
Console.WriteLine(_binFolder.LastWriteTimeUtc);
|
||||
}
|
||||
|
||||
private void VerifyCopy()
|
||||
{
|
||||
_binFolder.Refresh();
|
||||
_binFolderCopy.Refresh();
|
||||
|
||||
_binFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)
|
||||
.Should().HaveSameCount(_binFolder.GetFiles("*.*", SearchOption.AllDirectories));
|
||||
|
||||
_binFolderCopy.GetDirectories().Should().HaveSameCount(_binFolder.GetDirectories());
|
||||
}
|
||||
|
||||
private void VerifyMove()
|
||||
{
|
||||
_binFolder.Refresh();
|
||||
_binFolderCopy.Refresh();
|
||||
_binFolderMove.Refresh();
|
||||
|
||||
_binFolderCopy.Exists.Should().BeFalse();
|
||||
|
||||
_binFolderMove.GetFiles("*.*", SearchOption.AllDirectories)
|
||||
.Should().HaveSameCount(_binFolder.GetFiles("*.*", SearchOption.AllDirectories));
|
||||
|
||||
_binFolderMove.GetDirectories().Should().HaveSameCount(_binFolder.GetDirectories());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.DiskProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class FreeSpaceFixture : TestBase<DiskProvider>
|
||||
{
|
||||
[Test]
|
||||
public void should_get_free_space_for_folder()
|
||||
{
|
||||
var path = @"C:\".AsOsAgnostic();
|
||||
|
||||
Subject.GetAvailableSpace(path).Should().NotBe(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_free_space_for_folder_that_doesnt_exist()
|
||||
{
|
||||
var path = @"C:\".AsOsAgnostic();
|
||||
|
||||
Subject.GetAvailableSpace(Path.Combine(path, "invalidFolder")).Should().NotBe(0);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_get_free_space_for_drive_that_doesnt_exist()
|
||||
{
|
||||
WindowsOnly();
|
||||
|
||||
Assert.Throws<DirectoryNotFoundException>(() => Subject.GetAvailableSpace("J:\\").Should().NotBe(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_check_space_on_ramdrive()
|
||||
{
|
||||
LinuxOnly();
|
||||
Subject.GetAvailableSpace("/run/").Should().NotBe(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.DiskProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class IsParentFixture : TestBase<DiskProvider>
|
||||
{
|
||||
private string _parent = @"C:\Test".AsOsAgnostic();
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_not_a_child()
|
||||
{
|
||||
var path = @"C:\Another Folder".AsOsAgnostic();
|
||||
|
||||
Subject.IsParent(_parent, path).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_folder_is_parent_of_another_folder()
|
||||
{
|
||||
var path = @"C:\Test\TV".AsOsAgnostic();
|
||||
|
||||
Subject.IsParent(_parent, path).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_folder_is_parent_of_a_file()
|
||||
{
|
||||
var path = @"C:\Test\30.Rock.S01E01.Pilot.avi".AsOsAgnostic();
|
||||
|
||||
Subject.IsParent(_parent, path).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.EnsureTest
|
||||
{
|
||||
[TestFixture]
|
||||
public class PathExtensionFixture : TestBase
|
||||
{
|
||||
[TestCase(@"p:\TV Shows\file with, comma.mkv")]
|
||||
[TestCase(@"\\serer\share\file with, comma.mkv")]
|
||||
public void EnsureWindowsPath(string path)
|
||||
{
|
||||
WindowsOnly();
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
}
|
||||
|
||||
|
||||
[TestCase(@"/var/user/file with, comma.mkv")]
|
||||
public void EnsureLinuxPath(string path)
|
||||
{
|
||||
LinuxOnly();
|
||||
Ensure.That(() => path).IsValidPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class IAppDirectoryInfoTest : TestBase<AppFolderInfo>
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void StartupPath_should_not_be_empty()
|
||||
{
|
||||
Subject.StartUpFolder.Should().NotBeBlank();
|
||||
Path.IsPathRooted(Subject.StartUpFolder).Should().BeTrue("Path is not rooted");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ApplicationPath_should_not_be_empty()
|
||||
{
|
||||
Subject.AppDataFolder.Should().NotBeBlank();
|
||||
Path.IsPathRooted(Subject.AppDataFolder).Should().BeTrue("Path is not rooted");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsProduction_should_return_false_when_run_within_nunit()
|
||||
{
|
||||
RuntimeInfo.IsProduction.Should().BeFalse("Process name is " + Process.GetCurrentProcess().ProcessName + " Folder is " + Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_path_from_arg_if_provided()
|
||||
{
|
||||
var args = new StartupArguments("-data=\"c:\\users\\test\\\"");
|
||||
|
||||
Mocker.SetConstant<IStartupArguments>(args);
|
||||
Subject.AppDataFolder.Should().Be("c:\\users\\test\\");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.EnvironmentTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BuildInfoTest : TestBase
|
||||
{
|
||||
|
||||
[TestCase("0.0.0.0")]
|
||||
[TestCase("1.0.0.0")]
|
||||
public void Application_version_should_not_be_default(string version)
|
||||
{
|
||||
BuildInfo.Version.Should().NotBe(new Version(version));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.EnvironmentTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class StartupArgumentsFixture : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void empty_array_should_return_empty_flags()
|
||||
{
|
||||
var args = new StartupArguments(new string[0]);
|
||||
args.Flags.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestCase("/t")]
|
||||
[TestCase(" /t")]
|
||||
[TestCase(" /T")]
|
||||
[TestCase(" /t ")]
|
||||
public void should_parse_single_flag(string arg)
|
||||
{
|
||||
var args = new StartupArguments(new[] { arg });
|
||||
args.Flags.Should().HaveCount(1);
|
||||
args.Flags.Contains("t").Should().BeTrue();
|
||||
}
|
||||
|
||||
|
||||
[TestCase("/key=value")]
|
||||
[TestCase("/KEY=value")]
|
||||
[TestCase(" /key=\"value\"")]
|
||||
public void should_parse_args_with_alues(string arg)
|
||||
{
|
||||
var args = new StartupArguments(new[] { arg });
|
||||
args.Args.Should().HaveCount(1);
|
||||
args.Args["key"].Should().Be("value");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2010 Darren Cauthon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{BEC74619-DDBB-4FBA-B517-D3E20AFC9997}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NzbDrone.Common.Test</RootNamespace>
|
||||
<AssemblyName>NzbDrone.Common.Test</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentAssertions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\FluentAssertions.2.1.0.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheTests\CachedManagerFixture.cs" />
|
||||
<Compile Include="CacheTests\CachedFixture.cs" />
|
||||
<Compile Include="ConfigFileProviderTest.cs" />
|
||||
<Compile Include="DiskProviderTests\FreeSpaceFixture.cs" />
|
||||
<Compile Include="DiskProviderTests\IsParentFixture.cs" />
|
||||
<Compile Include="EnsureTest\PathExtensionFixture.cs" />
|
||||
<Compile Include="EnvironmentTests\StartupArgumentsFixture.cs" />
|
||||
<Compile Include="EnvironmentTests\EnvironmentProviderTest.cs" />
|
||||
<Compile Include="ReflectionExtensions.cs" />
|
||||
<Compile Include="PathExtensionFixture.cs" />
|
||||
<Compile Include="DiskProviderTests\DiskProviderFixture.cs" />
|
||||
<Compile Include="EnvironmentProviderTest.cs" />
|
||||
<Compile Include="ProcessProviderTests.cs" />
|
||||
<Compile Include="ReflectionTests\ReflectionExtensionFixture.cs" />
|
||||
<Compile Include="ServiceFactoryFixture.cs" />
|
||||
<Compile Include="ServiceProviderTests.cs" />
|
||||
<Compile Include="WebClientTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\NzbDrone.Test.Common\App.config">
|
||||
<Link>App.config</Link>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
|
||||
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||
<Name>NzbDrone.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
|
||||
<Project>{FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}</Project>
|
||||
<Name>NzbDrone.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NzbDrone.Host\NzbDrone.Host.csproj">
|
||||
<Project>{95C11A9E-56ED-456A-8447-2C89C1139266}</Project>
|
||||
<Name>NzbDrone.Host</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NzbDrone.Test.Common\NzbDrone.Test.Common.csproj">
|
||||
<Project>{CADDFCE0-7509-4430-8364-2074E1EEFCA2}</Project>
|
||||
<Name>NzbDrone.Test.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NzbDrone.Test.Dummy\NzbDrone.Test.Dummy.csproj">
|
||||
<Project>{FAFB5948-A222-4CF6-AD14-026BE7564802}</Project>
|
||||
<Name>NzbDrone.Test.Dummy</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NzbDrone\NzbDrone.csproj">
|
||||
<Project>{D12F7F2F-8A3C-415F-88FA-6DD061A84869}</Project>
|
||||
<Name>NzbDrone</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class PathExtensionFixture : TestBase
|
||||
{
|
||||
|
||||
private IAppFolderInfo GetIAppDirectoryInfo()
|
||||
{
|
||||
var fakeEnvironment = new Mock<IAppFolderInfo>();
|
||||
|
||||
fakeEnvironment.SetupGet(c => c.AppDataFolder).Returns(@"C:\NzbDrone\".AsOsAgnostic());
|
||||
|
||||
fakeEnvironment.SetupGet(c => c.TempFolder).Returns(@"C:\Temp\".AsOsAgnostic());
|
||||
|
||||
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 Clean_Path_Windows(string dirty, string clean)
|
||||
{
|
||||
WindowsOnly();
|
||||
|
||||
var result = dirty.CleanFilePath();
|
||||
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 Clean_Path_Linux(string dirty, string clean)
|
||||
{
|
||||
LinuxOnly();
|
||||
|
||||
var result = dirty.CleanFilePath();
|
||||
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();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void normalize_path_exception_empty()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => "".CleanFilePath());
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void normalize_path_exception_null()
|
||||
{
|
||||
string nullPath = null;
|
||||
Assert.Throws<ArgumentException>(() => nullPath.CleanFilePath());
|
||||
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()
|
||||
{
|
||||
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();
|
||||
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_in_windows()
|
||||
{
|
||||
WindowsOnly();
|
||||
var path = Directory.GetCurrentDirectory().Replace("c:\\","C:\\");
|
||||
|
||||
path.ToUpper().GetActualCasing().Should().Be(path);
|
||||
path.ToLower().GetActualCasing().Should().Be(path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_actual_casing_should_return_original_value_in_linux()
|
||||
{
|
||||
LinuxOnly();
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AppDataDirectory_path_test()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetAppDataPath().Should().BeEquivalentTo(@"C:\NzbDrone\".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Config_path_test()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetConfigPath().Should().BeEquivalentTo(@"C:\NzbDrone\Config.xml".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Sanbox()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetUpdateSandboxFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdatePackageFolder()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetUpdatePackageFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateClientFolder()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone\NzbDrone.Update\".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateClientExePath()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\Nzbdrone_update\NzbDrone.Update.exe".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUpdateLogFolder()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetUpdateLogFolder().Should().BeEquivalentTo(@"C:\NzbDrone\UpdateLogs\".AsOsAgnostic());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Common.Processes;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Dummy;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProcessProviderTests : TestBase<ProcessProvider>
|
||||
{
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c =>
|
||||
{
|
||||
c.Kill();
|
||||
c.WaitForExit();
|
||||
});
|
||||
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetById_should_return_null_if_process_doesnt_exist()
|
||||
{
|
||||
Subject.GetProcessById(1234567).Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
[TestCase(-1)]
|
||||
[TestCase(9999)]
|
||||
public void GetProcessById_should_return_null_for_invalid_process(int processId)
|
||||
{
|
||||
Subject.GetProcessById(processId).Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_be_able_to_start_process()
|
||||
{
|
||||
var process = Subject.Start(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe"));
|
||||
|
||||
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
||||
.BeTrue("excepted one dummy process to be already running");
|
||||
|
||||
process.Kill();
|
||||
process.WaitForExit();
|
||||
|
||||
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void kill_all_should_kill_all_process_with_name()
|
||||
{
|
||||
var dummy1 = StartDummyProcess();
|
||||
var dummy2 = StartDummyProcess();
|
||||
|
||||
Subject.KillAll(DummyApp.DUMMY_PROCCESS_NAME);
|
||||
|
||||
dummy1.HasExited.Should().BeTrue();
|
||||
dummy2.HasExited.Should().BeTrue();
|
||||
}
|
||||
|
||||
private Process StartDummyProcess()
|
||||
{
|
||||
return Subject.Start(DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToString_on_new_processInfo()
|
||||
{
|
||||
Console.WriteLine(new ProcessInfo().ToString());
|
||||
ExceptionVerification.MarkInconclusive(typeof(Win32Exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
public static T GetPropertyValue<T>(this object obj, string propertyName)
|
||||
{
|
||||
return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Reflection;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.ReflectionTests
|
||||
{
|
||||
public class ReflectionExtensionFixture : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_get_properties_from_models()
|
||||
{
|
||||
var models = Assembly.Load("NzbDrone.Core").ImplementationsOf<ModelBase>();
|
||||
|
||||
foreach (var model in models)
|
||||
{
|
||||
model.GetSimpleProperties().Should().NotBeEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_get_implementations()
|
||||
{
|
||||
var models = Assembly.Load("NzbDrone.Core").ImplementationsOf<ModelBase>();
|
||||
|
||||
models.Should().NotBeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Host;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class ServiceFactoryFixture : TestBase<ServiceFactory>
|
||||
{
|
||||
[SetUp]
|
||||
public void setup()
|
||||
{
|
||||
Mocker.SetConstant(MainAppContainerBuilder.BuildContainer(new StartupArguments()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void event_handlers_should_be_unique()
|
||||
{
|
||||
var handlers = Subject.BuildAll<IHandle<ApplicationShutdownRequested>>()
|
||||
.Select(c => c.GetType().FullName);
|
||||
|
||||
handlers.Should().OnlyHaveUniqueItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.ServiceProcess;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
[Timeout(15000)]
|
||||
public class ServiceProviderTests : TestBase<ServiceProvider>
|
||||
{
|
||||
private const string ALWAYS_INSTALLED_SERVICE = "SCardSvr"; //Smart Card
|
||||
private const string TEMP_SERVICE_NAME = "NzbDrone_Nunit";
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
WindowsOnly();
|
||||
CleanupService();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
WindowsOnly();
|
||||
CleanupService();
|
||||
}
|
||||
|
||||
|
||||
private void CleanupService()
|
||||
{
|
||||
if (Subject.ServiceExist(TEMP_SERVICE_NAME))
|
||||
{
|
||||
Subject.UnInstall(TEMP_SERVICE_NAME);
|
||||
}
|
||||
|
||||
if (Subject.IsServiceRunning(ALWAYS_INSTALLED_SERVICE))
|
||||
{
|
||||
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exists_should_find_existing_service()
|
||||
{
|
||||
Subject.ServiceExist(ALWAYS_INSTALLED_SERVICE).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exists_should_not_find_random_service()
|
||||
{
|
||||
Subject.ServiceExist("random_service_name").Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Service_should_be_installed_and_then_uninstalled()
|
||||
{
|
||||
|
||||
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse("Service already installed");
|
||||
Subject.Install(TEMP_SERVICE_NAME);
|
||||
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeTrue();
|
||||
Subject.UnInstall(TEMP_SERVICE_NAME);
|
||||
Subject.ServiceExist(TEMP_SERVICE_NAME).Should().BeFalse();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
public void UnInstallService()
|
||||
{
|
||||
Subject.UnInstall(ServiceProvider.NZBDRONE_SERVICE_NAME);
|
||||
Subject.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_be_able_to_start_and_stop_service()
|
||||
{
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().NotBe(ServiceControllerStatus.Running);
|
||||
|
||||
Subject.Start(ALWAYS_INSTALLED_SERVICE);
|
||||
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().Be(ServiceControllerStatus.Running);
|
||||
|
||||
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
||||
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().Be(ServiceControllerStatus.Stopped);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_starting_a_running_serivce()
|
||||
{
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().NotBe(ServiceControllerStatus.Running);
|
||||
|
||||
Subject.Start(ALWAYS_INSTALLED_SERVICE);
|
||||
Assert.Throws<InvalidOperationException>(() => Subject.Start(ALWAYS_INSTALLED_SERVICE));
|
||||
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Should_log_warn_if_on_stop_if_service_is_already_stopped()
|
||||
{
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().NotBe(ServiceControllerStatus.Running);
|
||||
|
||||
|
||||
Subject.Stop(ALWAYS_INSTALLED_SERVICE);
|
||||
|
||||
|
||||
Subject.GetService(ALWAYS_INSTALLED_SERVICE).Status
|
||||
.Should().Be(ServiceControllerStatus.Stopped);
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class WebClientTests : TestBase<HttpProvider>
|
||||
{
|
||||
[Test]
|
||||
public void DownloadString_should_be_able_to_dowload_text_file()
|
||||
{
|
||||
var jquery = Subject.DownloadString("http://www.google.com/robots.txt");
|
||||
|
||||
jquery.Should().NotBeBlank();
|
||||
jquery.Should().Contain("Sitemap");
|
||||
}
|
||||
|
||||
[TestCase("")]
|
||||
[TestCase("http://")]
|
||||
public void DownloadString_should_throw_on_error(string url)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => Subject.DownloadString(url));
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_get_headers()
|
||||
{
|
||||
Subject.GetHeader("http://www.google.com").Should().NotBeEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="2.1.0.0" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NLog" version="2.0.1.2" targetFramework="net40" />
|
||||
<package id="NUnit" version="2.6.2" targetFramework="net40" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user