Lidarr/NzbDrone.Common.Test/DiskProviderTests.cs

71 lines
2.0 KiB
C#
Raw Normal View History

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;
[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"));
if (BinFolderCopy.Exists)
{
BinFolderCopy.Delete(true);
}
}
[Test]
public void CopyFolder_should_copy_folder()
{
//Act
var diskProvider = new DiskProvider();
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
//Assert
VerifyCopy();
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
BinFolderCopy.Refresh();
BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories).First().Delete();
2011-10-24 05:54:09 +00:00
diskProvider.CopyDirectory(BinFolder.FullName, BinFolderCopy.FullName);
//Assert
VerifyCopy();
}
private void VerifyCopy()
{
2011-10-24 05:54:09 +00:00
BinFolder.Refresh();
BinFolderCopy.Refresh();
BinFolderCopy.GetFiles("*.*", SearchOption.AllDirectories)
.Should().HaveSameCount(BinFolder.GetFiles("*.*", SearchOption.AllDirectories));
BinFolderCopy.GetDirectories().Should().HaveSameCount(BinFolder.GetDirectories());
2011-10-24 05:54:09 +00:00
}
}
}