2013-08-03 03:01:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-08-04 17:26:37 +00:00
|
|
|
|
using NzbDrone.Api.Directories;
|
|
|
|
|
using NzbDrone.Common;
|
2013-08-03 03:01:16 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
2013-08-04 17:26:37 +00:00
|
|
|
|
namespace NzbDrone.Api.Test
|
2013-08-03 03:01:16 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-08-06 02:42:22 +00:00
|
|
|
|
public class DirectoryLookupServiceFixture : TestBase<DirectoryLookupService>
|
2013-08-03 03:01:16 +00:00
|
|
|
|
{
|
|
|
|
|
private const string RECYCLING_BIN = "$Recycle.Bin";
|
|
|
|
|
private const string SYSTEM_VOLUME_INFORMATION = "System Volume Information";
|
|
|
|
|
private List<String> _folders;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
_folders = new List<String>
|
|
|
|
|
{
|
|
|
|
|
RECYCLING_BIN,
|
|
|
|
|
"Chocolatey",
|
|
|
|
|
"Documents and Settings",
|
|
|
|
|
"Dropbox",
|
|
|
|
|
"Intel",
|
|
|
|
|
"PerfLogs",
|
|
|
|
|
"Program Files",
|
|
|
|
|
"Program Files (x86)",
|
|
|
|
|
"ProgramData",
|
|
|
|
|
SYSTEM_VOLUME_INFORMATION,
|
|
|
|
|
"Test",
|
|
|
|
|
"Users",
|
|
|
|
|
"Windows"
|
|
|
|
|
};
|
2013-08-05 09:49:37 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.SetupGet(s => s.SpecialFolders)
|
|
|
|
|
.Returns(new HashSet<string> { "$recycle.bin", "system volume information", "recycler" });
|
2013-08-03 03:01:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetupFolders(string root)
|
|
|
|
|
{
|
|
|
|
|
_folders.ForEach(e =>
|
|
|
|
|
{
|
|
|
|
|
e = Path.Combine(root, e);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-08-06 02:42:22 +00:00
|
|
|
|
|
2013-08-03 03:01:16 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_contain_recycling_bin_for_root_of_drive()
|
|
|
|
|
{
|
2013-08-06 02:42:22 +00:00
|
|
|
|
string root = @"C:\".AsOsAgnostic();
|
2013-08-03 03:01:16 +00:00
|
|
|
|
SetupFolders(root);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.GetDirectories(It.IsAny<String>()))
|
|
|
|
|
.Returns(_folders.ToArray());
|
|
|
|
|
|
|
|
|
|
Subject.LookupSubDirectories(root).Should().NotContain(Path.Combine(root, RECYCLING_BIN));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-08-06 02:42:22 +00:00
|
|
|
|
public void should_not_contain_system_volume_information()
|
2013-08-03 03:01:16 +00:00
|
|
|
|
{
|
2013-08-06 02:42:22 +00:00
|
|
|
|
string root = @"C:\".AsOsAgnostic();
|
2013-08-03 03:01:16 +00:00
|
|
|
|
SetupFolders(root);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.GetDirectories(It.IsAny<String>()))
|
|
|
|
|
.Returns(_folders.ToArray());
|
|
|
|
|
|
|
|
|
|
Subject.LookupSubDirectories(root).Should().NotContain(Path.Combine(root, SYSTEM_VOLUME_INFORMATION));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_contain_recycling_bin_or_system_volume_information_for_root_of_drive()
|
|
|
|
|
{
|
2013-08-06 02:42:22 +00:00
|
|
|
|
string root = @"C:\";
|
2013-08-03 03:01:16 +00:00
|
|
|
|
SetupFolders(root);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDiskProvider>()
|
|
|
|
|
.Setup(s => s.GetDirectories(It.IsAny<String>()))
|
|
|
|
|
.Returns(_folders.ToArray());
|
|
|
|
|
|
2013-08-05 09:49:37 +00:00
|
|
|
|
var result = Subject.LookupSubDirectories(root);
|
|
|
|
|
|
|
|
|
|
result.Should().HaveCount(_folders.Count - 2);
|
|
|
|
|
result.Should().NotContain(RECYCLING_BIN);
|
|
|
|
|
result.Should().NotContain(SYSTEM_VOLUME_INFORMATION);
|
2013-08-03 03:01:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|