2011-10-24 05:54:09 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2011-11-13 18:16:31 +00:00
|
|
|
|
using NzbDrone.Test.Common;
|
2011-10-24 05:54:09 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-11-13 18:16:31 +00:00
|
|
|
|
public class DiskProviderTests : TestBase
|
2011-10-24 05:54:09 +00:00
|
|
|
|
{
|
|
|
|
|
DirectoryInfo BinFolder;
|
|
|
|
|
DirectoryInfo BinFolderCopy;
|
2011-11-18 06:52:50 +00:00
|
|
|
|
DirectoryInfo BinFolderMove;
|
2011-10-24 05:54:09 +00:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
var binRoot = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.Parent;
|
|
|
|
|
BinFolder = new DirectoryInfo(Path.Combine(binRoot.FullName, "bin"));
|
|
|
|
|
BinFolderCopy = new DirectoryInfo(Path.Combine(binRoot.FullName, "bin_copy"));
|
2011-11-18 06:52:50 +00:00
|
|
|
|
BinFolderMove = new DirectoryInfo(Path.Combine(binRoot.FullName, "bin_move"));
|
2011-10-24 05:54:09 +00:00
|
|
|
|
|
|
|
|
|
if (BinFolderCopy.Exists)
|
|
|
|
|
{
|
|
|
|
|
BinFolderCopy.Delete(true);
|
|
|
|
|
}
|
2011-11-18 06:52:50 +00:00
|
|
|
|
|
|
|
|
|
if (BinFolderMove.Exists)
|
|
|
|
|
{
|
|
|
|
|
BinFolderMove.Delete(true);
|
|
|
|
|
}
|
2011-10-24 05:54:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-18 07:16:05 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void moveFile_should_overwrite_existing_file()
|
|
|
|
|
{
|
|
|
|
|
var diskProvider = new DiskProvider();
|
|
|
|
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
|
|
|
|
|
|
|
|
|
var targetPath = Path.Combine(BinFolderCopy.FullName, "file.move");
|
|
|
|
|
|
|
|
|
|
diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath);
|
|
|
|
|
diskProvider.MoveFile(BinFolderCopy.GetFiles("*.dll", SearchOption.AllDirectories).First().FullName, targetPath);
|
|
|
|
|
|
|
|
|
|
File.Exists(targetPath).Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-24 05:54:09 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void CopyFolder_should_copy_folder()
|
|
|
|
|
{
|
|
|
|
|
//Act
|
|
|
|
|
var diskProvider = new DiskProvider();
|
|
|
|
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-11-14 04:05:33 +00:00
|
|
|
|
VerifyCopy();
|
2011-10-24 05:54:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-18 07:16:05 +00:00
|
|
|
|
|
2011-10-24 05:54:09 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void CopyFolder_should_overright_existing_folder()
|
|
|
|
|
{
|
|
|
|
|
//Act
|
|
|
|
|
var diskProvider = new DiskProvider();
|
|
|
|
|
|
|
|
|
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
|
|
|
|
|
|
|
|
|
//Delete Random File
|
2011-11-14 04:05:33 +00:00
|
|
|
|
BinFolderCopy.Refresh();
|
|
|
|
|
BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete();
|
2011-10-24 05:54:09 +00:00
|
|
|
|
|
|
|
|
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-11-14 04:05:33 +00:00
|
|
|
|
VerifyCopy();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-18 06:52:50 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void MoveFolder_should_overright_existing_folder()
|
|
|
|
|
{
|
|
|
|
|
var diskProvider = new DiskProvider();
|
|
|
|
|
|
|
|
|
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
|
|
|
|
|
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderMove.FullName);
|
|
|
|
|
VerifyCopy();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
diskProvider.MoveDirectory(BinFolderCopy.FullName, BinFolderMove.FullName);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
VerifyMove();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 04:05:33 +00:00
|
|
|
|
private void VerifyCopy()
|
|
|
|
|
{
|
2011-10-24 05:54:09 +00:00
|
|
|
|
BinFolder.Refresh();
|
|
|
|
|
BinFolderCopy.Refresh();
|
|
|
|
|
|
2011-11-14 04:05:33 +00:00
|
|
|
|
BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)
|
|
|
|
|
.Should().HaveSameCount(BinFolder.GetFiles("*.*", SearchOption.AllDirectories));
|
|
|
|
|
|
|
|
|
|
BinFolderCopy.GetDirectories().Should().HaveSameCount(BinFolder.GetDirectories());
|
2011-10-24 05:54:09 +00:00
|
|
|
|
}
|
2011-11-18 06:52:50 +00:00
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
2011-10-24 05:54:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|