mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Refactored the Notification service to how it should have really been done in the first place.
This commit is contained in:
parent
840deb6161
commit
3fe1f13bd1
17 changed files with 220 additions and 166 deletions
|
@ -1,33 +1,37 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: NotificationServiceTests.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
/************************************************************************
|
||||
Copyright (c) 2016 Jamie Rees
|
||||
File: NotificationServiceTests.cs
|
||||
Created By: Jamie Rees
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Moq;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using PlexRequests.Services.Interfaces;
|
||||
using PlexRequests.Services.Notification;
|
||||
|
||||
namespace PlexRequests.Services.Tests
|
||||
|
@ -35,9 +39,15 @@ namespace PlexRequests.Services.Tests
|
|||
[TestFixture]
|
||||
public class NotificationServiceTests
|
||||
{
|
||||
public NotificationService NotificationService { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
NotificationService = new NotificationService();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Need to rework due to static class")]
|
||||
public void SubscribeNewNotifier()
|
||||
{
|
||||
var notificationMock = new Mock<INotification>();
|
||||
|
@ -49,7 +59,6 @@ namespace PlexRequests.Services.Tests
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Need to rework due to static class")]
|
||||
public void SubscribeExistingNotifier()
|
||||
{
|
||||
var notificationMock1 = new Mock<INotification>();
|
||||
|
@ -68,7 +77,6 @@ namespace PlexRequests.Services.Tests
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Need to rework due to static class")]
|
||||
public void UnSubscribeMissingNotifier()
|
||||
{
|
||||
var notificationMock = new Mock<INotification>();
|
||||
|
@ -79,7 +87,6 @@ namespace PlexRequests.Services.Tests
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Need to rework due to static class")]
|
||||
public void UnSubscribeNotifier()
|
||||
{
|
||||
var notificationMock = new Mock<INotification>();
|
||||
|
@ -92,17 +99,15 @@ namespace PlexRequests.Services.Tests
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Need to rework due to static class")]
|
||||
public void PublishWithNoObservers()
|
||||
{
|
||||
Assert.DoesNotThrow(
|
||||
() =>
|
||||
{ NotificationService.Publish(new NotificationModel()); });
|
||||
Assert.DoesNotThrowAsync(
|
||||
async() =>
|
||||
{ await NotificationService.Publish(new NotificationModel()); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Need to rework due to static class")]
|
||||
public void PublishAllNotifiers()
|
||||
public async Task PublishAllNotifiers()
|
||||
{
|
||||
var notificationMock1 = new Mock<INotification>();
|
||||
var notificationMock2 = new Mock<INotification>();
|
||||
|
@ -112,11 +117,21 @@ namespace PlexRequests.Services.Tests
|
|||
NotificationService.Subscribe(notificationMock2.Object);
|
||||
|
||||
Assert.That(NotificationService.Observers.Count, Is.EqualTo(2));
|
||||
var model = new NotificationModel {Title = "abc", Body = "test"};
|
||||
NotificationService.Publish(model);
|
||||
var model = new NotificationModel { Title = "abc", Body = "test" };
|
||||
await NotificationService.Publish(model);
|
||||
|
||||
notificationMock1.Verify(x => x.Notify(model), Times.Once);
|
||||
notificationMock2.Verify(x => x.Notify(model), Times.Once);
|
||||
notificationMock1.Verify(x => x.NotifyAsync(model), Times.Once);
|
||||
notificationMock2.Verify(x => x.NotifyAsync(model), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PublishWithException()
|
||||
{
|
||||
var notificationMock = new Mock<INotification>();
|
||||
notificationMock.Setup(x => x.NotifyAsync(It.IsAny<NotificationModel>())).Throws<Exception>();
|
||||
notificationMock.SetupGet(x => x.NotificationName).Returns("Notification1");
|
||||
NotificationService.Subscribe(notificationMock.Object);
|
||||
await NotificationService.Publish(new NotificationModel());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue