Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into NMSHDB-65-implementat…
Browse files Browse the repository at this point in the history
…ion-of-the-first-performance-test-scenario
  • Loading branch information
Dannyps committed Sep 13, 2024
2 parents eb074c2 + daa7e71 commit e9244a9
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Applications/AdminApi/src/AdminApi/AdminApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="5.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.23.0" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0" />
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.2" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
Expand Down
2 changes: 1 addition & 1 deletion Applications/AdminApi/src/AdminApi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ RUN dotnet publish /p:UseAppHost=false --no-restore --configuration Release --ou
RUN dotnet publish --configuration Release --output /app/publish/health "/src/Applications/HealthCheck/src/HealthCheck.csproj"

#### Build Flutter Admin UI ####
FROM ghcr.io/cirruslabs/flutter:3.24.2 AS flutter-build-env
FROM ghcr.io/cirruslabs/flutter:3.24.3 AS flutter-build-env

COPY Applications/AdminUi /src
WORKDIR /src
Expand Down
2 changes: 1 addition & 1 deletion Applications/ConsumerApi/src/ConsumerApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2"/>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8"/>
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.23.0"/>
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0"/>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8"/>
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.2"/>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Applications/SseServer/src/SseServer/SseServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8"/>
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.23.0"/>
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0"/>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0"/>
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.2"/>
<PackageReference Include="Serilog" Version="4.0.1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Backbone.BuildingBlocks.Application.PushNotifications;
public interface IPushNotificationSender
{
Task SendNotification(IdentityAddress recipient, IPushNotification notification, CancellationToken cancellationToken);
Task SendFilteredNotification(IdentityAddress recipient, IPushNotification notification, IEnumerable<string> excludedDevices, CancellationToken cancellationToken);
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="SimpleBase" Version="4.0.0" />
<PackageReference Include="SimpleBase" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public DatawalletModifiedDomainEventHandler(IPushNotificationSender pushSenderSe
public async Task Handle(DatawalletModifiedDomainEvent domainEvent)
{
var notification = new DatawalletModificationsCreatedPushNotification(domainEvent.ModifiedByDevice);
await _pushSenderService.SendNotification(domainEvent.Identity, notification, CancellationToken.None);
await _pushSenderService.SendFilteredNotification(domainEvent.Identity, notification, [domainEvent.ModifiedByDevice], CancellationToken.None);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="FirebaseAdmin" Version="3.0.0" />
<PackageReference Include="FirebaseAdmin" Version="3.0.1" />
<PackageReference Include="JWT" Version="10.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public async Task SendNotification(IdentityAddress recipient, IPushNotification
{
var registrations = await _pnsRegistrationsRepository.FindWithAddress(recipient, cancellationToken);

await SendNotification(registrations, notification, cancellationToken);
}

public async Task SendFilteredNotification(IdentityAddress recipient, IPushNotification notification, IEnumerable<string> excludedDevices, CancellationToken cancellationToken)
{
var registrations = await _pnsRegistrationsRepository.FindWithAddress(recipient, cancellationToken);
registrations = registrations.Where(x => !excludedDevices.Contains(x.DeviceId));

await SendNotification(registrations, notification, cancellationToken);
}

private async Task SendNotification(IEnumerable<PnsRegistration> registrations, IPushNotification notification, CancellationToken cancellationToken)
{
var groups = registrations.GroupBy(registration => registration.Handle.Platform);

foreach (var group in groups)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Backbone.BuildingBlocks.Application.PushNotifications;
using Backbone.Modules.Devices.Application.DomainEvents.Incoming.DatawalletModificationCreated;
using Backbone.Modules.Devices.Domain.DomainEvents.Incoming.DatawalletModificationCreated;
using Backbone.UnitTestTools.BaseClasses;
using FakeItEasy;
using Xunit;

namespace Backbone.Modules.Devices.Application.Tests.Tests.PushNotifications.DatawalletModified;

public class HandlerTests : AbstractTestsBase
{
[Fact]
public async Task Creating_a_Datawallet_modification_sends_a_filtered_notification()
{
// Arrange
var modifiedByDevice = UnitTestTools.Data.TestDataGenerator.CreateRandomDeviceId();
var identity = UnitTestTools.Data.TestDataGenerator.CreateRandomIdentityAddress();
var mockSender = A.Fake<IPushNotificationSender>();
var handler = new DatawalletModifiedDomainEventHandler(mockSender);
var domainEvent = new DatawalletModifiedDomainEvent { Identity = identity, ModifiedByDevice = modifiedByDevice };

// Act
await handler.Handle(domainEvent);

// Assert
var expectedFilteredDeviceIds = new List<string>([modifiedByDevice.Value]);
A.CallTo(() => mockSender.SendFilteredNotification(identity, A<IPushNotification>._, expectedFilteredDeviceIds, A<CancellationToken>._)).MustHaveHappenedOnceExactly();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Backbone.DevelopmentKit.Identity.ValueObjects;
using Backbone.Modules.Devices.Application.Infrastructure.Persistence.Repository;
using Backbone.Modules.Devices.Application.Infrastructure.PushNotifications;
using Backbone.Modules.Devices.Domain.Aggregates.PushNotifications;
using Backbone.Modules.Devices.Domain.Aggregates.PushNotifications.Handles;
using Backbone.Modules.Devices.Infrastructure.PushNotifications;
Expand Down Expand Up @@ -114,11 +115,84 @@ public async Task Trying_to_delete_non_existing_PnsRegistration_does_nothing()
.MustNotHaveHappened();
}

private static PushService CreateDirectPushService(IPnsRegistrationsRepository pnsRegistrationsRepository)
[Fact]
public async Task SendFilteredNotification_does_not_call_connectors_for_filtered_devices()
{
// Arrange
var filteredDeviceId = CreateRandomDeviceId();
var otherDeviceId = CreateRandomDeviceId();
var address = CreateRandomIdentityAddress();

var fakePnsRegistrationsRepository = A.Fake<IPnsRegistrationsRepository>();
var mockConnector = A.Fake<IPnsConnector>();

var registrationToFilter = CreatePnsRegistration(address, filteredDeviceId);
var otherRegistration = CreatePnsRegistration(address, otherDeviceId);

A.CallTo(() => fakePnsRegistrationsRepository.FindWithAddress(address, A<CancellationToken>._, A<bool>._))!
.Returns<IEnumerable<PnsRegistration>?>(new List<PnsRegistration>
{
registrationToFilter,
otherRegistration
});

var directPushService = CreateDirectPushService(fakePnsRegistrationsRepository, FakePnsConnectorFactory.Returning(mockConnector));

// Act
await directPushService.SendFilteredNotification(address, new TestPushNotification(), [filteredDeviceId], CancellationToken.None);

// Assert
A.CallTo(() => mockConnector.Send(
A<IEnumerable<PnsRegistration>>.That.Matches(r => r.Count() == 1 && r.First() == otherRegistration),
A<TestPushNotification>._))
.MustHaveHappenedOnceExactly();
}

private static PnsRegistration CreatePnsRegistration(IdentityAddress address, DeviceId filteredDeviceId)
{
return new PnsRegistration(address, filteredDeviceId, PnsHandle.Parse(PushNotificationPlatform.Fcm, "someValue").Value, "someAppId", PushEnvironment.Development);
}

private PushService CreateDirectPushService(IPnsRegistrationsRepository pnsRegistrationsRepository, PnsConnectorFactory? pnsConnectorFactory = null)
{
var dummyPnsConnectorFactory = A.Dummy<PnsConnectorFactory>();
var dummyLogger = A.Dummy<ILogger<PushService>>();
pnsConnectorFactory ??= A.Dummy<PnsConnectorFactory>();
var logger = A.Dummy<ILogger<PushService>>();

return new PushService(pnsRegistrationsRepository, dummyPnsConnectorFactory, dummyLogger);
return new PushService(pnsRegistrationsRepository, pnsConnectorFactory, logger);
}

private class FakePnsConnectorFactory : PnsConnectorFactory
{
private readonly IPnsConnector _connector;

private FakePnsConnectorFactory(IPnsConnector connector)
{
_connector = connector;
}

protected override IPnsConnector CreateForFirebaseCloudMessaging()
{
return _connector;
}

protected override IPnsConnector CreateForApplePushNotificationService()
{
return _connector;
}

protected override IPnsConnector CreateForDummy()
{
return _connector;
}

protected override IPnsConnector CreateForSse()
{
return _connector;
}

public static PnsConnectorFactory Returning(IPnsConnector connector)
{
return new FakePnsConnectorFactory(connector);
}
}
}

0 comments on commit e9244a9

Please sign in to comment.