Radarr/src/NzbDrone.Common.Test/DiskTests/DirectoryLookupServiceFixtu...

88 lines
2.9 KiB
C#
Raw Normal View History

2018-11-23 07:03:32 +00:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Test.Common;
namespace NzbDrone.Common.Test.DiskTests
{
[TestFixture]
public class DirectoryLookupServiceFixture : TestBase<FileSystemLookupService>
{
private const string RECYCLING_BIN = "$Recycle.Bin";
private const string SYSTEM_VOLUME_INFORMATION = "System Volume Information";
private const string WINDOWS = "Windows";
private List<DirectoryInfo> _folders;
private void SetupFolders(string root)
{
var 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
_folders = folders.Select(f => new DirectoryInfo(Path.Combine(root, f))).ToList();
}
2013-08-06 02:42:22 +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();
SetupFolders(root);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
.Returns(_folders);
2018-11-23 07:03:32 +00:00
Subject.LookupContents(root, false, false).Directories.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-06 02:42:22 +00:00
string root = @"C:\".AsOsAgnostic();
SetupFolders(root);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
.Returns(_folders);
2018-11-23 07:03:32 +00:00
Subject.LookupContents(root, false, false).Directories.Should().NotContain(Path.Combine(root, SYSTEM_VOLUME_INFORMATION));
}
[Test]
public void should_not_contain_recycling_bin_or_system_volume_information_for_root_of_drive()
{
string root = @"C:\".AsOsAgnostic();
SetupFolders(root);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectoryInfos(It.IsAny<string>()))
.Returns(_folders);
2018-11-23 07:03:32 +00:00
var result = Subject.LookupContents(root, false, false);
2019-12-22 21:24:11 +00:00
result.Directories.Should().HaveCount(_folders.Count - 3);
2013-08-05 09:49:37 +00:00
result.Directories.Should().NotContain(f => f.Name == RECYCLING_BIN);
result.Directories.Should().NotContain(f => f.Name == SYSTEM_VOLUME_INFORMATION);
result.Directories.Should().NotContain(f => f.Name == WINDOWS);
}
}
}