1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

PM-10564: Sync notification push type separation for notification updates

Sync notification push type is now used for both Notification create and update.
Renamed the event types to specifically mention the purpose of status for notification status updates.
This commit is contained in:
Maciej Zieniuk
2024-11-25 20:45:41 +00:00
parent 1285a7e994
commit fcf346985f
22 changed files with 221 additions and 184 deletions

View File

@ -26,6 +26,6 @@ public enum PushType : byte
SyncOrganizations = 17, SyncOrganizations = 17,
SyncNotificationCreate = 18, SyncNotification = 18,
SyncNotificationUpdate = 19 SyncNotificationStatus = 19
} }

View File

@ -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.PushSyncNotificationAsync(newNotification);
return newNotification; return newNotification;
} }

View File

@ -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.PushSyncNotificationStatusAsync(notification, newNotificationStatus);
return newNotificationStatus; return newNotificationStatus;
} }

View File

@ -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.PushSyncNotificationStatusAsync(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.PushSyncNotificationStatusAsync(notification, notificationStatus);
} }
} }
} }

View File

@ -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.PushSyncNotificationStatusAsync(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.PushSyncNotificationStatusAsync(notification, notificationStatus);
} }
} }
} }

View File

@ -48,6 +48,6 @@ public class UpdateNotificationCommand : IUpdateNotificationCommand
await _notificationRepository.ReplaceAsync(notification); await _notificationRepository.ReplaceAsync(notification);
await _pushNotificationService.PushSyncNotificationUpdateAsync(notification, null); await _pushNotificationService.PushSyncNotificationAsync(notification);
} }
} }

View File

@ -182,7 +182,7 @@ public class NotificationHubPushNotificationService : IPushNotificationService
await PushAuthRequestAsync(authRequest, PushType.AuthRequestResponse); await PushAuthRequestAsync(authRequest, PushType.AuthRequestResponse);
} }
public async Task PushSyncNotificationCreateAsync(Notification notification) public async Task PushSyncNotificationAsync(Notification notification)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -195,17 +195,17 @@ public class NotificationHubPushNotificationService : IPushNotificationService
if (notification.UserId.HasValue) 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, message, await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotification, message,
true, notification.ClientType); true, notification.ClientType);
} }
} }
public async Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus) public async Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -214,18 +214,18 @@ public class NotificationHubPushNotificationService : IPushNotificationService
OrganizationId = notification.OrganizationId, OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType, ClientType = notification.ClientType,
RevisionDate = notification.RevisionDate, RevisionDate = notification.RevisionDate,
ReadDate = notificationStatus?.ReadDate, ReadDate = notificationStatus.ReadDate,
DeletedDate = notificationStatus?.DeletedDate DeletedDate = notificationStatus.DeletedDate
}; };
if (notification.UserId.HasValue) 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, message, await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationStatus, message,
true, notification.ClientType); true, notification.ClientType);
} }
} }

View File

@ -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 PushSyncNotificationAsync(Notification notification);
Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus); Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus);
Task PushAuthRequestAsync(AuthRequest authRequest); Task PushAuthRequestAsync(AuthRequest authRequest);
Task PushAuthRequestResponseAsync(AuthRequest authRequest); Task PushAuthRequestResponseAsync(AuthRequest authRequest);

View File

@ -165,7 +165,7 @@ public class AzureQueuePushNotificationService : IPushNotificationService
await PushSendAsync(send, PushType.SyncSendDelete); await PushSendAsync(send, PushType.SyncSendDelete);
} }
public async Task PushSyncNotificationCreateAsync(Notification notification) public async Task PushSyncNotificationAsync(Notification notification)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -176,10 +176,10 @@ public class AzureQueuePushNotificationService : IPushNotificationService
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 PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -188,11 +188,11 @@ public class AzureQueuePushNotificationService : IPushNotificationService
OrganizationId = notification.OrganizationId, OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType, ClientType = notification.ClientType,
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)

View File

@ -146,15 +146,15 @@ public class MultiServicePushNotificationService : IPushNotificationService
return Task.FromResult(0); return Task.FromResult(0);
} }
public Task PushSyncNotificationCreateAsync(Notification notification) public Task PushSyncNotificationAsync(Notification notification)
{ {
PushToServices((s) => s.PushSyncNotificationCreateAsync(notification)); PushToServices((s) => s.PushSyncNotificationAsync(notification));
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus) public Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{ {
PushToServices((s) => s.PushSyncNotificationUpdateAsync(notification, notificationStatus)); PushToServices((s) => s.PushSyncNotificationStatusAsync(notification, notificationStatus));
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -172,7 +172,7 @@ public class NotificationsApiPushNotificationService : BaseIdentityClientService
await PushSendAsync(send, PushType.SyncSendDelete); await PushSendAsync(send, PushType.SyncSendDelete);
} }
public async Task PushSyncNotificationCreateAsync(Notification notification) public async Task PushSyncNotificationAsync(Notification notification)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -183,10 +183,10 @@ public class NotificationsApiPushNotificationService : BaseIdentityClientService
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 PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -195,11 +195,11 @@ public class NotificationsApiPushNotificationService : BaseIdentityClientService
OrganizationId = notification.OrganizationId, OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType, ClientType = notification.ClientType,
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)

View File

@ -190,7 +190,7 @@ 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 PushSyncNotificationAsync(Notification notification)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -203,17 +203,17 @@ public class RelayPushNotificationService : BaseIdentityClientService, IPushNoti
if (notification.UserId.HasValue) 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, message, await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotification, message,
true, notification.ClientType); true, notification.ClientType);
} }
} }
public async Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus) public async Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus)
{ {
var message = new SyncNotificationPushNotification var message = new SyncNotificationPushNotification
{ {
@ -222,18 +222,18 @@ public class RelayPushNotificationService : BaseIdentityClientService, IPushNoti
OrganizationId = notification.OrganizationId, OrganizationId = notification.OrganizationId,
ClientType = notification.ClientType, ClientType = notification.ClientType,
RevisionDate = notification.RevisionDate, RevisionDate = notification.RevisionDate,
ReadDate = notificationStatus?.ReadDate, ReadDate = notificationStatus.ReadDate,
DeletedDate = notificationStatus?.DeletedDate DeletedDate = notificationStatus.DeletedDate
}; };
if (notification.UserId.HasValue) 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, message, await SendPayloadToOrganizationAsync(notification.OrganizationId.Value, PushType.SyncNotificationStatus, message,
true, notification.ClientType); true, notification.ClientType);
} }
} }

View File

@ -106,7 +106,7 @@ public class NoopPushNotificationService : IPushNotificationService
return Task.FromResult(0); return Task.FromResult(0);
} }
public Task PushSyncNotificationCreateAsync(Notification notification) => Task.CompletedTask; public Task PushSyncNotificationAsync(Notification notification) => Task.CompletedTask;
public Task PushSyncNotificationUpdateAsync(Notification notification, NotificationStatus? notificationStatus) => Task.CompletedTask; public Task PushSyncNotificationStatusAsync(Notification notification, NotificationStatus notificationStatus) => Task.CompletedTask;
} }

View File

@ -89,8 +89,8 @@ 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<SyncNotificationPushNotification>>(
notificationJson, _deserializerOptions); notificationJson, _deserializerOptions);

View File

@ -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>()); .PushSyncNotificationAsync(Arg.Any<Notification>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationStatusAsync(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); .PushSyncNotificationAsync(newNotification);
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
} }
} }

View File

@ -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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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); .PushSyncNotificationStatusAsync(notification, notificationStatus);
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(Arg.Any<Notification>());
} }
} }

View File

@ -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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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, .PushSyncNotificationStatusAsync(notification,
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns))); Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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, .PushSyncNotificationStatusAsync(notification,
Arg.Do<NotificationStatus?>(ns => AssertNotificationStatus(notificationStatus, ns))); Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(Arg.Any<Notification>());
} }
private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus, private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus,

View File

@ -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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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?>()); .PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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, .PushSyncNotificationStatusAsync(notification,
Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns))); Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(expectedNotificationStatus, ns)));
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(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, .PushSyncNotificationStatusAsync(notification,
Arg.Do<NotificationStatus?>(ns => AssertNotificationStatus(notificationStatus, ns))); Arg.Do<NotificationStatus>(ns => AssertNotificationStatus(notificationStatus, ns)));
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationAsync(Arg.Any<Notification>());
} }
private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus, private static void AssertNotificationStatus(NotificationStatus expectedNotificationStatus,

View File

@ -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?>()); .PushSyncNotificationAsync(Arg.Any<Notification>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationStatusAsync(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?>()); .PushSyncNotificationAsync(Arg.Any<Notification>());
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationStatusAsync(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); .PushSyncNotificationAsync(notification);
await sutProvider.GetDependency<IPushNotificationService>()
.Received(0)
.PushSyncNotificationStatusAsync(Arg.Any<Notification>(), Arg.Any<NotificationStatus>());
} }
} }

View File

@ -21,10 +21,10 @@ public class NotificationHubPushNotificationServiceTests
[Theory] [Theory]
[BitAutoData] [BitAutoData]
[NotificationCustomize] [NotificationCustomize]
public async Task PushSyncNotificationCreateAsync_Global_NotSent( public async Task PushSyncNotificationAsync_Global_NotSent(
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification) SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
{ {
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.GetDependency<INotificationHubPool>() await sutProvider.GetDependency<INotificationHubPool>()
.Received(0) .Received(0)
@ -40,7 +40,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 PushSyncNotificationAsync_UserIdProvidedClientTypeAll_SentToUser(
bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider, bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification) Notification notification)
{ {
@ -52,9 +52,9 @@ public class NotificationHubPushNotificationServiceTests
notification.ClientType = ClientType.All; notification.ClientType = ClientType.All;
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null); var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(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>()
@ -68,7 +68,7 @@ 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 PushSyncNotificationAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser(
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider, ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification) Notification notification)
{ {
@ -76,9 +76,9 @@ public class NotificationHubPushNotificationServiceTests
notification.ClientType = clientType; notification.ClientType = clientType;
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null); var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(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>()
@ -92,16 +92,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 PushSyncNotificationAsync_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 = ToSyncNotificationPushNotification(notification, null);
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(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>()
@ -112,16 +112,16 @@ public class NotificationHubPushNotificationServiceTests
[Theory] [Theory]
[BitAutoData] [BitAutoData]
[NotificationCustomize(false)] [NotificationCustomize(false)]
public async Task PushSyncNotificationCreateAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization( public async Task PushSyncNotificationAsync_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 = ToSyncNotificationPushNotification(notification, null);
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(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>()
@ -135,8 +135,7 @@ 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 PushSyncNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
PushSyncNotificationCreateAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider, ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification) Notification notification)
{ {
@ -144,9 +143,9 @@ public class NotificationHubPushNotificationServiceTests
notification.ClientType = clientType; notification.ClientType = clientType;
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null); var expectedSyncNotification = ToSyncNotificationPushNotification(notification, null);
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(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>()
@ -155,15 +154,13 @@ public class NotificationHubPushNotificationServiceTests
} }
[Theory] [Theory]
[BitAutoData(false)] [BitAutoData]
[BitAutoData(true)]
[NotificationCustomize] [NotificationCustomize]
public async Task PushSyncNotificationUpdateAsync_Global_NotSent(bool notificationStatusNull, public async Task PushSyncNotificationStatusAsync_Global_NotSent(
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification, SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
NotificationStatus notificationStatus) NotificationStatus notificationStatus)
{ {
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
notificationStatusNull ? null : notificationStatus);
await sutProvider.GetDependency<INotificationHubPool>() await sutProvider.GetDependency<INotificationHubPool>()
.Received(0) .Received(0)
@ -176,14 +173,11 @@ public class NotificationHubPushNotificationServiceTests
} }
[Theory] [Theory]
[BitAutoData(false, false)] [BitAutoData(false)]
[BitAutoData(false, true)] [BitAutoData(true)]
[BitAutoData(true, false)]
[BitAutoData(true, true)]
[NotificationCustomize(false)] [NotificationCustomize(false)]
public async Task PushSyncNotificationUpdateAsync_UserIdProvidedClientTypeAll_SentToUser( public async Task PushSyncNotificationStatusAsync_UserIdProvidedClientTypeAll_SentToUser(
bool organizationIdNull, bool notificationStatusNull, bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification, NotificationStatus notificationStatus) Notification notification, NotificationStatus notificationStatus)
{ {
if (organizationIdNull) if (organizationIdNull)
@ -192,12 +186,11 @@ public class NotificationHubPushNotificationServiceTests
} }
notification.ClientType = ClientType.All; notification.ClientType = ClientType.All;
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus; var expectedSyncNotification = ToSyncNotificationPushNotification(notification, notificationStatus);
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus); await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate, await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
expectedSyncNotification, expectedSyncNotification,
$"(template:payload_userId:{notification.UserId})"); $"(template:payload_userId:{notification.UserId})");
await sutProvider.GetDependency<IInstallationDeviceRepository>() await sutProvider.GetDependency<IInstallationDeviceRepository>()
@ -206,28 +199,22 @@ public class NotificationHubPushNotificationServiceTests
} }
[Theory] [Theory]
[BitAutoData(false, ClientType.Browser)] [BitAutoData(ClientType.Browser)]
[BitAutoData(false, ClientType.Desktop)] [BitAutoData(ClientType.Desktop)]
[BitAutoData(false, ClientType.Web)] [BitAutoData(ClientType.Web)]
[BitAutoData(false, ClientType.Mobile)] [BitAutoData(ClientType.Mobile)]
[BitAutoData(true, ClientType.Browser)]
[BitAutoData(true, ClientType.Desktop)]
[BitAutoData(true, ClientType.Web)]
[BitAutoData(true, ClientType.Mobile)]
[NotificationCustomize(false)] [NotificationCustomize(false)]
public async Task PushSyncNotificationUpdateAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser( public async Task PushSyncNotificationStatusAsync_UserIdProvidedOrganizationIdNullClientTypeNotAll_SentToUser(
bool notificationStatusNull, ClientType clientType, ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification, Notification notification, NotificationStatus notificationStatus)
NotificationStatus notificationStatus)
{ {
notification.OrganizationId = null; notification.OrganizationId = null;
notification.ClientType = clientType; notification.ClientType = clientType;
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus; var expectedSyncNotification = ToSyncNotificationPushNotification(notification, notificationStatus);
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus); await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate, await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
expectedSyncNotification, expectedSyncNotification,
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})"); $"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
await sutProvider.GetDependency<IInstallationDeviceRepository>() await sutProvider.GetDependency<IInstallationDeviceRepository>()
@ -236,27 +223,21 @@ public class NotificationHubPushNotificationServiceTests
} }
[Theory] [Theory]
[BitAutoData(false, ClientType.Browser)] [BitAutoData(ClientType.Browser)]
[BitAutoData(false, ClientType.Desktop)] [BitAutoData(ClientType.Desktop)]
[BitAutoData(false, ClientType.Web)] [BitAutoData(ClientType.Web)]
[BitAutoData(false, ClientType.Mobile)] [BitAutoData(ClientType.Mobile)]
[BitAutoData(true, ClientType.Browser)]
[BitAutoData(true, ClientType.Desktop)]
[BitAutoData(true, ClientType.Web)]
[BitAutoData(true, ClientType.Mobile)]
[NotificationCustomize(false)] [NotificationCustomize(false)]
public async Task PushSyncNotificationUpdateAsync_UserIdProvidedOrganizationIdProvidedClientTypeNotAll_SentToUser( public async Task PushSyncNotificationStatusAsync_UserIdProvidedOrganizationIdProvidedClientTypeNotAll_SentToUser(
bool notificationStatusNull, ClientType clientType, ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
SutProvider<NotificationHubPushNotificationService> sutProvider,
Notification notification, NotificationStatus notificationStatus) Notification notification, NotificationStatus notificationStatus)
{ {
notification.ClientType = clientType; notification.ClientType = clientType;
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus; var expectedSyncNotification = ToSyncNotificationPushNotification(notification, notificationStatus);
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus); await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate, await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
expectedSyncNotification, expectedSyncNotification,
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})"); $"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
await sutProvider.GetDependency<IInstallationDeviceRepository>() await sutProvider.GetDependency<IInstallationDeviceRepository>()
@ -265,21 +246,19 @@ public class NotificationHubPushNotificationServiceTests
} }
[Theory] [Theory]
[BitAutoData(false)] [BitAutoData]
[BitAutoData(true)]
[NotificationCustomize(false)] [NotificationCustomize(false)]
public async Task PushSyncNotificationUpdateAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization( public async Task PushSyncNotificationStatusAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
bool notificationStatusNull, SutProvider<NotificationHubPushNotificationService> sutProvider, SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification,
Notification notification, NotificationStatus notificationStatus) NotificationStatus notificationStatus)
{ {
notification.UserId = null; notification.UserId = null;
notification.ClientType = ClientType.All; notification.ClientType = ClientType.All;
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus; var expectedSyncNotification = ToSyncNotificationPushNotification(notification, notificationStatus);
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus); await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate, await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
expectedSyncNotification, expectedSyncNotification,
$"(template:payload && organizationId:{notification.OrganizationId})"); $"(template:payload && organizationId:{notification.OrganizationId})");
await sutProvider.GetDependency<IInstallationDeviceRepository>() await sutProvider.GetDependency<IInstallationDeviceRepository>()
@ -288,29 +267,23 @@ public class NotificationHubPushNotificationServiceTests
} }
[Theory] [Theory]
[BitAutoData(false, ClientType.Browser)] [BitAutoData(ClientType.Browser)]
[BitAutoData(false, ClientType.Desktop)] [BitAutoData(ClientType.Desktop)]
[BitAutoData(false, ClientType.Web)] [BitAutoData(ClientType.Web)]
[BitAutoData(false, ClientType.Mobile)] [BitAutoData(ClientType.Mobile)]
[BitAutoData(true, ClientType.Browser)]
[BitAutoData(true, ClientType.Desktop)]
[BitAutoData(true, ClientType.Web)]
[BitAutoData(true, ClientType.Mobile)]
[NotificationCustomize(false)] [NotificationCustomize(false)]
public async Task public async Task
PushSyncNotificationUpdateAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization( PushSyncNotificationStatusAsync_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 expectedSyncNotification = ToSyncNotificationPushNotification(notification, notificationStatus);
var expectedSyncNotification = ToSyncNotificationPushNotification(notification, expectedNotificationStatus);
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus); await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationUpdate, await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotificationStatus,
expectedSyncNotification, expectedSyncNotification,
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})"); $"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
await sutProvider.GetDependency<IInstallationDeviceRepository>() await sutProvider.GetDependency<IInstallationDeviceRepository>()

View File

@ -25,7 +25,7 @@ public class AzureQueuePushNotificationServiceTests
[BitAutoData] [BitAutoData]
[NotificationCustomize] [NotificationCustomize]
[CurrentContextCustomize] [CurrentContextCustomize]
public async Task PushSyncNotificationCreateAsync_Notification_Sent( public async Task PushSyncNotificationAsync_Notification_Sent(
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier, SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
ICurrentContext currentContext) ICurrentContext currentContext)
{ {
@ -33,35 +33,33 @@ public class AzureQueuePushNotificationServiceTests
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
.GetService(Arg.Any<Type>()).Returns(currentContext); .GetService(Arg.Any<Type>()).Returns(currentContext);
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(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, new SyncNotificationEquals(notification, null), MatchMessage(PushType.SyncNotification, message, new SyncNotificationEquals(notification, null),
deviceIdentifier.ToString()))); deviceIdentifier.ToString())));
} }
[Theory] [Theory]
[BitAutoData(false)] [BitAutoData]
[BitAutoData(true)]
[NotificationCustomize] [NotificationCustomize]
[NotificationStatusCustomize] [NotificationStatusCustomize]
[CurrentContextCustomize] [CurrentContextCustomize]
public async Task PushSyncNotificationUpdateAsync_Notification_Sent(bool notificationStatusNull, public async Task PushSyncNotificationStatusAsync_Notification_Sent(
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier, SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
ICurrentContext currentContext, NotificationStatus notificationStatus) ICurrentContext currentContext, NotificationStatus notificationStatus)
{ {
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);
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus); await sutProvider.Sut.PushSyncNotificationStatusAsync(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), new SyncNotificationEquals(notification, notificationStatus),
deviceIdentifier.ToString()))); deviceIdentifier.ToString())));
} }

View File

@ -16,34 +16,31 @@ public class MultiServicePushNotificationServiceTests
[Theory] [Theory]
[BitAutoData] [BitAutoData]
[NotificationCustomize] [NotificationCustomize]
public async Task PushSyncNotificationCreateAsync_Notification_Sent( public async Task PushSyncNotificationAsync_Notification_Sent(
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification) SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification)
{ {
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification); await sutProvider.Sut.PushSyncNotificationAsync(notification);
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>() await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
.First() .First()
.Received(1) .Received(1)
.PushSyncNotificationCreateAsync(notification); .PushSyncNotificationAsync(notification);
} }
[Theory] [Theory]
[BitAutoData(false)] [BitAutoData]
[BitAutoData(true)]
[NotificationCustomize] [NotificationCustomize]
[NotificationStatusCustomize] [NotificationStatusCustomize]
public async Task PushSyncNotificationUpdateAsync_Notification_Sent(bool notificationStatusNull, public async Task PushSyncNotificationStatusAsync_Notification_Sent(
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification, SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification,
NotificationStatus notificationStatus) NotificationStatus notificationStatus)
{ {
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification, await sutProvider.Sut.PushSyncNotificationStatusAsync(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); .PushSyncNotificationStatusAsync(notification, notificationStatus);
} }
[Theory] [Theory]