2012-12-26 10:20:31 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2013-02-17 08:09:35 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-02-04 07:18:59 +03:00
|
|
|
using NzbDrone.Core.RootFolders;
|
2012-12-26 10:20:31 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
2013-02-17 07:33:56 +03:00
|
|
|
namespace NzbDrone.Core.Test.RootFolderTests
|
2012-12-26 10:20:31 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-17 07:33:56 +03:00
|
|
|
public class FreeSpaceOnDrivesFixture : CoreTest<RootFolderService>
|
2012-12-26 10:20:31 +03:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void should_return_one_drive_when_only_one_root_dir_exists()
|
|
|
|
{
|
2013-02-17 08:09:35 +03:00
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
2013-02-05 07:07:07 +03:00
|
|
|
.Setup(s => s.All())
|
2013-02-17 04:52:40 +03:00
|
|
|
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" } });
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
|
|
|
.Returns(@"C:\");
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-17 07:33:56 +03:00
|
|
|
.Setup(s => s.FreeDiskSpace(@"C:\"))
|
2012-12-26 10:20:31 +03:00
|
|
|
.Returns(123456);
|
|
|
|
|
2013-02-17 07:33:56 +03:00
|
|
|
var result = Subject.FreeSpaceOnDrives();
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_one_drive_when_two_rootDirs_on_the_same_drive_exist()
|
|
|
|
{
|
2013-02-17 08:09:35 +03:00
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
2013-02-05 07:07:07 +03:00
|
|
|
.Setup(s => s.All())
|
2013-02-17 04:52:40 +03:00
|
|
|
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" },
|
|
|
|
new RootFolder { OID = 2, Path = @"C:\Test\TV2" }});
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetPathRoot(It.IsAny<String>()))
|
|
|
|
.Returns(@"C:\");
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-17 07:33:56 +03:00
|
|
|
.Setup(s => s.FreeDiskSpace(@"C:\"))
|
2012-12-26 10:20:31 +03:00
|
|
|
.Returns(123456);
|
|
|
|
|
2013-02-17 07:33:56 +03:00
|
|
|
var result = Subject.FreeSpaceOnDrives();
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_two_drives_when_two_rootDirs_on_the_different_drive_exist()
|
|
|
|
{
|
2013-02-17 08:09:35 +03:00
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
2013-02-05 07:07:07 +03:00
|
|
|
.Setup(s => s.All())
|
2013-02-17 04:52:40 +03:00
|
|
|
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" },
|
|
|
|
new RootFolder { OID = 2, Path = @"D:\Test\TV" }});
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
|
|
|
.Returns(@"C:\");
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetPathRoot(@"D:\Test\TV"))
|
|
|
|
.Returns(@"D:\");
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-17 07:33:56 +03:00
|
|
|
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
|
2012-12-26 10:20:31 +03:00
|
|
|
.Returns(123456);
|
|
|
|
|
2013-02-17 07:33:56 +03:00
|
|
|
var result = Subject.FreeSpaceOnDrives();
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
result.Should().HaveCount(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_skip_rootDir_if_not_found_on_disk()
|
|
|
|
{
|
2013-02-17 08:09:35 +03:00
|
|
|
Mocker.GetMock<IBasicRepository<RootFolder>>()
|
2013-02-05 07:07:07 +03:00
|
|
|
.Setup(s => s.All())
|
2013-02-17 04:52:40 +03:00
|
|
|
.Returns(new List<RootFolder> { new RootFolder { OID = 1, Path = @"C:\Test\TV" } });
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
|
|
|
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
|
|
|
.Returns(@"C:\");
|
|
|
|
|
|
|
|
Mocker.GetMock<DiskProvider>()
|
2013-02-17 07:33:56 +03:00
|
|
|
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
|
2012-12-26 10:20:31 +03:00
|
|
|
.Throws(new DirectoryNotFoundException());
|
|
|
|
|
2013-02-17 07:33:56 +03:00
|
|
|
var result = Subject.FreeSpaceOnDrives();
|
2012-12-26 10:20:31 +03:00
|
|
|
|
|
|
|
result.Should().HaveCount(0);
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|