fix(notifications): 🐛 This is a fix for some of the duplicate notification issues #3825

pull/4457/merge
tidusjar 2 years ago
parent 53bff29795
commit 22bb4226ea

@ -0,0 +1,42 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq.AutoMock;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Ombi.Notifications.Tests
{
[TestFixture]
public class NotificationServiceTests
{
private NotitficationServiceTestFacade _subject;
[SetUp]
public void Setup()
{
var mocker = new AutoMocker();
mocker.Use(NullLogger.Instance);
_subject = mocker.CreateInstance<NotitficationServiceTestFacade>();
}
[Test]
public void PopulateAgentsTests()
{
Assert.That(_subject.Agents, Has.Count.EqualTo(12));
Assert.That(_subject.Agents.DistinctBy(x => x.NotificationName).ToList(), Has.Count.EqualTo(12));
}
}
public class NotitficationServiceTestFacade : NotificationService
{
public NotitficationServiceTestFacade(IServiceProvider provider, ILogger<NotificationService> log) : base(provider, log)
{
}
public List<INotification> Agents => base.NotificationAgents;
}
}

@ -13,6 +13,7 @@
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<packagereference Include="Microsoft.NET.Test.Sdk" Version="16.8.0"></packagereference>
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="Moq.AutoMock" Version="0.4.0" />
</ItemGroup>
<ItemGroup>

@ -33,7 +33,7 @@ namespace Ombi.Notifications
AlbumRepository = album;
UserNotificationPreferences = notificationUserPreferences;
_userManager = um;
Settings.ClearCache();
Settings?.ClearCache();
}
protected ISettingsService<T> Settings { get; }
@ -64,7 +64,11 @@ namespace Ombi.Notifications
public async Task NotifyAsync(NotificationOptions model, Settings.Settings.Models.Settings settings)
{
if (settings == null) await NotifyAsync(model);
if (settings == null)
{
await NotifyAsync(model);
return;
}
var notificationSettings = (T)settings;
@ -114,15 +118,13 @@ namespace Ombi.Notifications
case NotificationType.IssueComment:
await IssueComment(model, notificationSettings);
break;
case NotificationType.AdminNote:
case NotificationType.PartiallyAvailable:
await PartiallyAvailable(model, notificationSettings);
break;
case NotificationType.AdminNote:
case NotificationType.WelcomeEmail:
break;
case NotificationType.Newsletter:
break;
case NotificationType.PartiallyAvailable:
await PartiallyAvailable(model, notificationSettings);
break;
default:
throw new ArgumentOutOfRangeException();
}

@ -23,7 +23,7 @@ namespace Ombi.Notifications
PopulateAgents();
}
private List<INotification> NotificationAgents { get; }
protected List<INotification> NotificationAgents { get; }
private ILogger<NotificationService> Log { get; }
/// <summary>
@ -55,7 +55,7 @@ namespace Ombi.Notifications
}
private void PopulateAgents()
protected void PopulateAgents()
{
var baseSearchType = typeof(BaseNotification<>).Name;

Loading…
Cancel
Save