fixed some tests, cleaned up root folders.

This commit is contained in:
kay.one 2013-02-16 20:33:56 -08:00
parent e44d262a1a
commit a0d0e4715e
18 changed files with 110 additions and 133 deletions

View File

@ -191,16 +191,16 @@ namespace NzbDrone.Common
File.SetAccessControl(filename, fs);
}
public virtual ulong FreeDiskSpace(DirectoryInfo directoryInfo)
public virtual ulong FreeDiskSpace(string path)
{
if(!directoryInfo.Exists)
throw new DirectoryNotFoundException(directoryInfo.FullName);
if (!FolderExists(path))
throw new DirectoryNotFoundException(path);
ulong freeBytesAvailable;
ulong totalNumberOfBytes;
ulong totalNumberOfFreeBytes;
bool success = GetDiskFreeSpaceEx(directoryInfo.FullName, out freeBytesAvailable, out totalNumberOfBytes,
bool success = GetDiskFreeSpaceEx(path, out freeBytesAvailable, out totalNumberOfBytes,
out totalNumberOfFreeBytes);
if (!success)
throw new System.ComponentModel.Win32Exception();

View File

@ -13,20 +13,20 @@ namespace NzbDrone.Core.Test.Datastore
[TestFixture]
public class ObjectDatabaseFixture : ObjectDbTest
{
private Series testSeries;
private Episode testEpisode;
private ChildModel childModel;
private ParentModel ParentModel;
[SetUp]
public void SetUp()
{
WithObjectDb(memory:false);
testSeries = Builder<Series>
childModel = Builder<ChildModel>
.CreateNew()
.With(s => s.OID = 0)
.Build();
testEpisode = Builder<Episode>
ParentModel = Builder<ParentModel>
.CreateNew()
.With(e => e.OID = 0)
.Build();
@ -37,29 +37,29 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_be_able_to_write_to_database()
{
Db.Insert(testSeries);
Db.AsQueryable<Series>().Should().HaveCount(1);
Db.Insert(childModel);
Db.AsQueryable<ChildModel>().Should().HaveCount(1);
}
[Test]
public void double_insert_should_fail()
{
Db.Insert(testSeries);
Assert.Throws<InvalidOperationException>(() => Db.Insert(testSeries));
Db.Insert(childModel);
Assert.Throws<InvalidOperationException>(() => Db.Insert(childModel));
}
[Test]
public void update_item_with_root_index_0_should_faile()
{
testSeries.OID = 0;
Assert.Throws<InvalidOperationException>(() => Db.Update(testSeries));
childModel.OID = 0;
Assert.Throws<InvalidOperationException>(() => Db.Update(childModel));
}
[Test]
public void should_be_able_to_store_empty_list()
{
var series = new List<Series>();
var series = new List<ParentModel>();
Db.InsertMany(series);
}
@ -67,61 +67,61 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_not_store_dirty_data_in_cache()
{
Db.Insert(testEpisode);
Db.Insert(ParentModel);
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
Db.AsQueryable<ParentModel>().Single().Child.Should().BeNull();
testEpisode.Series = Builder<Series>.CreateNew().Build();
ParentModel.Child = Builder<ChildModel>.CreateNew().Build();
Db.AsQueryable<Episode>().Single().Series.Should().BeNull();
Db.AsQueryable<ParentModel>().Single().Child.Should().BeNull();
}
[Test]
public void should_store_nested_objects()
{
testEpisode.Series = testSeries;
ParentModel.Child = childModel;
Db.Insert(testEpisode);
Db.Insert(ParentModel);
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
Db.AsQueryable<ParentModel>().Should().HaveCount(1);
Db.AsQueryable<ParentModel>().Single().Child.Should().NotBeNull();
}
[Test]
public void should_update_nested_objects()
{
testEpisode.Series = Builder<Series>
ParentModel.Child = Builder<ChildModel>
.CreateNew()
.With(s => s.OID = 0)
.Build();
Db.Insert(testEpisode);
Db.Insert(ParentModel);
testEpisode.Series.Title = "UpdatedTitle";
ParentModel.Child.A = "UpdatedTitle";
Db.Update(testEpisode);
Db.Update(ParentModel);
Db.AsQueryable<Episode>().Should().HaveCount(1);
Db.AsQueryable<Episode>().Single().Series.Should().NotBeNull();
Db.AsQueryable<Episode>().Single().Series.Title.Should().Be("UpdatedTitle");
Db.AsQueryable<ParentModel>().Should().HaveCount(1);
Db.AsQueryable<ParentModel>().Single().Child.Should().NotBeNull();
Db.AsQueryable<ParentModel>().Single().Child.A.Should().Be("UpdatedTitle");
}
[Test]
public void new_objects_should_get_id()
{
testSeries.OID = 0;
Db.Insert(testSeries);
testSeries.OID.Should().NotBe(0);
childModel.OID = 0;
Db.Insert(childModel);
childModel.OID.Should().NotBe(0);
}
[Test]
public void new_object_should_get_new_id()
{
testSeries.OID = 0;
Db.Insert(testSeries);
childModel.OID = 0;
Db.Insert(childModel);
Db.AsQueryable<Series>().Should().HaveCount(1);
testSeries.OID.Should().Be(1);
Db.AsQueryable<ChildModel>().Should().HaveCount(1);
childModel.OID.Should().Be(1);
}
@ -141,24 +141,24 @@ namespace NzbDrone.Core.Test.Datastore
[Test]
public void should_have_id_when_returned_from_database()
{
testSeries.OID = 0;
Db.Insert(testSeries);
var item = Db.AsQueryable<Series>();
childModel.OID = 0;
Db.Insert(childModel);
var item = Db.AsQueryable<ChildModel>();
item.Should().HaveCount(1);
item.First().OID.Should().NotBe(0);
item.First().OID.Should().BeLessThan(100);
item.First().OID.Should().Be(testSeries.OID);
item.First().OID.Should().Be(childModel.OID);
}
[Test]
public void should_be_able_to_find_object_by_id()
{
Db.Insert(testSeries);
var item = Db.AsQueryable<Series>().Single(c => c.OID == testSeries.OID);
Db.Insert(childModel);
var item = Db.AsQueryable<ChildModel>().Single(c => c.OID == childModel.OID);
item.OID.Should().NotBe(0);
item.OID.Should().Be(testSeries.OID);
item.OID.Should().Be(childModel.OID);
}
[Test]
@ -182,5 +182,18 @@ namespace NzbDrone.Core.Test.Datastore
public List<NestedModel> List { get; set; }
}
public class ParentModel : BaseRepositoryModel
{
public ChildModel Child { get; set; }
}
public class ChildModel : BaseRepositoryModel
{
public String A { get; set; }
public int B { get; set; }
public int C { get; set; }
}
}

View File

@ -27,8 +27,15 @@ namespace NzbDrone.Core.Test.Integeration
builder.Register(c => Db)
.As<IDatabase>();
builder.RegisterType<ReferenceDataProvider>().AsSelf();
builder.RegisterType<SceneMappingProvider>().AsSelf();
builder.RegisterType<HttpProvider>().AsSelf();
builder.RegisterType<ConfigProvider>().AsSelf();
_container = builder.Build();
Mocker.GetMock<ConfigProvider>().SetupGet(s => s.ServiceRootUrl)
.Returns("http://services.nzbdrone.com");
}
@ -54,30 +61,5 @@ namespace NzbDrone.Core.Test.Integeration
dailySeries.Should().NotBeEmpty();
dailySeries.Should().OnlyContain(c => c > 0);
}
[Test]
public void should_be_able_to_submit_exceptions()
{
ReportingService.SetupExceptronDriver();
try
{
ThrowException();
}
catch (Exception e)
{
var log = new LogEventInfo
{
LoggerName = "LoggerName.LoggerName.LoggerName.LoggerName",
Exception = e,
Message = "New message string. New message string.",
};
var hash = ReportingService.ReportException(log);
hash.Should().HaveLength(8);
}
}
}
}

View File

@ -161,7 +161,7 @@
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
<Compile Include="ProviderTests\DownloadProviderTests\ContainsRecentEpisode.cs" />
<Compile Include="ProviderTests\RootFolderServiceTests\FreeSpaceOnDrivesFixture.cs" />
<Compile Include="RootFolderTests\FreeSpaceOnDrivesFixture.cs" />
<Compile Include="ProviderTests\SearchTests\ProcessResultsFixture.cs" />
<Compile Include="ProviderTests\SearchTests\DailyEpisodeSearchTests\CheckReportFixture.cs" />
<Compile Include="ProviderTests\SearchTests\EpisodeSearchTests\CheckReportFixture.cs" />
@ -262,7 +262,7 @@
<Compile Include="ProviderTests\DecisionEngineTests\AllowedDownloadSpecificationFixture.cs" />
<Compile Include="ProviderTests\JobProviderTests\JobProviderFixture.cs" />
<Compile Include="QualityTest.cs" />
<Compile Include="ProviderTests\RootFolderServiceTests\RootFolderServiceFixture.cs" />
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
<Compile Include="ProviderTests\IndexerProviderTest.cs" />
<Compile Include="ProviderTests\HistoryProviderTest.cs" />
<Compile Include="ProviderTests\MediaFileProviderTest.cs" />

View File

@ -15,23 +15,20 @@ using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
{
[TestFixture]
public class FreeDiskSpaceTest : SqlCeTest
public class FreeDiskSpaceTest : CoreTest<DiskProvider>
{
[Test]
public void should_return_free_disk_space()
{
var di = new DirectoryInfo(Directory.GetCurrentDirectory());
var result = Mocker.Resolve<DiskProvider>().FreeDiskSpace(di);
var result = Subject.FreeDiskSpace(Directory.GetCurrentDirectory());
//Checks to ensure that the free space on the first is greater than 0 (It should be in 99.99999999999999% of cases... I hope)
result.Should().BeGreaterThan(0);
}
[Test]
public void should_throw_if_directoy_does_not_exist()
public void should_throw_if_drive_doesnt_exist()
{
var di = new DirectoryInfo(@"Z:\NOT_A_REAL_PATH\DOES_NOT_EXIST");
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<DiskProvider>().FreeDiskSpace(di));
Assert.Throws<DirectoryNotFoundException>(() => Subject.FreeDiskSpace(@"Z:\NOT_A_REAL_PATH\DOES_NOT_EXIST"));
}
}
}

View File

@ -64,7 +64,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
private void WithLotsOfFreeDiskSpace()
{
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>())).Returns(1000000000);
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
}
private void WithImportedFiles(string droppedFolder)
@ -357,7 +357,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Returns(true);
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(series.Path)))
.Setup(s => s.FreeDiskSpace(series.Path))
.Returns(9);
//Act
@ -408,7 +408,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Returns(10);
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>()))
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
.Returns(10);
//Act

View File

@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
private void WithLotsOfFreeDiskSpace()
{
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>())).Returns(1000000000);
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
}
[Test]

View File

@ -64,7 +64,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
private void WithLotsOfFreeDiskSpace()
{
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>())).Returns(1000000000);
Mocker.GetMock<DiskProvider>().Setup(s => s.FreeDiskSpace(It.IsAny<string>())).Returns(1000000000);
}
private void WithImportedFile(string file)
@ -157,7 +157,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Returns(10);
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(series.Path)))
.Setup(s => s.FreeDiskSpace(series.Path))
.Returns(9);
Mocker.GetMock<DiskProvider>()
@ -209,7 +209,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Returns(10);
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>()))
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
.Returns(10);
//Act

View File

@ -4,25 +4,19 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
using PetaPoco;
namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
namespace NzbDrone.Core.Test.RootFolderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class FreeSpaceOnDrivesFixture : CoreTest
public class FreeSpaceOnDrivesFixture : CoreTest<RootFolderService>
{
[Test]
public void should_return_one_drive_when_only_one_root_dir_exists()
@ -36,10 +30,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\")))
.Setup(s => s.FreeDiskSpace(@"C:\"))
.Returns(123456);
var result = Mocker.Resolve<RootFolderService>().FreeSpaceOnDrives();
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(1);
}
@ -57,10 +51,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\")))
.Setup(s => s.FreeDiskSpace(@"C:\"))
.Returns(123456);
var result = Mocker.Resolve<RootFolderService>().FreeSpaceOnDrives();
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(1);
}
@ -82,10 +76,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
.Returns(@"D:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>()))
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
.Returns(123456);
var result = Mocker.Resolve<RootFolderService>().FreeSpaceOnDrives();
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(2);
}
@ -102,10 +96,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
.Returns(@"C:\");
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>()))
.Setup(s => s.FreeDiskSpace(It.IsAny<string>()))
.Throws(new DirectoryNotFoundException());
var result = Mocker.Resolve<RootFolderService>().FreeSpaceOnDrives();
var result = Subject.FreeSpaceOnDrives();
result.Should().HaveCount(0);

View File

@ -8,14 +8,10 @@ using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests.RootFolderServiceTests
namespace NzbDrone.Core.Test.RootFolderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming

View File

@ -83,7 +83,7 @@ namespace NzbDrone.Core
container.Register(c =>
{
return c.Resolve<IObjectDbFactory>().Create("");
}).As<SiaqodbProxy>().SingleInstance();
}).As<IObjectDatabase>().SingleInstance();
container.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
container.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));

View File

@ -70,12 +70,15 @@ namespace NzbDrone.Core.Datastore
public void Delete<T>(T obj) where T : BaseRepositoryModel
{
throw new NotImplementedException();
_db.Delete(obj);
}
public void DeleteMany<T>(IEnumerable<T> objects) where T : BaseRepositoryModel
{
throw new NotImplementedException();
foreach (var o in objects)
{
Delete(o);
}
}
private IList<T> DoMany<T>(IEnumerable<T> objects, Func<T, T> function) where T : BaseRepositoryModel

View File

@ -92,7 +92,7 @@ namespace NzbDrone.Core.Providers
}
var size = _diskProvider.GetDirectorySize(subfolderInfo.FullName);
var freeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(series.Path));
var freeSpace = _diskProvider.FreeDiskSpace(series.Path);
if (Convert.ToUInt64(size) > freeSpace)
{
@ -161,7 +161,7 @@ namespace NzbDrone.Core.Providers
}
var size = _diskProvider.GetSize(videoFile);
var freeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(series.Path));
var freeSpace = _diskProvider.FreeDiskSpace(series.Path);
if (Convert.ToUInt64(size) > freeSpace)
{

View File

@ -7,7 +7,7 @@ namespace NzbDrone.Core.Repository
{
[TableName("Episodes")]
[PrimaryKey("EpisodeId", autoIncrement = true)]
public class Episode:BaseRepositoryModel
public class Episode
{
public int EpisodeId { get; set; }

View File

@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Model;
using NzbDrone.Core.Repository.Quality;
using PetaPoco;
@ -8,7 +7,7 @@ using PetaPoco;
namespace NzbDrone.Core.Repository
{
[PrimaryKey("SeriesId", autoIncrement = false)]
public class Series:BaseRepositoryModel
public class Series
{
public virtual int SeriesId { get; set; }

View File

@ -1,20 +1,16 @@
using System.Collections.Generic;
using NzbDrone.Core.Datastore;
using PetaPoco;
using Sqo.Attributes;
namespace NzbDrone.Core.RootFolders
{
[TableName("RootDirs")]
[PrimaryKey("Id", autoIncrement = true)]
public class RootFolder : BaseRepositoryModel
{
public string Path { get; set; }
[ResultColumn]
[Ignore]
public ulong FreeSpace { get; set; }
[Ignore]
public List<string> UnmappedFolders { get; set; }
}
}

View File

@ -8,7 +8,6 @@ namespace NzbDrone.Core.RootFolders
}
//This way we only need to implement none_custom methods for repos, like custom queries etc... rest is done automagically.
public class RootFolderRepository : BasicRepository<RootFolder>, IRootFolderRepository
{
public RootFolderRepository(IObjectDatabase objectDatabase)
@ -16,10 +15,5 @@ namespace NzbDrone.Core.RootFolders
{
}
public RootFolder Add(RootFolder rootFolder)
{
return ObjectDatabase.Insert(rootFolder);
}
}
}

View File

@ -38,8 +38,11 @@ namespace NzbDrone.Core.RootFolders
rootFolders.ForEach(folder =>
{
folder.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(folder.Path));
if (_diskProvider.FolderExists(folder.Path))
{
folder.FreeSpace = _diskProvider.FreeDiskSpace(folder.Path);
folder.UnmappedFolders = GetUnmappedFolders(folder.Path);
}
});
return rootFolders;
@ -58,7 +61,7 @@ namespace NzbDrone.Core.RootFolders
_rootFolderRepository.Add(rootFolder);
rootFolder.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(rootFolder.Path));
rootFolder.FreeSpace = _diskProvider.FreeDiskSpace(rootFolder.Path);
rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path);
return rootFolder;
}
@ -108,7 +111,7 @@ namespace NzbDrone.Core.RootFolders
{
try
{
freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)));
freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(rootDir.Path));
}
catch (Exception ex)
{