From a0d0e4715e72315256a9c6ccb326242c048a820b Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 16 Feb 2013 20:33:56 -0800 Subject: [PATCH] fixed some tests, cleaned up root folders. --- NzbDrone.Common/DiskProvider.cs | 8 +- .../Datastore/ObjectDatabaseFixture.cs | 93 +++++++++++-------- .../ServiceIntegerationFixture.cs | 32 ++----- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 4 +- .../DiskProviderTests/FreeDiskSpaceTest.cs | 11 +-- .../ProcessDownloadFixture.cs | 6 +- .../ProcessDropDirectoryFixture.cs | 2 +- .../ProcessVideoFileFixture.cs | 6 +- .../FreeSpaceOnDrivesFixture.cs | 26 ++---- .../RootFolderServiceFixture.cs | 6 +- NzbDrone.Core/ContainerExtentions.cs | 2 +- NzbDrone.Core/Datastore/SiaqodbProxy.cs | 11 ++- .../Providers/PostDownloadProvider.cs | 4 +- NzbDrone.Core/Repository/Episode.cs | 2 +- NzbDrone.Core/Repository/Series.cs | 3 +- NzbDrone.Core/RootFolders/RootFolder.cs | 8 +- .../RootFolders/RootFolderRepository.cs | 8 +- .../RootFolders/RootFolderService.cs | 11 ++- 18 files changed, 110 insertions(+), 133 deletions(-) rename NzbDrone.Core.Test/{ProviderTests/RootFolderServiceTests => RootFolderTests}/FreeSpaceOnDrivesFixture.cs (77%) rename NzbDrone.Core.Test/{ProviderTests/RootFolderServiceTests => RootFolderTests}/RootFolderServiceFixture.cs (94%) diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index 53ceacebf..fe5c10bf4 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -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(); diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 06f7e7427..46f2d5c93 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -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 + childModel = Builder .CreateNew() .With(s => s.OID = 0) .Build(); - testEpisode = Builder + ParentModel = Builder .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().Should().HaveCount(1); + Db.Insert(childModel); + Db.AsQueryable().Should().HaveCount(1); } [Test] public void double_insert_should_fail() { - Db.Insert(testSeries); - Assert.Throws(() => Db.Insert(testSeries)); + Db.Insert(childModel); + Assert.Throws(() => Db.Insert(childModel)); } [Test] public void update_item_with_root_index_0_should_faile() { - testSeries.OID = 0; - Assert.Throws(() => Db.Update(testSeries)); + childModel.OID = 0; + Assert.Throws(() => Db.Update(childModel)); } [Test] public void should_be_able_to_store_empty_list() { - var series = new List(); + var series = new List(); 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().Single().Series.Should().BeNull(); + Db.AsQueryable().Single().Child.Should().BeNull(); - testEpisode.Series = Builder.CreateNew().Build(); + ParentModel.Child = Builder.CreateNew().Build(); - Db.AsQueryable().Single().Series.Should().BeNull(); + Db.AsQueryable().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().Should().HaveCount(1); - Db.AsQueryable().Single().Series.Should().NotBeNull(); + Db.AsQueryable().Should().HaveCount(1); + Db.AsQueryable().Single().Child.Should().NotBeNull(); } [Test] public void should_update_nested_objects() { - testEpisode.Series = Builder + ParentModel.Child = Builder .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().Should().HaveCount(1); - Db.AsQueryable().Single().Series.Should().NotBeNull(); - Db.AsQueryable().Single().Series.Title.Should().Be("UpdatedTitle"); + Db.AsQueryable().Should().HaveCount(1); + Db.AsQueryable().Single().Child.Should().NotBeNull(); + Db.AsQueryable().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().Should().HaveCount(1); - testSeries.OID.Should().Be(1); + Db.AsQueryable().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(); + childModel.OID = 0; + Db.Insert(childModel); + var item = Db.AsQueryable(); 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().Single(c => c.OID == testSeries.OID); + Db.Insert(childModel); + var item = Db.AsQueryable().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 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; } + } } diff --git a/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs b/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs index 4d52f87ab..81d2bd62b 100644 --- a/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs +++ b/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs @@ -27,8 +27,15 @@ namespace NzbDrone.Core.Test.Integeration builder.Register(c => Db) .As(); + builder.RegisterType().AsSelf(); + builder.RegisterType().AsSelf(); + builder.RegisterType().AsSelf(); + builder.RegisterType().AsSelf(); + _container = builder.Build(); + + Mocker.GetMock().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); - } - } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 3a78efc33..2ea240707 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -161,7 +161,7 @@ - + @@ -262,7 +262,7 @@ - + diff --git a/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs b/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs index 2f3176887..1ff440b4a 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs @@ -15,23 +15,20 @@ using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests { [TestFixture] - public class FreeDiskSpaceTest : SqlCeTest + public class FreeDiskSpaceTest : CoreTest { [Test] public void should_return_free_disk_space() { - var di = new DirectoryInfo(Directory.GetCurrentDirectory()); - var result = Mocker.Resolve().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(() => Mocker.Resolve().FreeDiskSpace(di)); + Assert.Throws(() => Subject.FreeDiskSpace(@"Z:\NOT_A_REAL_PATH\DOES_NOT_EXIST")); } } } diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs index e49f2ac72..0ed3a7ccc 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests private void WithLotsOfFreeDiskSpace() { - Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); + Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); } private void WithImportedFiles(string droppedFolder) @@ -357,7 +357,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Returns(true); Mocker.GetMock() - .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() - .Setup(s => s.FreeDiskSpace(It.IsAny())) + .Setup(s => s.FreeDiskSpace(It.IsAny())) .Returns(10); //Act diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs index a5543a53a..2e69bad7c 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDropDirectoryFixture.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests private void WithLotsOfFreeDiskSpace() { - Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); + Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs index 966119536..188f8c82a 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessVideoFileFixture.cs @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests private void WithLotsOfFreeDiskSpace() { - Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); + Mocker.GetMock().Setup(s => s.FreeDiskSpace(It.IsAny())).Returns(1000000000); } private void WithImportedFile(string file) @@ -157,7 +157,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Returns(10); Mocker.GetMock() - .Setup(s => s.FreeDiskSpace(new DirectoryInfo(series.Path))) + .Setup(s => s.FreeDiskSpace(series.Path)) .Returns(9); Mocker.GetMock() @@ -209,7 +209,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests .Returns(10); Mocker.GetMock() - .Setup(s => s.FreeDiskSpace(It.IsAny())) + .Setup(s => s.FreeDiskSpace(It.IsAny())) .Returns(10); //Act diff --git a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs b/NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs similarity index 77% rename from NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs rename to NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs index ca53b1ea1..2b1530524 100644 --- a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs +++ b/NzbDrone.Core.Test/RootFolderTests/FreeSpaceOnDrivesFixture.cs @@ -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 { [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() - .Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\"))) + .Setup(s => s.FreeDiskSpace(@"C:\")) .Returns(123456); - var result = Mocker.Resolve().FreeSpaceOnDrives(); + var result = Subject.FreeSpaceOnDrives(); result.Should().HaveCount(1); } @@ -57,10 +51,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests .Returns(@"C:\"); Mocker.GetMock() - .Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\"))) + .Setup(s => s.FreeDiskSpace(@"C:\")) .Returns(123456); - var result = Mocker.Resolve().FreeSpaceOnDrives(); + var result = Subject.FreeSpaceOnDrives(); result.Should().HaveCount(1); } @@ -82,10 +76,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests .Returns(@"D:\"); Mocker.GetMock() - .Setup(s => s.FreeDiskSpace(It.IsAny())) + .Setup(s => s.FreeDiskSpace(It.IsAny())) .Returns(123456); - var result = Mocker.Resolve().FreeSpaceOnDrives(); + var result = Subject.FreeSpaceOnDrives(); result.Should().HaveCount(2); } @@ -102,10 +96,10 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests .Returns(@"C:\"); Mocker.GetMock() - .Setup(s => s.FreeDiskSpace(It.IsAny())) + .Setup(s => s.FreeDiskSpace(It.IsAny())) .Throws(new DirectoryNotFoundException()); - var result = Mocker.Resolve().FreeSpaceOnDrives(); + var result = Subject.FreeSpaceOnDrives(); result.Should().HaveCount(0); diff --git a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs b/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs similarity index 94% rename from NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs rename to NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs index 13bc0463c..9af970013 100644 --- a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs +++ b/NzbDrone.Core.Test/RootFolderTests/RootFolderServiceFixture.cs @@ -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 diff --git a/NzbDrone.Core/ContainerExtentions.cs b/NzbDrone.Core/ContainerExtentions.cs index 3602c37aa..51db19a76 100644 --- a/NzbDrone.Core/ContainerExtentions.cs +++ b/NzbDrone.Core/ContainerExtentions.cs @@ -83,7 +83,7 @@ namespace NzbDrone.Core container.Register(c => { return c.Resolve().Create(""); - }).As().SingleInstance(); + }).As().SingleInstance(); container.RegisterType().WithParameter(ResolvedParameter.ForNamed("DatabaseTarget")); container.RegisterType().WithParameter(ResolvedParameter.ForNamed("LogProvider")); diff --git a/NzbDrone.Core/Datastore/SiaqodbProxy.cs b/NzbDrone.Core/Datastore/SiaqodbProxy.cs index e60680bce..eb2176dff 100644 --- a/NzbDrone.Core/Datastore/SiaqodbProxy.cs +++ b/NzbDrone.Core/Datastore/SiaqodbProxy.cs @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Datastore throw new InvalidOperationException("Attempted to insert object with existing ID as new object"); } - _db.StoreObject(obj); + _db.StoreObject(obj); return obj; } @@ -59,7 +59,7 @@ namespace NzbDrone.Core.Datastore public IList InsertMany(IList objects) where T : BaseRepositoryModel { - return DoMany(objects,Insert); + return DoMany(objects, Insert); } public IList UpdateMany(IList objects) where T : BaseRepositoryModel @@ -70,12 +70,15 @@ namespace NzbDrone.Core.Datastore public void Delete(T obj) where T : BaseRepositoryModel { - throw new NotImplementedException(); + _db.Delete(obj); } public void DeleteMany(IEnumerable objects) where T : BaseRepositoryModel { - throw new NotImplementedException(); + foreach (var o in objects) + { + Delete(o); + } } private IList DoMany(IEnumerable objects, Func function) where T : BaseRepositoryModel diff --git a/NzbDrone.Core/Providers/PostDownloadProvider.cs b/NzbDrone.Core/Providers/PostDownloadProvider.cs index bdf192641..0b852306e 100644 --- a/NzbDrone.Core/Providers/PostDownloadProvider.cs +++ b/NzbDrone.Core/Providers/PostDownloadProvider.cs @@ -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) { diff --git a/NzbDrone.Core/Repository/Episode.cs b/NzbDrone.Core/Repository/Episode.cs index 091a8f89a..a6f4110d3 100644 --- a/NzbDrone.Core/Repository/Episode.cs +++ b/NzbDrone.Core/Repository/Episode.cs @@ -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; } diff --git a/NzbDrone.Core/Repository/Series.cs b/NzbDrone.Core/Repository/Series.cs index ddfd335f6..7084cfcb9 100644 --- a/NzbDrone.Core/Repository/Series.cs +++ b/NzbDrone.Core/Repository/Series.cs @@ -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; } diff --git a/NzbDrone.Core/RootFolders/RootFolder.cs b/NzbDrone.Core/RootFolders/RootFolder.cs index 45f196a06..d3a258c38 100644 --- a/NzbDrone.Core/RootFolders/RootFolder.cs +++ b/NzbDrone.Core/RootFolders/RootFolder.cs @@ -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 UnmappedFolders { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/RootFolders/RootFolderRepository.cs b/NzbDrone.Core/RootFolders/RootFolderRepository.cs index c71ee7a3b..964e91f30 100644 --- a/NzbDrone.Core/RootFolders/RootFolderRepository.cs +++ b/NzbDrone.Core/RootFolders/RootFolderRepository.cs @@ -7,8 +7,7 @@ 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, IRootFolderRepository { public RootFolderRepository(IObjectDatabase objectDatabase) @@ -16,10 +15,5 @@ namespace NzbDrone.Core.RootFolders { } - - public RootFolder Add(RootFolder rootFolder) - { - return ObjectDatabase.Insert(rootFolder); - } } } diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index bc21e7ab4..7544cd27e 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -38,8 +38,11 @@ namespace NzbDrone.Core.RootFolders rootFolders.ForEach(folder => { - folder.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(folder.Path)); - folder.UnmappedFolders = GetUnmappedFolders(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) {