mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Merge branch 'km/pm-10564' into km/pm-15084
# Conflicts: # src/Core/Models/PushNotification.cs # src/Core/NotificationHub/NotificationHubPushNotificationService.cs # src/Core/Services/Implementations/AzureQueuePushNotificationService.cs # src/Core/Services/Implementations/NotificationsApiPushNotificationService.cs # src/Core/Services/Implementations/RelayPushNotificationService.cs # src/Core/Services/NoopImplementations/NoopPushNotificationService.cs # test/Core.Test/NotificationHub/NotificationHubPushNotificationServiceTests.cs # test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs
This commit is contained in:
@ -26,6 +26,6 @@ public enum PushType : byte
|
|||||||
|
|
||||||
SyncOrganizations = 17,
|
SyncOrganizations = 17,
|
||||||
|
|
||||||
SyncNotificationCreate = 18,
|
SyncNotification = 18,
|
||||||
SyncNotificationUpdate = 19
|
SyncNotificationStatus = 19
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
|
using Bit.Core.NotificationCenter.Enums;
|
||||||
|
|
||||||
namespace Bit.Core.Models;
|
namespace Bit.Core.Models;
|
||||||
|
|
||||||
@ -46,13 +47,18 @@ public class SyncSendPushNotification
|
|||||||
public DateTime RevisionDate { get; set; }
|
public DateTime RevisionDate { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SyncNotificationPushNotification
|
public class NotificationPushNotification
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
public Priority Priority { get; set; }
|
||||||
|
public bool Global { get; set; }
|
||||||
|
public ClientType ClientType { get; set; }
|
||||||
public Guid? UserId { get; set; }
|
public Guid? UserId { get; set; }
|
||||||
public Guid? OrganizationId { get; set; }
|
public Guid? OrganizationId { get; set; }
|
||||||
public Guid? InstallationId { get; set; }
|
public Guid? InstallationId { get; set; }
|
||||||
public ClientType ClientType { get; set; }
|
public string? Title { get; set; }
|
||||||
|
public string? Body { get; set; }
|
||||||
|
public DateTime CreationDate { get; set; }
|
||||||
public DateTime RevisionDate { get; set; }
|
public DateTime RevisionDate { get; set; }
|
||||||
public DateTime? ReadDate { get; set; }
|
public DateTime? ReadDate { get; set; }
|
||||||
public DateTime? DeletedDate { get; set; }
|
public DateTime? DeletedDate { get; set; }
|
||||||
|
@ -37,7 +37,7 @@ public class CreateNotificationCommand : ICreateNotificationCommand
|
|||||||
|
|
||||||
var newNotification = await _notificationRepository.CreateAsync(notification);
|
var newNotification = await _notificationRepository.CreateAsync(notification);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationCreateAsync(newNotification);
|
await _pushNotificationService.PushNotificationAsync(newNotification);
|
||||||
|
|
||||||
return newNotification;
|
return newNotification;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class CreateNotificationStatusCommand : ICreateNotificationStatusCommand
|
|||||||
|
|
||||||
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, newNotificationStatus);
|
await _pushNotificationService.PushNotificationStatusAsync(notification, newNotificationStatus);
|
||||||
|
|
||||||
return newNotificationStatus;
|
return newNotificationStatus;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
|
|||||||
|
|
||||||
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, newNotificationStatus);
|
await _pushNotificationService.PushNotificationStatusAsync(notification, newNotificationStatus);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
|
|||||||
|
|
||||||
await _notificationStatusRepository.UpdateAsync(notificationStatus);
|
await _notificationStatusRepository.UpdateAsync(notificationStatus);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, notificationStatus);
|
await _pushNotificationService.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
|
|||||||
|
|
||||||
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, newNotificationStatus);
|
await _pushNotificationService.PushNotificationStatusAsync(notification, newNotificationStatus);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
|
|||||||
|
|
||||||
await _notificationStatusRepository.UpdateAsync(notificationStatus);
|
await _notificationStatusRepository.UpdateAsync(notificationStatus);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, notificationStatus);
|
await _pushNotificationService.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,6 @@ public class UpdateNotificationCommand : IUpdateNotificationCommand
|
|||||||
|
|
||||||
await _notificationRepository.ReplaceAsync(notification);
|
await _notificationRepository.ReplaceAsync(notification);
|
||||||
|
|
||||||
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, null);
|
await _pushNotificationService.PushNotificationAsync(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,8 @@ public class Notification : ITableObject<Guid>
|
|||||||
public ClientType ClientType { get; set; }
|
public ClientType ClientType { get; set; }
|
||||||
public Guid? UserId { get; set; }
|
public Guid? UserId { get; set; }
|
||||||
public Guid? OrganizationId { get; set; }
|
public Guid? OrganizationId { get; set; }
|
||||||
[MaxLength(256)]
|
[MaxLength(256)] public string? Title { get; set; }
|
||||||
public string? Title { get; set; }
|
[MaxLength(3000)] public string? Body { get; set; }
|
||||||
public string? Body { get; set; }
|
|
||||||
public DateTime CreationDate { get; set; }
|
public DateTime CreationDate { get; set; }
|
||||||
public DateTime RevisionDate { get; set; }
|
public DateTime RevisionDate { get; set; }
|
||||||
|
|
||||||
|
@ -191,73 +191,81 @@ public class NotificationHubPushNotificationService : IPushNotificationService
|
|||||||
await PushAuthRequestAsync(authRequest, PushType.AuthRequestResponse);
|
await PushAuthRequestAsync(authRequest, PushType.AuthRequestResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationCreateAsync(Notification notification)
|
public async Task PushNotificationAsync(Notification notification)
|
||||||
{
|
{
|
||||||
Guid? installationId = notification.Global && _globalSettings.Installation.Id != default
|
Guid? installationId = notification.Global && _globalSettings.Installation.Id != default
|
||||||
? _globalSettings.Installation.Id
|
? _globalSettings.Installation.Id
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = installationId,
|
InstallationId = installationId,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate
|
RevisionDate = notification.RevisionDate
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.Global && installationId.HasValue)
|
if (notification.Global && installationId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToInstallationAsync(installationId.Value, PushType.SyncNotificationCreate, message, true,
|
await SendPayloadToInstallationAsync(installationId.Value, PushType.SyncNotification, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.UserId.HasValue)
|
else if (notification.UserId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotificationCreate, message, true,
|
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotification, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.OrganizationId.HasValue)
|
else if (notification.OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationCreate,
|
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotification, message,
|
||||||
message,
|
|
||||||
true, notification.ClientType);
|
true, notification.ClientType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus)
|
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
Guid? installationId = notification.Global && _globalSettings.Installation.Id != default
|
Guid? installationId = notification.Global && _globalSettings.Installation.Id != default
|
||||||
? _globalSettings.Installation.Id
|
? _globalSettings.Installation.Id
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = installationId,
|
InstallationId = installationId,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate,
|
RevisionDate = notification.RevisionDate,
|
||||||
ReadDate = notificationStatus?.ReadDate,
|
ReadDate = notificationStatus.ReadDate,
|
||||||
DeletedDate = notificationStatus?.DeletedDate
|
DeletedDate = notificationStatus.DeletedDate
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.Global && installationId.HasValue)
|
if (notification.Global && installationId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToInstallationAsync(installationId.Value, PushType.SyncNotificationUpdate, message, true,
|
await SendPayloadToInstallationAsync(installationId.Value, PushType.SyncNotificationStatus, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.UserId.HasValue)
|
else if (notification.UserId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotificationUpdate, message, true,
|
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotificationStatus, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.OrganizationId.HasValue)
|
else if (notification.OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationUpdate,
|
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationStatus,
|
||||||
message,
|
message, true, notification.ClientType);
|
||||||
true, notification.ClientType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ public interface IPushNotificationService
|
|||||||
Task PushSyncSendCreateAsync(Send send);
|
Task PushSyncSendCreateAsync(Send send);
|
||||||
Task PushSyncSendUpdateAsync(Send send);
|
Task PushSyncSendUpdateAsync(Send send);
|
||||||
Task PushSyncSendDeleteAsync(Send send);
|
Task PushSyncSendDeleteAsync(Send send);
|
||||||
Task PushSyncNotificationCreateAsync(Notification notification);
|
Task PushNotificationAsync(Notification notification);
|
||||||
Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus);
|
Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus);
|
||||||
Task PushAuthRequestAsync(AuthRequest authRequest);
|
Task PushAuthRequestAsync(AuthRequest authRequest);
|
||||||
Task PushAuthRequestResponseAsync(AuthRequest authRequest);
|
Task PushAuthRequestResponseAsync(AuthRequest authRequest);
|
||||||
|
|
||||||
|
@ -169,36 +169,46 @@ public class AzureQueuePushNotificationService : IPushNotificationService
|
|||||||
await PushSendAsync(send, PushType.SyncSendDelete);
|
await PushSendAsync(send, PushType.SyncSendDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationCreateAsync(Notification notification)
|
public async Task PushNotificationAsync(Notification notification)
|
||||||
{
|
{
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate
|
RevisionDate = notification.RevisionDate
|
||||||
};
|
};
|
||||||
|
|
||||||
await SendMessageAsync(PushType.SyncNotificationCreate, message, true);
|
await SendMessageAsync(PushType.SyncNotification, message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus)
|
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate,
|
RevisionDate = notification.RevisionDate,
|
||||||
ReadDate = notificationStatus?.ReadDate,
|
ReadDate = notificationStatus.ReadDate,
|
||||||
DeletedDate = notificationStatus?.DeletedDate
|
DeletedDate = notificationStatus.DeletedDate
|
||||||
};
|
};
|
||||||
|
|
||||||
await SendMessageAsync(PushType.SyncNotificationUpdate, message, true);
|
await SendMessageAsync(PushType.SyncNotificationStatus, message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PushSendAsync(Send send, PushType type)
|
private async Task PushSendAsync(Send send, PushType type)
|
||||||
|
@ -154,15 +154,15 @@ public class MultiServicePushNotificationService : IPushNotificationService
|
|||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task PushSyncNotificationCreateAsync(Notification notification)
|
public Task PushNotificationAsync(Notification notification)
|
||||||
{
|
{
|
||||||
PushToServices((s) => s.PushSyncNotificationCreateAsync(notification));
|
PushToServices((s) => s.PushNotificationAsync(notification));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus)
|
public Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
PushToServices((s) => s.PushSyncNotificationUpdateAsync(notification, notificationStatus));
|
PushToServices((s) => s.PushNotificationStatusAsync(notification, notificationStatus));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,36 +179,46 @@ public class NotificationsApiPushNotificationService : BaseIdentityClientService
|
|||||||
await PushSendAsync(send, PushType.SyncSendDelete);
|
await PushSendAsync(send, PushType.SyncSendDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationCreateAsync(Notification notification)
|
public async Task PushNotificationAsync(Notification notification)
|
||||||
{
|
{
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate
|
RevisionDate = notification.RevisionDate
|
||||||
};
|
};
|
||||||
|
|
||||||
await SendMessageAsync(PushType.SyncNotificationCreate, message, true);
|
await SendMessageAsync(PushType.SyncNotification, message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus)
|
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate,
|
RevisionDate = notification.RevisionDate,
|
||||||
ReadDate = notificationStatus?.ReadDate,
|
ReadDate = notificationStatus.ReadDate,
|
||||||
DeletedDate = notificationStatus?.DeletedDate
|
DeletedDate = notificationStatus.DeletedDate
|
||||||
};
|
};
|
||||||
|
|
||||||
await SendMessageAsync(PushType.SyncNotificationUpdate, message, true);
|
await SendMessageAsync(PushType.SyncNotificationStatus, message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PushSendAsync(Send send, PushType type)
|
private async Task PushSendAsync(Send send, PushType type)
|
||||||
|
@ -197,63 +197,72 @@ public class RelayPushNotificationService : BaseIdentityClientService, IPushNoti
|
|||||||
await SendPayloadToUserAsync(authRequest.UserId, type, message, true);
|
await SendPayloadToUserAsync(authRequest.UserId, type, message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationCreateAsync(Notification notification)
|
public async Task PushNotificationAsync(Notification notification)
|
||||||
{
|
{
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate
|
RevisionDate = notification.RevisionDate
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.Global)
|
if (notification.Global)
|
||||||
{
|
{
|
||||||
await SendPayloadToInstallationAsync(PushType.SyncNotificationCreate, message, true,
|
await SendPayloadToInstallationAsync(PushType.SyncNotification, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.UserId.HasValue)
|
else if (notification.UserId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotificationCreate, message, true,
|
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotification, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.OrganizationId.HasValue)
|
else if (notification.OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationCreate,
|
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotification, message,
|
||||||
message,
|
|
||||||
true, notification.ClientType);
|
true, notification.ClientType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus)
|
public async Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
var message = new SyncNotificationPushNotification
|
var message = new NotificationPushNotification
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
InstallationId = notification.Global ? _globalSettings.Installation.Id : null,
|
||||||
ClientType = notification.ClientType,
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate,
|
RevisionDate = notification.RevisionDate,
|
||||||
ReadDate = notificationStatus?.ReadDate,
|
ReadDate = notificationStatus.ReadDate,
|
||||||
DeletedDate = notificationStatus?.DeletedDate
|
DeletedDate = notificationStatus.DeletedDate
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.Global)
|
if (notification.Global)
|
||||||
{
|
{
|
||||||
await SendPayloadToInstallationAsync(PushType.SyncNotificationUpdate, message, true,
|
await SendPayloadToInstallationAsync(PushType.SyncNotificationStatus, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.UserId.HasValue)
|
else if (notification.UserId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotificationUpdate, message, true,
|
await SendPayloadToUserAsync(notification.UserId.Value, PushType.SyncNotificationStatus, message, true,
|
||||||
notification.ClientType);
|
notification.ClientType);
|
||||||
}
|
}
|
||||||
else if (notification.OrganizationId.HasValue)
|
else if (notification.OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationUpdate,
|
await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationStatus,
|
||||||
message, true, notification.ClientType);
|
message, true, notification.ClientType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,7 @@ public class NoopPushNotificationService : IPushNotificationService
|
|||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task PushSyncNotificationCreateAsync(Notification notification) => Task.CompletedTask;
|
public Task PushNotificationAsync(Notification notification) => Task.CompletedTask;
|
||||||
|
|
||||||
public Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus) =>
|
public Task PushNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus) => Task.CompletedTask;
|
||||||
Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
|
@ -89,10 +89,10 @@ public static class HubHelpers
|
|||||||
await hubContext.Clients.User(authRequestNotification.Payload.UserId.ToString())
|
await hubContext.Clients.User(authRequestNotification.Payload.UserId.ToString())
|
||||||
.SendAsync(_receiveMessageMethod, authRequestNotification, cancellationToken);
|
.SendAsync(_receiveMessageMethod, authRequestNotification, cancellationToken);
|
||||||
break;
|
break;
|
||||||
case PushType.SyncNotificationCreate:
|
case PushType.SyncNotification:
|
||||||
case PushType.SyncNotificationUpdate:
|
case PushType.SyncNotificationStatus:
|
||||||
var syncNotification =
|
var syncNotification =
|
||||||
JsonSerializer.Deserialize<PushNotificationData<SyncNotificationPushNotification>>(
|
JsonSerializer.Deserialize<PushNotificationData<NotificationPushNotification>>(
|
||||||
notificationJson, _deserializerOptions);
|
notificationJson, _deserializerOptions);
|
||||||
if (syncNotification.Payload.InstallationId.HasValue)
|
if (syncNotification.Payload.InstallationId.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ public class PushControllerTests
|
|||||||
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
|
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
|
||||||
sutProvider.Sut.SendAsync(new PushSendRequestModel
|
sutProvider.Sut.SendAsync(new PushSendRequestModel
|
||||||
{
|
{
|
||||||
Type = PushType.SyncNotificationCreate,
|
Type = PushType.SyncNotification,
|
||||||
UserId = userId.ToString(),
|
UserId = userId.ToString(),
|
||||||
OrganizationId = organizationId.ToString(),
|
OrganizationId = organizationId.ToString(),
|
||||||
InstallationId = installationId.ToString(),
|
InstallationId = installationId.ToString(),
|
||||||
@ -63,7 +63,7 @@ public class PushControllerTests
|
|||||||
|
|
||||||
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
||||||
{
|
{
|
||||||
Type = PushType.SyncNotificationCreate,
|
Type = PushType.SyncNotification,
|
||||||
UserId = null,
|
UserId = null,
|
||||||
OrganizationId = null,
|
OrganizationId = null,
|
||||||
InstallationId = null,
|
InstallationId = null,
|
||||||
@ -96,7 +96,7 @@ public class PushControllerTests
|
|||||||
|
|
||||||
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
||||||
{
|
{
|
||||||
Type = PushType.SyncNotificationCreate,
|
Type = PushType.SyncNotification,
|
||||||
UserId = userId.ToString(),
|
UserId = userId.ToString(),
|
||||||
OrganizationId = haveOrganizationId ? Guid.NewGuid().ToString() : null,
|
OrganizationId = haveOrganizationId ? Guid.NewGuid().ToString() : null,
|
||||||
InstallationId = null,
|
InstallationId = null,
|
||||||
@ -107,7 +107,7 @@ public class PushControllerTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().Received(1)
|
await sutProvider.GetDependency<IPushNotificationService>().Received(1)
|
||||||
.SendPayloadToUserAsync(expectedUserId, PushType.SyncNotificationCreate, "test-payload", expectedIdentifier,
|
.SendPayloadToUserAsync(expectedUserId, PushType.SyncNotification, "test-payload", expectedIdentifier,
|
||||||
expectedDeviceId, ClientType.All);
|
expectedDeviceId, ClientType.All);
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().Received(0)
|
await sutProvider.GetDependency<IPushNotificationService>().Received(0)
|
||||||
.SendPayloadToOrganizationAsync(Arg.Any<string>(), Arg.Any<PushType>(), Arg.Any<object>(),
|
.SendPayloadToOrganizationAsync(Arg.Any<string>(), Arg.Any<PushType>(), Arg.Any<object>(),
|
||||||
@ -132,7 +132,7 @@ public class PushControllerTests
|
|||||||
|
|
||||||
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
||||||
{
|
{
|
||||||
Type = PushType.SyncNotificationCreate,
|
Type = PushType.SyncNotification,
|
||||||
UserId = null,
|
UserId = null,
|
||||||
OrganizationId = organizationId.ToString(),
|
OrganizationId = organizationId.ToString(),
|
||||||
InstallationId = null,
|
InstallationId = null,
|
||||||
@ -143,7 +143,7 @@ public class PushControllerTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().Received(1)
|
await sutProvider.GetDependency<IPushNotificationService>().Received(1)
|
||||||
.SendPayloadToOrganizationAsync(expectedOrganizationId, PushType.SyncNotificationCreate, "test-payload",
|
.SendPayloadToOrganizationAsync(expectedOrganizationId, PushType.SyncNotification, "test-payload",
|
||||||
expectedIdentifier, expectedDeviceId, ClientType.All);
|
expectedIdentifier, expectedDeviceId, ClientType.All);
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().Received(0)
|
await sutProvider.GetDependency<IPushNotificationService>().Received(0)
|
||||||
.SendPayloadToUserAsync(Arg.Any<string>(), Arg.Any<PushType>(), Arg.Any<object>(), Arg.Any<string>(),
|
.SendPayloadToUserAsync(Arg.Any<string>(), Arg.Any<PushType>(), Arg.Any<object>(), Arg.Any<string>(),
|
||||||
@ -166,7 +166,7 @@ public class PushControllerTests
|
|||||||
|
|
||||||
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
await sutProvider.Sut.SendAsync(new PushSendRequestModel
|
||||||
{
|
{
|
||||||
Type = PushType.SyncNotificationCreate,
|
Type = PushType.SyncNotification,
|
||||||
UserId = null,
|
UserId = null,
|
||||||
OrganizationId = null,
|
OrganizationId = null,
|
||||||
InstallationId = installationId.ToString(),
|
InstallationId = installationId.ToString(),
|
||||||
@ -177,7 +177,7 @@ public class PushControllerTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().Received(1)
|
await sutProvider.GetDependency<IPushNotificationService>().Received(1)
|
||||||
.SendPayloadToInstallationAsync(installationId.ToString(), PushType.SyncNotificationCreate, "test-payload",
|
.SendPayloadToInstallationAsync(installationId.ToString(), PushType.SyncNotification, "test-payload",
|
||||||
expectedIdentifier, expectedDeviceId, ClientType.All);
|
expectedIdentifier, expectedDeviceId, ClientType.All);
|
||||||
await sutProvider.GetDependency<IPushNotificationService>().Received(0)
|
await sutProvider.GetDependency<IPushNotificationService>().Received(0)
|
||||||
.SendPayloadToOrganizationAsync(Arg.Any<string>(), Arg.Any<PushType>(), Arg.Any<object>(),
|
.SendPayloadToOrganizationAsync(Arg.Any<string>(), Arg.Any<PushType>(), Arg.Any<object>(),
|
||||||
@ -198,7 +198,7 @@ public class PushControllerTests
|
|||||||
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
|
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
|
||||||
sutProvider.Sut.SendAsync(new PushSendRequestModel
|
sutProvider.Sut.SendAsync(new PushSendRequestModel
|
||||||
{
|
{
|
||||||
Type = PushType.SyncNotificationCreate,
|
Type = PushType.SyncNotification,
|
||||||
UserId = null,
|
UserId = null,
|
||||||
OrganizationId = null,
|
OrganizationId = null,
|
||||||
InstallationId = Guid.NewGuid().ToString(),
|
InstallationId = Guid.NewGuid().ToString(),
|
||||||
|
@ -43,7 +43,10 @@ public class CreateNotificationCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notification));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notification));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationCreateAsync(Arg.Any<Notification>());
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -61,6 +64,9 @@ public class CreateNotificationCommandTest
|
|||||||
Assert.Equal(notification.CreationDate, notification.RevisionDate);
|
Assert.Equal(notification.CreationDate, notification.RevisionDate);
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationCreateAsync(newNotification);
|
.PushNotificationAsync(newNotification);
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,10 @@ public class CreateNotificationStatusCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notificationStatus));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notificationStatus));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -67,7 +70,10 @@ public class CreateNotificationStatusCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notificationStatus));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notificationStatus));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -81,7 +87,10 @@ public class CreateNotificationStatusCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notificationStatus));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.CreateAsync(notificationStatus));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -97,6 +106,9 @@ public class CreateNotificationStatusCommandTest
|
|||||||
Assert.Equal(notificationStatus, newNotificationStatus);
|
Assert.Equal(notificationStatus, newNotificationStatus);
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification, notificationStatus);
|
.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,10 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -80,7 +83,10 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -95,7 +101,10 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -110,7 +119,10 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -125,7 +137,10 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkDeletedAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -149,8 +164,11 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
.CreateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
.CreateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification,
|
.PushNotificationStatusAsync(notification,
|
||||||
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -167,8 +185,11 @@ public class MarkNotificationDeletedCommandTest
|
|||||||
.UpdateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
.UpdateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification,
|
.PushNotificationStatusAsync(notification,
|
||||||
Arg.Do<NotificationStatus?>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus,
|
private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus,
|
||||||
|
@ -66,7 +66,10 @@ public class MarkNotificationReadCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -80,7 +83,10 @@ public class MarkNotificationReadCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -95,7 +101,10 @@ public class MarkNotificationReadCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -110,7 +119,10 @@ public class MarkNotificationReadCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -125,7 +137,10 @@ public class MarkNotificationReadCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.MarkReadAsync(notificationId));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -149,8 +164,11 @@ public class MarkNotificationReadCommandTest
|
|||||||
.CreateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
.CreateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification,
|
.PushNotificationStatusAsync(notification,
|
||||||
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -167,8 +185,11 @@ public class MarkNotificationReadCommandTest
|
|||||||
.UpdateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
.UpdateAsync(Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification,
|
.PushNotificationStatusAsync(notification,
|
||||||
Arg.Do<NotificationStatus?>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus,
|
private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus,
|
||||||
|
@ -48,7 +48,10 @@ public class UpdateNotificationCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateAsync(notification));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateAsync(notification));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -62,7 +65,10 @@ public class UpdateNotificationCommandTest
|
|||||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateAsync(notification));
|
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateAsync(notification));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
.PushSyncNotificationUpdateAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus?>());
|
.PushNotificationAsync(Arg.Any<Notification>());
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@ -100,6 +106,9 @@ public class UpdateNotificationCommandTest
|
|||||||
DateTime.UtcNow - n.RevisionDate < TimeSpan.FromMinutes(1)));
|
DateTime.UtcNow - n.RevisionDate < TimeSpan.FromMinutes(1)));
|
||||||
await sutProvider.GetDependency<IPushNotificationService>()
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification, null);
|
.PushNotificationAsync(notification);
|
||||||
|
await sutProvider.GetDependency<IPushNotificationService>()
|
||||||
|
.Received(0)
|
||||||
|
.PushNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,12 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData]
|
[BitAutoData]
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task PushSyncNotificationCreateAsync_GlobalInstallationIdDefault_NotSent(
|
public async Task PushNotificationAsync_GlobalInstallationIdDefault_NotSent(
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
|
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = default;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = default;
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await sutProvider.GetDependency<INotificationHubPool>()
|
await sutProvider.GetDependency<INotificationHubPool>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
@ -42,17 +42,16 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData]
|
[BitAutoData]
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task PushSyncNotificationCreateAsync_GlobalInstallationIdSetClientTypeAll_SentToInstallationId(
|
public async Task PushNotificationAsync_GlobalInstallationIdSetClientTypeAll_SentToInstallationId(
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification, Guid installationId)
|
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification, Guid installationId)
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
notification.ClientType = ClientType.All;
|
notification.ClientType = ClientType.All;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, installationId);
|
||||||
expectedSyncNotification.InstallationId = installationId;
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload && installationId:{installationId})");
|
$"(template:payload && installationId:{installationId})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -66,19 +65,17 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[BitAutoData(ClientType.Web)]
|
[BitAutoData(ClientType.Web)]
|
||||||
[BitAutoData(ClientType.Mobile)]
|
[BitAutoData(ClientType.Mobile)]
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task
|
public async Task PushNotificationAsync_GlobalInstallationIdSetClientTypeNotAll_SentToInstallationIdAndClientType(
|
||||||
PushSyncNotificationCreateAsync_GlobalInstallationIdSetClientTypeNotAll_SentToInstallationIdAndClientType(
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
Notification notification, Guid installationId)
|
||||||
Notification notification, Guid installationId)
|
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
notification.ClientType = clientType;
|
notification.ClientType = clientType;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, installationId);
|
||||||
expectedSyncNotification.InstallationId = installationId;
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload && installationId:{installationId} && clientType:{clientType})");
|
$"(template:payload && installationId:{installationId} && clientType:{clientType})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -90,7 +87,7 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[BitAutoData(false)]
|
[BitAutoData(false)]
|
||||||
[BitAutoData(true)]
|
[BitAutoData(true)]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task PushSyncNotificationCreateAsync_UserIdProvidedClientTypeAll_SentToUser(
|
public async Task PushNotificationAsync_UserIdProvidedClientTypeAll_SentToUser(
|
||||||
bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
Notification notification)
|
Notification notification)
|
||||||
{
|
{
|
||||||
@ -100,11 +97,11 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
notification.ClientType = ClientType.All;
|
notification.ClientType = ClientType.All;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, null);
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload_userId:{notification.UserId})");
|
$"(template:payload_userId:{notification.UserId})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -118,17 +115,17 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[BitAutoData(ClientType.Web)]
|
[BitAutoData(ClientType.Web)]
|
||||||
[BitAutoData(ClientType.Mobile)]
|
[BitAutoData(ClientType.Mobile)]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task PushSyncNotificationCreateAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser(
|
public async Task PushNotificationAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser(
|
||||||
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
Notification notification)
|
Notification notification)
|
||||||
{
|
{
|
||||||
notification.OrganizationId = null;
|
notification.OrganizationId = null;
|
||||||
notification.ClientType = clientType;
|
notification.ClientType = clientType;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, null);
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -142,16 +139,16 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[BitAutoData(ClientType.Web)]
|
[BitAutoData(ClientType.Web)]
|
||||||
[BitAutoData(ClientType.Mobile)]
|
[BitAutoData(ClientType.Mobile)]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task PushSyncNotificationCreateAsync_UserIdProvidedOrganizationIdProvidedClientTypeNotAll_SentToUser(
|
public async Task PushNotificationAsync_UserIdProvidedOrganizationIdProvidedClientTypeNotAll_SentToUser(
|
||||||
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
Notification notification)
|
Notification notification)
|
||||||
{
|
{
|
||||||
notification.ClientType = clientType;
|
notification.ClientType = clientType;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, null);
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -162,16 +159,16 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData]
|
[BitAutoData]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task PushSyncNotificationCreateAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
|
public async Task PushNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
|
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
|
||||||
{
|
{
|
||||||
notification.UserId = null;
|
notification.UserId = null;
|
||||||
notification.ClientType = ClientType.All;
|
notification.ClientType = ClientType.All;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, null);
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload && organizationId:{notification.OrganizationId})");
|
$"(template:payload && organizationId:{notification.OrganizationId})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -185,18 +182,17 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
[BitAutoData(ClientType.Web)]
|
[BitAutoData(ClientType.Web)]
|
||||||
[BitAutoData(ClientType.Mobile)]
|
[BitAutoData(ClientType.Mobile)]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task
|
public async Task PushNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
|
||||||
PushSyncNotificationCreateAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
Notification notification)
|
||||||
Notification notification)
|
|
||||||
{
|
{
|
||||||
notification.UserId = null;
|
notification.UserId = null;
|
||||||
notification.ClientType = clientType;
|
notification.ClientType = clientType;
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
|
var expectedSyncNotification = ToNotificationPushNotification(notification, null, null);
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationCreate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
|
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -205,17 +201,15 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(false)]
|
[BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task PushSyncNotificationUpdateAsync_GlobalInstallationIdDefault_NotSent(bool notificationStatusNull,
|
public async Task PushNotificationStatusAsync_GlobalInstallationIdDefault_NotSent(
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
|
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
|
||||||
NotificationStatus notificationStatus)
|
NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = default;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = default;
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification,
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
notificationStatusNull ? null : notificationStatus);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<INotificationHubPool>()
|
await sutProvider.GetDependency<INotificationHubPool>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
@ -228,23 +222,20 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(false)]
|
[BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task PushSyncNotificationUpdateAsync_GlobalInstallationIdSetClientTypeAll_SentToInstallationId(
|
public async Task PushNotificationStatusAsync_GlobalInstallationIdSetClientTypeAll_SentToInstallationId(
|
||||||
bool notificationStatusNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
Notification notification, NotificationStatus notificationStatus, Guid installationId)
|
Notification notification, NotificationStatus notificationStatus, Guid installationId)
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
notification.ClientType = ClientType.All;
|
notification.ClientType = ClientType.All;
|
||||||
|
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
var expectedSyncNotification = ToNotificationPushNotification(notification, notificationStatus, installationId);
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
expectedSyncNotification.InstallationId = installationId;
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload && installationId:{installationId})");
|
$"(template:payload && installationId:{installationId})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -253,25 +244,24 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[RepeatingPatternBitAutoData([false, true],
|
[BitAutoData(ClientType.Browser)]
|
||||||
[ClientType.Browser, ClientType.Desktop, ClientType.Web, ClientType.Mobile])]
|
[BitAutoData(ClientType.Desktop)]
|
||||||
|
[BitAutoData(ClientType.Web)]
|
||||||
|
[BitAutoData(ClientType.Mobile)]
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task
|
public async Task
|
||||||
PushSyncNotificationUpdateAsync_GlobalInstallationIdSetClientTypeNotAll_SentToInstallationIdAndClientType(
|
PushNotificationStatusAsync_GlobalInstallationIdSetClientTypeNotAll_SentToInstallationIdAndClientType(
|
||||||
bool notificationStatusNull, ClientType clientType,
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider,
|
|
||||||
Notification notification, NotificationStatus notificationStatus, Guid installationId)
|
Notification notification, NotificationStatus notificationStatus, Guid installationId)
|
||||||
{
|
{
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
notification.ClientType = clientType;
|
notification.ClientType = clientType;
|
||||||
|
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
var expectedSyncNotification = ToNotificationPushNotification(notification, notificationStatus, installationId);
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
expectedSyncNotification.InstallationId = installationId;
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
expectedSyncNotification,
|
expectedSyncNotification,
|
||||||
$"(template:payload && installationId:{installationId} && clientType:{clientType})");
|
$"(template:payload && installationId:{installationId} && clientType:{clientType})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
@ -279,97 +269,94 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[RepeatingPatternBitAutoData([false, true], [false, true])]
|
|
||||||
[NotificationCustomize(false)]
|
|
||||||
public async Task PushSyncNotificationUpdateAsync_UserIdProvidedClientTypeAll_SentToUser(
|
|
||||||
bool organizationIdNull, bool notificationStatusNull,
|
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider,
|
|
||||||
Notification notification, NotificationStatus notificationStatus)
|
|
||||||
{
|
|
||||||
if (organizationIdNull)
|
|
||||||
{
|
|
||||||
notification.OrganizationId = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
notification.ClientType = ClientType.All;
|
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
|
||||||
expectedSyncNotification,
|
|
||||||
$"(template:payload_userId:{notification.UserId})");
|
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
|
||||||
.Received(0)
|
|
||||||
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[RepeatingPatternBitAutoData([false, true],
|
|
||||||
[ClientType.Browser, ClientType.Desktop, ClientType.Web, ClientType.Mobile])]
|
|
||||||
[NotificationCustomize(false)]
|
|
||||||
public async Task PushSyncNotificationUpdateAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser(
|
|
||||||
bool notificationStatusNull, ClientType clientType,
|
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
|
|
||||||
NotificationStatus notificationStatus)
|
|
||||||
{
|
|
||||||
notification.OrganizationId = null;
|
|
||||||
notification.ClientType = clientType;
|
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
|
||||||
expectedSyncNotification,
|
|
||||||
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
|
||||||
.Received(0)
|
|
||||||
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[RepeatingPatternBitAutoData([false, true],
|
|
||||||
[ClientType.Browser, ClientType.Desktop, ClientType.Web, ClientType.Mobile])]
|
|
||||||
[NotificationCustomize(false)]
|
|
||||||
public async Task PushSyncNotificationUpdateAsync_UserIdProvidedOrganizationIdProvidedClientTypeNotAll_SentToUser(
|
|
||||||
bool notificationStatusNull, ClientType clientType,
|
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider,
|
|
||||||
Notification notification, NotificationStatus notificationStatus)
|
|
||||||
{
|
|
||||||
notification.ClientType = clientType;
|
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
|
||||||
expectedSyncNotification,
|
|
||||||
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
|
||||||
.Received(0)
|
|
||||||
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(false)]
|
[BitAutoData(false)]
|
||||||
[BitAutoData(true)]
|
[BitAutoData(true)]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task PushSyncNotificationUpdateAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
|
public async Task PushNotificationStatusAsync_UserIdProvidedClientTypeAll_SentToUser(
|
||||||
bool notificationStatusNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
Notification notification, NotificationStatus notificationStatus)
|
Notification notification, NotificationStatus notificationStatus)
|
||||||
|
{
|
||||||
|
if (organizationIdNull)
|
||||||
|
{
|
||||||
|
notification.OrganizationId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.ClientType = ClientType.All;
|
||||||
|
var expectedSyncNotification = ToNotificationPushNotification(notification, notificationStatus, null);
|
||||||
|
|
||||||
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
|
expectedSyncNotification,
|
||||||
|
$"(template:payload_userId:{notification.UserId})");
|
||||||
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
|
.Received(0)
|
||||||
|
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[BitAutoData(ClientType.Browser)]
|
||||||
|
[BitAutoData(ClientType.Desktop)]
|
||||||
|
[BitAutoData(ClientType.Web)]
|
||||||
|
[BitAutoData(ClientType.Mobile)]
|
||||||
|
[NotificationCustomize(false)]
|
||||||
|
public async Task PushNotificationStatusAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser(
|
||||||
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
|
Notification notification, NotificationStatus notificationStatus)
|
||||||
|
{
|
||||||
|
notification.OrganizationId = null;
|
||||||
|
notification.ClientType = clientType;
|
||||||
|
var expectedNotification = ToNotificationPushNotification(notification, notificationStatus, null);
|
||||||
|
|
||||||
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
|
expectedNotification,
|
||||||
|
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
||||||
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
|
.Received(0)
|
||||||
|
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[BitAutoData(ClientType.Browser)]
|
||||||
|
[BitAutoData(ClientType.Desktop)]
|
||||||
|
[BitAutoData(ClientType.Web)]
|
||||||
|
[BitAutoData(ClientType.Mobile)]
|
||||||
|
[NotificationCustomize(false)]
|
||||||
|
public async Task PushNotificationStatusAsync_UserIdProvidedOrganizationIdProvidedClientTypeNotAll_SentToUser(
|
||||||
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
|
Notification notification, NotificationStatus notificationStatus)
|
||||||
|
{
|
||||||
|
notification.ClientType = clientType;
|
||||||
|
var expectedNotification = ToNotificationPushNotification(notification, notificationStatus, null);
|
||||||
|
|
||||||
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
|
expectedNotification,
|
||||||
|
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
||||||
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
|
.Received(0)
|
||||||
|
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[BitAutoData]
|
||||||
|
[NotificationCustomize(false)]
|
||||||
|
public async Task PushNotificationStatusAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
|
||||||
|
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
|
||||||
|
NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
notification.UserId = null;
|
notification.UserId = null;
|
||||||
notification.ClientType = ClientType.All;
|
notification.ClientType = ClientType.All;
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
var expectedNotification = ToNotificationPushNotification(notification, notificationStatus, null);
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
expectedSyncNotification,
|
expectedNotification,
|
||||||
$"(template:payload && organizationId:{notification.OrganizationId})");
|
$"(template:payload && organizationId:{notification.OrganizationId})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
@ -377,24 +364,24 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[RepeatingPatternBitAutoData([false, true],
|
[BitAutoData(ClientType.Browser)]
|
||||||
[ClientType.Browser, ClientType.Desktop, ClientType.Web, ClientType.Mobile])]
|
[BitAutoData(ClientType.Desktop)]
|
||||||
|
[BitAutoData(ClientType.Web)]
|
||||||
|
[BitAutoData(ClientType.Mobile)]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
public async Task
|
public async Task
|
||||||
PushSyncNotificationUpdateAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
|
PushNotificationStatusAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
|
||||||
bool notificationStatusNull, ClientType clientType,
|
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
|
Notification notification, NotificationStatus notificationStatus)
|
||||||
NotificationStatus notificationStatus)
|
|
||||||
{
|
{
|
||||||
notification.UserId = null;
|
notification.UserId = null;
|
||||||
notification.ClientType = clientType;
|
notification.ClientType = clientType;
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
var expectedNotification = ToNotificationPushNotification(notification, notificationStatus, null);
|
||||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
|
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate,
|
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
|
||||||
expectedSyncNotification,
|
expectedNotification,
|
||||||
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
|
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
|
||||||
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
await sutProvider.GetDependency<IInstallationDeviceRepository>()
|
||||||
.Received(0)
|
.Received(0)
|
||||||
@ -509,14 +496,20 @@ public class NotificationHubPushNotificationServiceTests
|
|||||||
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SyncNotificationPushNotification ToSyncNotificationPushNotification(Notification notification,
|
private static NotificationPushNotification ToNotificationPushNotification(Notification notification,
|
||||||
NotificationStatus? notificationStatus) =>
|
NotificationStatus? notificationStatus, Guid? installationId) =>
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
Id = notification.Id,
|
Id = notification.Id,
|
||||||
|
Priority = notification.Priority,
|
||||||
|
Global = notification.Global,
|
||||||
|
ClientType = notification.ClientType,
|
||||||
UserId = notification.UserId,
|
UserId = notification.UserId,
|
||||||
OrganizationId = notification.OrganizationId,
|
OrganizationId = notification.OrganizationId,
|
||||||
ClientType = notification.ClientType,
|
InstallationId = installationId,
|
||||||
|
Title = notification.Title,
|
||||||
|
Body = notification.Body,
|
||||||
|
CreationDate = notification.CreationDate,
|
||||||
RevisionDate = notification.RevisionDate,
|
RevisionDate = notification.RevisionDate,
|
||||||
ReadDate = notificationStatus?.ReadDate,
|
ReadDate = notificationStatus?.ReadDate,
|
||||||
DeletedDate = notificationStatus?.DeletedDate
|
DeletedDate = notificationStatus?.DeletedDate
|
||||||
|
@ -26,7 +26,7 @@ public class AzureQueuePushNotificationServiceTests
|
|||||||
[BitAutoData]
|
[BitAutoData]
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
[CurrentContextCustomize]
|
[CurrentContextCustomize]
|
||||||
public async Task PushSyncNotificationCreateAsync_NotificationGlobal_Sent(
|
public async Task PushNotificationAsync_NotificationGlobal_Sent(
|
||||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||||
ICurrentContext currentContext, Guid installationId)
|
ICurrentContext currentContext, Guid installationId)
|
||||||
{
|
{
|
||||||
@ -35,12 +35,12 @@ public class AzureQueuePushNotificationServiceTests
|
|||||||
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await sutProvider.GetDependency<QueueClient>().Received(1)
|
await sutProvider.GetDependency<QueueClient>().Received(1)
|
||||||
.SendMessageAsync(Arg.Is<string>(message =>
|
.SendMessageAsync(Arg.Is<string>(message =>
|
||||||
MatchMessage(PushType.SyncNotificationCreate, message,
|
MatchMessage(PushType.SyncNotification, message,
|
||||||
new SyncNotificationEquals(notification, null, installationId),
|
new NotificationPushNotificationEquals(notification, null, installationId),
|
||||||
deviceIdentifier.ToString())));
|
deviceIdentifier.ToString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public class AzureQueuePushNotificationServiceTests
|
|||||||
[BitAutoData]
|
[BitAutoData]
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
[CurrentContextCustomize]
|
[CurrentContextCustomize]
|
||||||
public async Task PushSyncNotificationCreateAsync_NotificationNotGlobal_Sent(
|
public async Task PushNotificationAsync_NotificationNotGlobal_Sent(
|
||||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||||
ICurrentContext currentContext, Guid installationId)
|
ICurrentContext currentContext, Guid installationId)
|
||||||
{
|
{
|
||||||
@ -57,90 +57,92 @@ public class AzureQueuePushNotificationServiceTests
|
|||||||
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await sutProvider.GetDependency<QueueClient>().Received(1)
|
await sutProvider.GetDependency<QueueClient>().Received(1)
|
||||||
.SendMessageAsync(Arg.Is<string>(message =>
|
.SendMessageAsync(Arg.Is<string>(message =>
|
||||||
MatchMessage(PushType.SyncNotificationCreate, message,
|
MatchMessage(PushType.SyncNotification, message,
|
||||||
new SyncNotificationEquals(notification, null, null),
|
new NotificationPushNotificationEquals(notification, null, null),
|
||||||
deviceIdentifier.ToString())));
|
deviceIdentifier.ToString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(false)]
|
[BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
[NotificationStatusCustomize]
|
[NotificationStatusCustomize]
|
||||||
[CurrentContextCustomize]
|
[CurrentContextCustomize]
|
||||||
public async Task PushSyncNotificationUpdateAsync_NotificationGlobal_Sent(bool notificationStatusNull,
|
public async Task PushNotificationStatusAsync_NotificationGlobal_Sent(
|
||||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||||
ICurrentContext currentContext, NotificationStatus notificationStatus, Guid installationId)
|
ICurrentContext currentContext, NotificationStatus notificationStatus, Guid installationId)
|
||||||
{
|
{
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
|
||||||
currentContext.DeviceIdentifier.Returns(deviceIdentifier.ToString());
|
currentContext.DeviceIdentifier.Returns(deviceIdentifier.ToString());
|
||||||
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
|
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
|
||||||
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
await sutProvider.GetDependency<QueueClient>().Received(1)
|
await sutProvider.GetDependency<QueueClient>().Received(1)
|
||||||
.SendMessageAsync(Arg.Is<string>(message =>
|
.SendMessageAsync(Arg.Is<string>(message =>
|
||||||
MatchMessage(PushType.SyncNotificationUpdate, message,
|
MatchMessage(PushType.SyncNotificationStatus, message,
|
||||||
new SyncNotificationEquals(notification, expectedNotificationStatus, installationId),
|
new NotificationPushNotificationEquals(notification, notificationStatus, installationId),
|
||||||
deviceIdentifier.ToString())));
|
deviceIdentifier.ToString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(false)]
|
[BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[NotificationCustomize(false)]
|
[NotificationCustomize(false)]
|
||||||
[NotificationStatusCustomize]
|
[NotificationStatusCustomize]
|
||||||
[CurrentContextCustomize]
|
[CurrentContextCustomize]
|
||||||
public async Task PushSyncNotificationUpdateAsync_NotificationNotGlobal_Sent(bool notificationStatusNull,
|
public async Task PushNotificationStatusAsync_NotificationNotGlobal_Sent(
|
||||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||||
ICurrentContext currentContext, NotificationStatus notificationStatus, Guid installationId)
|
ICurrentContext currentContext, NotificationStatus notificationStatus, Guid installationId)
|
||||||
{
|
{
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
|
||||||
currentContext.DeviceIdentifier.Returns(deviceIdentifier.ToString());
|
currentContext.DeviceIdentifier.Returns(deviceIdentifier.ToString());
|
||||||
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
|
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
|
||||||
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
||||||
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
sutProvider.GetDependency<IGlobalSettings>().Installation.Id = installationId;
|
||||||
|
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
|
|
||||||
await sutProvider.GetDependency<QueueClient>().Received(1)
|
await sutProvider.GetDependency<QueueClient>().Received(1)
|
||||||
.SendMessageAsync(Arg.Is<string>(message =>
|
.SendMessageAsync(Arg.Is<string>(message =>
|
||||||
MatchMessage(PushType.SyncNotificationUpdate, message,
|
MatchMessage(PushType.SyncNotificationStatus, message,
|
||||||
new SyncNotificationEquals(notification, expectedNotificationStatus, null),
|
new NotificationPushNotificationEquals(notification, notificationStatus, null),
|
||||||
deviceIdentifier.ToString())));
|
deviceIdentifier.ToString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool MatchMessage<T>(PushType pushType, string message, IEquatable<T> expectedPayloadEquatable,
|
private static bool MatchMessage<T>(PushType pushType, string message, IEquatable<T> expectedPayloadEquatable,
|
||||||
string contextId)
|
string contextId)
|
||||||
{
|
{
|
||||||
var pushNotificationData =
|
var pushNotificationData = JsonSerializer.Deserialize<PushNotificationData<T>>(message);
|
||||||
JsonSerializer.Deserialize<PushNotificationData<T>>(message);
|
|
||||||
return pushNotificationData != null &&
|
return pushNotificationData != null &&
|
||||||
pushNotificationData.Type == pushType &&
|
pushNotificationData.Type == pushType &&
|
||||||
expectedPayloadEquatable.Equals(pushNotificationData.Payload) &&
|
expectedPayloadEquatable.Equals(pushNotificationData.Payload) &&
|
||||||
pushNotificationData.ContextId == contextId;
|
pushNotificationData.ContextId == contextId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SyncNotificationEquals(
|
private class NotificationPushNotificationEquals(
|
||||||
Notification notification,
|
Notification notification,
|
||||||
NotificationStatus? notificationStatus,
|
NotificationStatus? notificationStatus,
|
||||||
Guid? installationId)
|
Guid? installationId)
|
||||||
: IEquatable<SyncNotificationPushNotification>
|
: IEquatable<NotificationPushNotification>
|
||||||
{
|
{
|
||||||
public bool Equals(SyncNotificationPushNotification? other)
|
public bool Equals(NotificationPushNotification? other)
|
||||||
{
|
{
|
||||||
return other != null &&
|
return other != null &&
|
||||||
other.Id == notification.Id &&
|
other.Id == notification.Id &&
|
||||||
|
other.Priority == notification.Priority &&
|
||||||
|
other.Global == notification.Global &&
|
||||||
|
other.ClientType == notification.ClientType &&
|
||||||
|
other.UserId.HasValue == notification.UserId.HasValue &&
|
||||||
other.UserId == notification.UserId &&
|
other.UserId == notification.UserId &&
|
||||||
|
other.OrganizationId.HasValue == notification.OrganizationId.HasValue &&
|
||||||
other.OrganizationId == notification.OrganizationId &&
|
other.OrganizationId == notification.OrganizationId &&
|
||||||
other.InstallationId == installationId &&
|
other.InstallationId == installationId &&
|
||||||
other.ClientType == notification.ClientType &&
|
other.Title == notification.Title &&
|
||||||
|
other.Body == notification.Body &&
|
||||||
|
other.CreationDate == notification.CreationDate &&
|
||||||
other.RevisionDate == notification.RevisionDate &&
|
other.RevisionDate == notification.RevisionDate &&
|
||||||
other.ReadDate == notificationStatus?.ReadDate &&
|
other.ReadDate == notificationStatus?.ReadDate &&
|
||||||
other.DeletedDate == notificationStatus?.DeletedDate;
|
other.DeletedDate == notificationStatus?.DeletedDate;
|
||||||
|
@ -16,34 +16,31 @@ public class MultiServicePushNotificationServiceTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData]
|
[BitAutoData]
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
public async Task PushSyncNotificationCreateAsync_Notification_Sent(
|
public async Task PushNotificationAsync_Notification_Sent(
|
||||||
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification)
|
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification)
|
||||||
{
|
{
|
||||||
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
|
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||||
|
|
||||||
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
|
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
|
||||||
.First()
|
.First()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationCreateAsync(notification);
|
.PushNotificationAsync(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(false)]
|
[BitAutoData]
|
||||||
[BitAutoData(true)]
|
|
||||||
[NotificationCustomize]
|
[NotificationCustomize]
|
||||||
[NotificationStatusCustomize]
|
[NotificationStatusCustomize]
|
||||||
public async Task PushSyncNotificationUpdateAsync_Notification_Sent(bool notificationStatusNull,
|
public async Task PushNotificationStatusAsync_Notification_Sent(
|
||||||
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification,
|
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification,
|
||||||
NotificationStatus notificationStatus)
|
NotificationStatus notificationStatus)
|
||||||
{
|
{
|
||||||
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification,
|
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
notificationStatusNull ? null : notificationStatus);
|
|
||||||
|
|
||||||
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
|
|
||||||
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
|
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
|
||||||
.First()
|
.First()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
|
.PushNotificationStatusAsync(notification, notificationStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
Reference in New Issue
Block a user