diff --git a/NzbDrone.Common.Test/EventingTests/EventAggregatorTests.cs b/NzbDrone.Common.Test/EventingTests/EventAggregatorTests.cs index 1c9ea2788..ccb6e0275 100644 --- a/NzbDrone.Common.Test/EventingTests/EventAggregatorTests.cs +++ b/NzbDrone.Common.Test/EventingTests/EventAggregatorTests.cs @@ -10,20 +10,12 @@ namespace NzbDrone.Common.Test.EventingTests [TestFixture] public class ServiceNameFixture : TestBase { - private EventAggregator _aggregator; - - [SetUp] - public void Setup() - { - _aggregator = new EventAggregator(TestLogger, null); - } - [Test] public void should_publish_event_to_handlers() { var intHandler = new Mock>(); - _aggregator = new EventAggregator(TestLogger, new List { intHandler.Object }); - _aggregator.Publish(12); + var aggregator = new EventAggregator(TestLogger, new List { intHandler.Object }); + aggregator.Publish(12); intHandler.Verify(c => c.Handle(12), Times.Once()); } @@ -31,23 +23,23 @@ public void should_publish_event_to_handlers() [Test] public void should_publish_to_more_than_one_handler() { - var intHandler1 =new Mock>(); + var intHandler1 = new Mock>(); var intHandler2 = new Mock>(); - _aggregator = new EventAggregator(TestLogger, new List { intHandler1.Object, intHandler2.Object }); - _aggregator.Publish(12); + var aggregator = new EventAggregator(TestLogger, new List { intHandler1.Object, intHandler2.Object }); + aggregator.Publish(12); intHandler1.Verify(c => c.Handle(12), Times.Once()); intHandler2.Verify(c => c.Handle(12), Times.Once()); } - + [Test] public void should_not_publish_to_incompatible_handlers() { var intHandler = new Mock>(); var stringHandler = new Mock>(); - _aggregator = new EventAggregator(TestLogger, new List { intHandler.Object, stringHandler.Object }); + var aggregator = new EventAggregator(TestLogger, new List { intHandler.Object, stringHandler.Object }); - _aggregator.Publish(12); + aggregator.Publish(12); intHandler.Verify(c => c.Handle(12), Times.Once()); stringHandler.Verify(c => c.Handle(It.IsAny()), Times.Never()); diff --git a/NzbDrone.Common/Eventing/EventAggregator.cs b/NzbDrone.Common/Eventing/EventAggregator.cs index 44648525b..c28ec283a 100644 --- a/NzbDrone.Common/Eventing/EventAggregator.cs +++ b/NzbDrone.Common/Eventing/EventAggregator.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.EnsureThat; namespace NzbDrone.Common.Eventing { @@ -11,6 +12,7 @@ public class EventAggregator : IEventAggregator public EventAggregator(Logger logger, IEnumerable handlers) { + Ensure.That(() => handlers).HasItems(); _logger = logger; _handlers = handlers; } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 23bfb734f..ce30b651c 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -306,6 +306,7 @@ + diff --git a/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs b/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs new file mode 100644 index 000000000..d7ddc95c6 --- /dev/null +++ b/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs @@ -0,0 +1,12 @@ +namespace NzbDrone.Core.Tv.Events +{ + public class SeriesAddedEvent + { + public Series Series { get; private set; } + + public SeriesAddedEvent(Series series) + { + Series = series; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 344652521..b67e0d621 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -4,9 +4,11 @@ using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.EnsureThat; +using NzbDrone.Common.Eventing; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv { @@ -26,6 +28,7 @@ public class SeriesService : ISeriesService private readonly TvDbProvider _tvDbProvider; private readonly MetadataProvider _metadataProvider; private readonly TvRageMappingProvider _tvRageMappingProvider; + private readonly IEventAggregator _eventAggregator; private static readonly Logger logger = LogManager.GetCurrentClassLogger(); @@ -33,7 +36,7 @@ public class SeriesService : ISeriesService public SeriesService(ISeriesRepository seriesRepository, ConfigProvider configProviderProvider, TvDbProvider tvDbProviderProvider, SceneMappingProvider sceneNameMappingProvider, MetadataProvider metadataProvider, - TvRageMappingProvider tvRageMappingProvider) + TvRageMappingProvider tvRageMappingProvider, IEventAggregator eventAggregator) { _seriesRepository = seriesRepository; _configProvider = configProviderProvider; @@ -41,6 +44,7 @@ public SeriesService(ISeriesRepository seriesRepository, ConfigProvider configPr _sceneNameMappingProvider = sceneNameMappingProvider; _metadataProvider = metadataProvider; _tvRageMappingProvider = tvRageMappingProvider; + _eventAggregator = eventAggregator; } @@ -128,6 +132,8 @@ public void AddSeries(string title, string path, int tvDbSeriesId, int qualityPr repoSeries.CustomStartDate = airedAfter; _seriesRepository.Insert(repoSeries); + + _eventAggregator.Publish(new SeriesAddedEvent(repoSeries)); } @@ -156,7 +162,7 @@ public void UpdateFromSeriesEditor(IList editedSeries) /// /// The TVDB AirsTime /// String that contains the AirTimes - + private static readonly Regex timeRegex = new Regex(@"^(?