fixed Ajax errors not being displayed in the UI.

pull/2/head
Keivan Beigi 12 years ago
parent b79f695564
commit 32d6909045

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Common.Exceptions
{
public abstract class NzbDroneException : ApplicationException
{
protected NzbDroneException(string message, params object[] args)
: base(string.Format(message, args))
{
}
protected NzbDroneException(string message)
: base(message)
{
}
}
}

@ -106,6 +106,7 @@
<Compile Include="EnvironmentInfo\BuildInfo.cs" /> <Compile Include="EnvironmentInfo\BuildInfo.cs" />
<Compile Include="EnvironmentInfo\RuntimeInfo.cs" /> <Compile Include="EnvironmentInfo\RuntimeInfo.cs" />
<Compile Include="EnvironmentInfo\OsInfo.cs" /> <Compile Include="EnvironmentInfo\OsInfo.cs" />
<Compile Include="Exceptions\NzbDroneException.cs" />
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" /> <Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
<Compile Include="Instrumentation\ExceptronTarget.cs" /> <Compile Include="Instrumentation\ExceptronTarget.cs" />
<Compile Include="Messaging\LimitedConcurrencyLevelTaskScheduler.cs" /> <Compile Include="Messaging\LimitedConcurrencyLevelTaskScheduler.cs" />
@ -176,6 +177,7 @@
<Name>Exceptron.Client</Name> <Name>Exceptron.Client</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -215,7 +215,7 @@
<Compile Include="Framework\TestDbHelper.cs" /> <Compile Include="Framework\TestDbHelper.cs" />
<Compile Include="ParserTests\ParserFixture.cs" /> <Compile Include="ParserTests\ParserFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Qualities\QualityProfileFixture.cs" /> <Compile Include="Qualities\QualityProfileServiceFixture.cs" />
<Compile Include="TvTests\SeriesServiceFixture.cs" /> <Compile Include="TvTests\SeriesServiceFixture.cs" />
<Compile Include="UpdateTests\UpdatePackageProviderFixture.cs" /> <Compile Include="UpdateTests\UpdatePackageProviderFixture.cs" />
<Compile Include="XbmcVersionTests.cs" /> <Compile Include="XbmcVersionTests.cs" />

@ -1,39 +0,0 @@
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Qualities
{
[TestFixture]
public class QualityProfileFixture : CoreTest<QualityProfileService>
{
[Test]
public void Init_should_add_two_profiles()
{
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IQualityProfileRepository>()
.Verify(v => v.Insert(It.IsAny<QualityProfile>()), Times.Exactly(4));
}
[Test]
//This confirms that new profiles are added only if no other profiles exists.
//We don't want to keep adding them back if a user deleted them on purpose.
public void Init_should_skip_if_any_profiles_already_exist()
{
Mocker.GetMock<IQualityProfileRepository>()
.Setup(s => s.All())
.Returns(Builder<QualityProfile>.CreateListOfSize(2).Build().ToList());
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IQualityProfileRepository>()
.Verify(v => v.Insert(It.IsAny<QualityProfile>()), Times.Never());
}
}
}

@ -0,0 +1,75 @@
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.Qualities
{
[TestFixture]
public class QualityProfileServiceFixture : CoreTest<QualityProfileService>
{
[Test]
public void Init_should_add_two_profiles()
{
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IQualityProfileRepository>()
.Verify(v => v.Insert(It.IsAny<QualityProfile>()), Times.Exactly(4));
}
[Test]
//This confirms that new profiles are added only if no other profiles exists.
//We don't want to keep adding them back if a user deleted them on purpose.
public void Init_should_skip_if_any_profiles_already_exist()
{
Mocker.GetMock<IQualityProfileRepository>()
.Setup(s => s.All())
.Returns(Builder<QualityProfile>.CreateListOfSize(2).Build().ToList());
Subject.Handle(new ApplicationStartedEvent());
Mocker.GetMock<IQualityProfileRepository>()
.Verify(v => v.Insert(It.IsAny<QualityProfile>()), Times.Never());
}
[Test]
public void should_not_be_able_to_delete_profile_if_assigned_to_series()
{
var seriesList = Builder<Series>.CreateListOfSize(3)
.Random(1)
.With(c => c.QualityProfileId = 2)
.Build().ToList();
Mocker.GetMock<ISeriesService>().Setup(c => c.GetAllSeries()).Returns(seriesList);
Assert.Throws<QualityProfileInUseException>(() => Subject.Delete(2));
Mocker.GetMock<IQualityProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
}
[Test]
public void should_delete_profile_if_not_assigned_to_series()
{
var seriesList = Builder<Series>.CreateListOfSize(3)
.All()
.With(c => c.QualityProfileId = 2)
.Build().ToList();
Mocker.GetMock<ISeriesService>().Setup(c => c.GetAllSeries()).Returns(seriesList);
Subject.Delete(1);
Mocker.GetMock<IQualityProfileRepository>().Verify(c => c.Delete(1), Times.Once());
}
}
}

@ -1,10 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using NLog; using NLog;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Tv.Events; using NzbDrone.Core.Tv.Events;
namespace NzbDrone.Core.MediaFiles namespace NzbDrone.Core.MediaFiles

@ -376,6 +376,7 @@
<Compile Include="Parser\Parser.cs" /> <Compile Include="Parser\Parser.cs" />
<Compile Include="Parser\ParsingService.cs" /> <Compile Include="Parser\ParsingService.cs" />
<Compile Include="Providers\UpdateXemMappings.cs" /> <Compile Include="Providers\UpdateXemMappings.cs" />
<Compile Include="Qualities\QualityProfileInUseException.cs" />
<Compile Include="Qualities\QualitySizeRepository.cs" /> <Compile Include="Qualities\QualitySizeRepository.cs" />
<Compile Include="Qualities\QualityProfileRepository.cs" /> <Compile Include="Qualities\QualityProfileRepository.cs" />
<Compile Include="SeriesStats\SeriesStatisticsService.cs" /> <Compile Include="SeriesStats\SeriesStatisticsService.cs" />

@ -0,0 +1,13 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.Qualities
{
public class QualityProfileInUseException : NzbDroneException
{
public QualityProfileInUseException(int profileId)
: base("QualityProfile [{0}] is in use.", profileId)
{
}
}
}

@ -3,6 +3,7 @@ using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Qualities namespace NzbDrone.Core.Qualities
@ -19,11 +20,13 @@ namespace NzbDrone.Core.Qualities
public class QualityProfileService : IQualityProfileService, IHandle<ApplicationStartedEvent> public class QualityProfileService : IQualityProfileService, IHandle<ApplicationStartedEvent>
{ {
private readonly IQualityProfileRepository _qualityProfileRepository; private readonly IQualityProfileRepository _qualityProfileRepository;
private readonly ISeriesService _seriesService;
private readonly Logger _logger; private readonly Logger _logger;
public QualityProfileService(IQualityProfileRepository qualityProfileRepository, Logger logger) public QualityProfileService(IQualityProfileRepository qualityProfileRepository, ISeriesService seriesService, Logger logger)
{ {
_qualityProfileRepository = qualityProfileRepository; _qualityProfileRepository = qualityProfileRepository;
_seriesService = seriesService;
_logger = logger; _logger = logger;
} }
@ -39,6 +42,11 @@ namespace NzbDrone.Core.Qualities
public void Delete(int id) public void Delete(int id)
{ {
if (_seriesService.GetAllSeries().Any(c => c.QualityProfileId == id))
{
throw new QualityProfileInUseException(id);
}
_qualityProfileRepository.Delete(id); _qualityProfileRepository.Delete(id);
} }

@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;

@ -30,16 +30,13 @@ require.config({
shim: { shim: {
$: { $: {
deps :
[
'Instrumentation/ErrorHandler'
],
exports: '$', exports: '$',
init: function () { init: function () {
require( require(
[ [
'jQuery/ToTheTop' 'jQuery/ToTheTop',
'Instrumentation/ErrorHandler'
]); ]);
} }

Loading…
Cancel
Save