From cc0ed59e7b807a30d11f75ac776a959d95196ced Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 5 Jun 2013 23:06:50 -0700 Subject: [PATCH] added quality size repo fixture --- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 1 + .../Qualities/QualitySizeRepositoryFixture.cs | 41 +++++++++++++++++++ .../Qualities/QualitySizeRepository.cs | 12 +++++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 NzbDrone.Core.Test/Qualities/QualitySizeRepositoryFixture.cs diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index f52f2b163..ed1deb168 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -150,6 +150,7 @@ + diff --git a/NzbDrone.Core.Test/Qualities/QualitySizeRepositoryFixture.cs b/NzbDrone.Core.Test/Qualities/QualitySizeRepositoryFixture.cs new file mode 100644 index 000000000..78cf675d5 --- /dev/null +++ b/NzbDrone.Core.Test/Qualities/QualitySizeRepositoryFixture.cs @@ -0,0 +1,41 @@ +using System; +using NUnit.Framework; +using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Qualities; +using NzbDrone.Core.Test.Framework; +using FluentAssertions; + +namespace NzbDrone.Core.Test.Qualities +{ + [TestFixture] + + public class QualitySizeRepositoryFixture : DbTest + { + + + + [SetUp] + public void Setup() + { + Mocker.SetConstant(Subject); + Mocker.Resolve().Handle(new ApplicationStartedEvent()); + } + + + [Test] + public void should_get_quality_size_by_id() + { + var size = Subject.GetByQualityId(Quality.Bluray1080p.Id); + + size.Should().NotBeNull(); + } + + [Test] + public void should_throw_with_id_if_not_exist() + { + var id = 123; + Assert.Throws(()=> Subject.GetByQualityId(id)).Message.Contains(id.ToString()); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Qualities/QualitySizeRepository.cs b/NzbDrone.Core/Qualities/QualitySizeRepository.cs index 2f62a9db2..c7f70f9e0 100644 --- a/NzbDrone.Core/Qualities/QualitySizeRepository.cs +++ b/NzbDrone.Core/Qualities/QualitySizeRepository.cs @@ -1,4 +1,5 @@ -using System.Data; +using System; +using System.Data; using System.Linq; using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; @@ -19,7 +20,14 @@ namespace NzbDrone.Core.Qualities public QualitySize GetByQualityId(int qualityId) { - return Query.Single(q => q.QualityId == qualityId); + try + { + return Query.Single(q => q.QualityId == qualityId); + } + catch (InvalidOperationException e) + { + throw new InvalidOperationException("Sequence contains no element with qualityId = " + qualityId.ToString()); + } } } }