From 35cb7e55c70bf267087275b53501a1f23d7a51db Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Mon, 4 Mar 2013 17:47:51 -0800 Subject: [PATCH] cleaned up some tests. --- NzbDrone.App.Test/CentralDispatchTests.cs | 44 ----- NzbDrone.App.Test/NzbDrone.App.Test.csproj | 1 - NzbDrone.Backbone/NzbDrone.Backbone.csproj | 2 +- ...ryFixture.cs => BasicRepositoryFixture.cs} | 39 +++-- .../Datastore/ObjectDatabaseFixture.cs | 6 +- .../MediaFileRepositoryFixture.cs | 82 ++++++++++ .../MediaFileTests/MediaFileServiceTest.cs | 154 +----------------- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 3 +- NzbDrone.Core/Datastore/SiaqodbProxy.cs | 3 +- 9 files changed, 116 insertions(+), 218 deletions(-) delete mode 100644 NzbDrone.App.Test/CentralDispatchTests.cs rename NzbDrone.Core.Test/Datastore/{SimpleRepositoryFixture.cs => BasicRepositoryFixture.cs} (59%) create mode 100644 NzbDrone.Core.Test/MediaFileTests/MediaFileRepositoryFixture.cs diff --git a/NzbDrone.App.Test/CentralDispatchTests.cs b/NzbDrone.App.Test/CentralDispatchTests.cs deleted file mode 100644 index 2093f28a6..000000000 --- a/NzbDrone.App.Test/CentralDispatchTests.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Autofac; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Test.Common; - -namespace NzbDrone.App.Test -{ - [TestFixture] - public class CentralDispatchTests : TestBase - { - [Test] - public void Kernel_can_get_kernel() - { - NzbDroneBootstrapper.Container.Should().NotBeNull(); - } - - [Test] - public void Kernel_should_return_same_kernel() - { - var firstKernel = NzbDroneBootstrapper.Container; - var secondKernel = NzbDroneBootstrapper.Container; - - firstKernel.Should().BeSameAs(secondKernel); - } - - [Test] - public void Kernel_should_be_able_to_resolve_ApplicationServer() - { - var appServer = NzbDroneBootstrapper.Container.Resolve(); - - appServer.Should().NotBeNull(); - } - - [Test] - public void Kernel_should_resolve_same_ApplicationServer_instance() - { - var appServer1 = NzbDroneBootstrapper.Container.Resolve(); - var appServer2 = NzbDroneBootstrapper.Container.Resolve(); - - appServer1.Should().BeSameAs(appServer2); - } - - } -} diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj index 5af7bfb77..de485a7a0 100644 --- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj +++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj @@ -81,7 +81,6 @@ - diff --git a/NzbDrone.Backbone/NzbDrone.Backbone.csproj b/NzbDrone.Backbone/NzbDrone.Backbone.csproj index 9053e7d92..10d427023 100644 --- a/NzbDrone.Backbone/NzbDrone.Backbone.csproj +++ b/NzbDrone.Backbone/NzbDrone.Backbone.csproj @@ -147,7 +147,7 @@ - + diff --git a/NzbDrone.Core.Test/Datastore/SimpleRepositoryFixture.cs b/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs similarity index 59% rename from NzbDrone.Core.Test/Datastore/SimpleRepositoryFixture.cs rename to NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs index 57d49f689..ff9e009ca 100644 --- a/NzbDrone.Core.Test/Datastore/SimpleRepositoryFixture.cs +++ b/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs @@ -8,8 +8,7 @@ using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Datastore { - - public class SampleType : ModelBase + public class BaiscType : ModelBase { public string Name { get; set; } public string Tilte { get; set; } @@ -17,25 +16,25 @@ namespace NzbDrone.Core.Test.Datastore } [TestFixture] - public class SimpleRepositoryFixture : ObjectDbTest,SampleType> + public class BasicRepositoryFixture : ObjectDbTest,BaiscType> { - private SampleType sampleType; + private BaiscType _baiscType; [SetUp] public void Setup() { - sampleType = Builder - .CreateNew() - .With(c => c.Id = 0) - .Build(); + _baiscType = Builder + .CreateNew() + .With(c => c.Id = 0) + .Build(); } [Test] public void should_be_able_to_add() { - Subject.Insert(sampleType); + Subject.Insert(_baiscType); Subject.All().Should().HaveCount(1); } @@ -44,21 +43,21 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void should_be_able_to_delete_model() { - Subject.Insert(sampleType); + Subject.Insert(_baiscType); Subject.All().Should().HaveCount(1); - Subject.Delete(sampleType.Id); + Subject.Delete(_baiscType.Id); Subject.All().Should().BeEmpty(); } [Test] public void should_be_able_to_find_by_id() { - Subject.Insert(sampleType); - Subject.Get(sampleType.Id) - .ShouldHave() - .AllProperties() - .EqualTo(sampleType); + Subject.Insert(_baiscType); + Subject.Get(_baiscType.Id) + .ShouldHave() + .AllProperties() + .EqualTo(_baiscType); } [Test] @@ -73,5 +72,13 @@ namespace NzbDrone.Core.Test.Datastore { Subject.All().Should().BeEmpty(); } + + + [Test] + public void should_be_able_to_call_ToList_on_empty_quariable() + { + Subject.All().ToList().Should().BeEmpty(); + + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 1e6689264..de8726eee 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -205,9 +205,9 @@ namespace NzbDrone.Core.Test.Datastore Db.Insert(childModel); - _childModel.A = "A_New"; - _childModel.B = 2; - _childModel.C = 2; + childModel.A = "A_New"; + childModel.B = 2; + childModel.C = 2; Db.UpdateField(childModel, "B"); diff --git a/NzbDrone.Core.Test/MediaFileTests/MediaFileRepositoryFixture.cs b/NzbDrone.Core.Test/MediaFileTests/MediaFileRepositoryFixture.cs new file mode 100644 index 000000000..4615a3091 --- /dev/null +++ b/NzbDrone.Core.Test/MediaFileTests/MediaFileRepositoryFixture.cs @@ -0,0 +1,82 @@ +using System.Linq; +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.MediaFiles; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.MediaFileTests +{ + [TestFixture] + public class MediaFileRepositoryFixture : ObjectDbTest + { + [Test] + public void get_files_by_series() + { + var files = Builder.CreateListOfSize(10) + .All() + .With(c => c.Id = 0) + .Random(4) + .With(s => s.SeriesId = 12) + .Build(); + + + Db.InsertMany(files); + + var seriesFiles = Subject.GetFilesBySeries(12); + + seriesFiles.Should().HaveCount(4); + seriesFiles.Should().OnlyContain(c => c.SeriesId == 12); + + } + + [Test] + public void get_files_by_season() + { + var files = Builder.CreateListOfSize(20) + .All() + .With(c => c.Id = 0) + .With(s => s.SeasonNumber = 10) + .TheFirst(10) + .With(c => c.SeriesId = 1) + .TheNext(10) + .With(c => c.SeriesId = 2) + .Random(10) + .With(s => s.SeasonNumber = 20) + .Build(); + + + Db.InsertMany(files); + + + Subject.GetFilesBySeason(1, 20).Should().OnlyContain(c => c.SeriesId == 1 && c.SeasonNumber == 20); + } + + + [Test] + public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database() + { + Subject.GetFileByPath(@"C:\Test\EpisodeFile.avi").Should().BeNull(); + } + + [Test] + public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database() + { + var path = @"C:\Test\EpisodeFile.avi"; + + var episodeFile = Builder.CreateNew() + .With(f => f.Id = 0) + .With(f => f.Path = path.NormalizePath()) + .Build(); + + Subject.Insert(episodeFile); + + var file = Subject.GetFileByPath(path); + + //Resolve + file.Should().NotBeNull(); + file.Path.Should().Be(path.NormalizePath()); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs index a5db8ec50..f73b08311 100644 --- a/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs +++ b/NzbDrone.Core.Test/MediaFileTests/MediaFileServiceTest.cs @@ -1,112 +1,23 @@ -// ReSharper disable RedundantUsingDirective - using System.Linq; -using System; -using System.Collections.Generic; using FizzWare.NBuilder; using FluentAssertions; -using Moq; using NUnit.Framework; -using NzbDrone.Common; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; -using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.MediaFileTests { [TestFixture] - // ReSharper disable InconsistentNaming - public class MediaFileServiceTest : ObjectDbTest + public class MediaFileServiceTest : CoreTest { - [Test] - public void get_series_files() - { - var firstSeriesFiles = Builder.CreateListOfSize(10) - .All() - .With(c => c.Quality = Quality.SDTV) - .With(s => s.SeriesId = 12).Build(); - - var secondSeriesFiles = Builder.CreateListOfSize(10) - .All() - .With(c => c.Quality = Quality.SDTV) - .With(s => s.SeriesId = 20).Build(); - - - - - Db.InsertMany(firstSeriesFiles); - Db.InsertMany(secondSeriesFiles); - - var result = Mocker.Resolve().GetFilesBySeries(12); - - - result.Should().HaveSameCount(firstSeriesFiles); - } - - [Test] - public void get_season_files() - { - var firstSeriesFiles = Builder.CreateListOfSize(10) - .All() - .With(c => c.Quality = Quality.SDTV) - .With(s => s.SeriesId = 12) - .With(s => s.SeasonNumber = 1) - .Build(); - - var secondSeriesFiles = Builder.CreateListOfSize(10) - .All() - .With(c => c.Quality = Quality.SDTV) - .With(s => s.SeriesId = 12) - .With(s => s.SeasonNumber = 2) - .Build(); - - - - Db.InsertMany(firstSeriesFiles); - Db.InsertMany(secondSeriesFiles); - - var result = Mocker.Resolve().GetFilesBySeason(12, 1); - - result.Should().HaveSameCount(firstSeriesFiles); - } - - [Test] - public void Scan_series_should_skip_series_with_no_episodes() - { - WithStrictMocker(); - - Mocker.GetMock() - .Setup(c => c.GetEpisodeBySeries(12)) - .Returns(new List()); - - - Mocker.GetMock() - .Setup(c => c.FolderExists(It.IsAny())) - .Returns(true); - - var series = Builder.CreateNew() - .With(s => s.Id = 12).Build(); - - //Act - Mocker.Resolve().Scan(series); - - //Assert - Mocker.VerifyAllMocks(); - - } [Test] [TestCase("Law & Order: Criminal Intent - S10E07 - Icarus [HDTV-720p]", "Law & Order- Criminal Intent - S10E07 - Icarus [HDTV-720p]")] public void CleanFileName(string name, string expectedName) { - //Act - var result = MediaFileService.CleanFilename(name); - - //Assert - Assert.AreEqual(expectedName, result); + MediaFileService.CleanFilename(name).Should().Be(expectedName); } [Test] @@ -117,74 +28,15 @@ namespace NzbDrone.Core.Test.MediaFileTests [TestCase("30 Rock - S01E05 - Episode Title", 1, true, "ReallyUglySeasonFolder %s", @"C:\Test\30 Rock\ReallyUglySeasonFolder 1\30 Rock - S01E05 - Episode Title.mkv")] public void CalculateFilePath_SeasonFolder_SingleNumber(string filename, int seasonNumber, bool useSeasonFolder, string seasonFolderFormat, string expectedPath) { - //Setup var fakeSeries = Builder.CreateNew() .With(s => s.Title = "30 Rock") .With(s => s.Path = @"C:\Test\30 Rock") .With(s => s.SeasonFolder = useSeasonFolder) .Build(); - Mocker.GetMock().Setup(e => e.SortingSeasonFolderFormat).Returns(seasonFolderFormat); - //Act - var result = Mocker.Resolve().CalculateFilePath(fakeSeries, 1, filename, ".mkv"); - - //Assert - Assert.AreEqual(expectedPath, result.FullName); - } - - [Test] - public void DeleteEpisodeFile() - { - //Setup - var episodeFiles = Builder - .CreateListOfSize(10) - .All() - .With(c => c.Quality = Quality.SDTV) - .Build(); - - - Db.InsertMany(episodeFiles); - - //Act - Mocker.Resolve().Delete(1); - - - } - - [Test] - public void GetFileByPath_should_return_null_if_file_does_not_exist_in_database() - { - //Setup - - //Act - var result = Mocker.Resolve().GetFileByPath(@"C:\Test\EpisodeFile.avi"); - - //Resolve - result.Should().BeNull(); - } - - [Test] - public void GetFileByPath_should_return_EpisodeFile_if_file_exists_in_database() - { - var path = @"C:\Test\EpisodeFile.avi"; - - //Setup - var episodeFile = Builder.CreateNew() - .With(c => c.Quality = Quality.SDTV) - .With(f => f.Path = path.NormalizePath()) - .Build(); - - var episodeFileId = Convert.ToInt32(Db.Insert(episodeFile)); - - //Act - var result = Mocker.Resolve().GetFileByPath(path); - - //Resolve - result.Should().NotBeNull(); - result.Path.Should().Be(path.NormalizePath()); - result.Id.Should().Be(episodeFileId); + Subject.CalculateFilePath(fakeSeries, 1, filename, ".mkv").FullName.Should().Be(expectedPath); } } } \ 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 ad8c8672e..8b3da67f1 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -131,7 +131,7 @@ - + @@ -141,6 +141,7 @@ + diff --git a/NzbDrone.Core/Datastore/SiaqodbProxy.cs b/NzbDrone.Core/Datastore/SiaqodbProxy.cs index cbb2a743e..de5aadf1c 100644 --- a/NzbDrone.Core/Datastore/SiaqodbProxy.cs +++ b/NzbDrone.Core/Datastore/SiaqodbProxy.cs @@ -119,7 +119,8 @@ namespace NzbDrone.Core.Datastore public void UpdateField(T model, string fieldName) where T : ModelBase { - _db.UpdateObjectBy(model, fieldName); + _db.StoreObjectPartially(model, fieldName); + } private IList DoMany(IEnumerable objects, Func function) where T : ModelBase