From ea643630ed9bb3833fc6b2f5e0c3c1496b08c425 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 19 Jun 2011 11:56:32 -0700 Subject: [PATCH] Fixed dbBenchmark tests --- NzbDrone.Core.Test/dbBenchmark.cs | 72 +++++++++++++++++++------------ 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/NzbDrone.Core.Test/dbBenchmark.cs b/NzbDrone.Core.Test/dbBenchmark.cs index 1de9d634f..60eb37b88 100644 --- a/NzbDrone.Core.Test/dbBenchmark.cs +++ b/NzbDrone.Core.Test/dbBenchmark.cs @@ -8,13 +8,14 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; +using PetaPoco; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - [Ignore] public class DbBenchmark : TestBase { const int Episodes_Per_Season = 20; @@ -22,6 +23,7 @@ namespace NzbDrone.Core.Test private readonly List seriesIds = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; private readonly List episodes = new List(); private readonly List files = new List(); + private IDatabase db; [TestFixtureSetUp] @@ -30,8 +32,18 @@ namespace NzbDrone.Core.Test base.Setup(); + db = MockLib.GetEmptyDatabase(); int currentFileId = 0; + + var qulityProfile = new QualityProfile + { + Name = "TestProfile", + Allowed = new List { QualityTypes.DVD, QualityTypes.Bluray1080p }, + Cutoff = QualityTypes.DVD + }; + db.Insert(qulityProfile); + foreach (var _seriesId in seriesIds) { int seriesId = _seriesId; @@ -40,7 +52,7 @@ namespace NzbDrone.Core.Test .With(s => s.Monitored = true) .Build(); - //repo.Add(series); + db.Insert(series); foreach (var _seasonNumber in seasonsNumbers) { @@ -52,8 +64,7 @@ namespace NzbDrone.Core.Test { var epFile = Builder.CreateNew() .With(e => e.SeriesId = seriesId) - .With(e => e.SeriesId = seriesId) - .And(e => e.SeasonNumber = _seasonNumber) + .And(e => e.SeasonNumber = _seasonNumber) .And(e => e.Path = Guid.NewGuid().ToString()) .Build(); @@ -83,30 +94,32 @@ namespace NzbDrone.Core.Test } - //repo.AddMany(episodes); - //repo.AddMany(files); + db.InsertMany(episodes); + db.InsertMany(files); } [Test] public void get_episode_by_series_seasons_episode_x5000() { - var epProvider = new EpisodeProvider(null, null, null); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + mocker.Resolve(); + var epProvider = mocker.Resolve(); Thread.Sleep(1000); - var random = new Random(); Console.WriteLine("Starting Test"); var sw = Stopwatch.StartNew(); for (int i = 0; i < 5000; i++) { - epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10)).Should().NotBeNull(); + var ep = epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10)); + ep.Series.Should().NotBeNull(); } - sw.Stop(); Console.WriteLine("Took " + sw.Elapsed); @@ -115,7 +128,11 @@ namespace NzbDrone.Core.Test [Test] public void get_episode_by_series_seasons_x1000() { - var epProvider = new EpisodeProvider(null, null, null); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + mocker.Resolve(); + + var epProvider = mocker.Resolve(); Thread.Sleep(1000); @@ -140,8 +157,9 @@ namespace NzbDrone.Core.Test public void get_episode_file_count_x100() { var mocker = new AutoMoqer(); - //mocker.SetConstant(repo); - mocker.SetConstant(mocker.Resolve()); + mocker.SetConstant(db); + mocker.Resolve(); + mocker.Resolve(); var mediaProvider = mocker.Resolve(); @@ -163,13 +181,14 @@ namespace NzbDrone.Core.Test Console.WriteLine("Took " + sw.Elapsed); } - [Test] - public void get_season_count_x5000() + public void get_episode_file_count_x1000() { var mocker = new AutoMoqer(); - //mocker.SetConstant(repo); - var provider = mocker.Resolve(); + mocker.SetConstant(db); + mocker.Resolve(); + mocker.Resolve(); + var mediaProvider = mocker.Resolve(); Thread.Sleep(1000); @@ -179,9 +198,9 @@ namespace NzbDrone.Core.Test Console.WriteLine("Starting Test"); var sw = Stopwatch.StartNew(); - for (int i = 0; i < 5000; i++) + for (int i = 0; i < 1000; i++) { - provider.GetSeasons(random.Next(1, 10)).Should().HaveSameCount(seasonsNumbers); + mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull(); } @@ -192,12 +211,11 @@ namespace NzbDrone.Core.Test [Test] - public void get_episode_file_count_x10() + public void get_season_count_x5000() { var mocker = new AutoMoqer(); - //mocker.SetConstant(repo); - mocker.SetConstant(mocker.Resolve()); - var provider = mocker.Resolve(); + mocker.SetConstant(db); + var provider = mocker.Resolve(); Thread.Sleep(1000); @@ -207,11 +225,9 @@ namespace NzbDrone.Core.Test Console.WriteLine("Starting Test"); var sw = Stopwatch.StartNew(); - for (int i = 0; i < 100; i++) + for (int i = 0; i < 5000; i++) { - var result = provider.GetEpisodeFilesCount(random.Next(1, 10)); - result.Item1.Should().NotBe(0); - result.Item2.Should().NotBe(0); + provider.GetSeasons(random.Next(1, 10)).Should().HaveSameCount(seasonsNumbers); } @@ -220,5 +236,7 @@ namespace NzbDrone.Core.Test Console.WriteLine("Took " + sw.Elapsed); } + + } }