-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
124 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ConsumerApi.Tests.Performance/tools/snapshot-creator-v2/Features/Create/CreateMessages.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Backbone.ConsumerApi.Sdk; | ||
using Backbone.ConsumerApi.Sdk.Authentication; | ||
using Backbone.ConsumerApi.Sdk.Endpoints.Messages.Types.Requests; | ||
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models; | ||
using Backbone.Crypto; | ||
using MediatR; | ||
|
||
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create; | ||
|
||
public record CreateMessages | ||
{ | ||
public record Command( | ||
List<DomainIdentity> Identities, | ||
List<RelationshipAndMessages> RelationshipAndMessages, | ||
string BaseUrlAddress, | ||
ClientCredentials ClientCredentials) : IRequest<List<DomainIdentity>>; | ||
|
||
// ReSharper disable once UnusedMember.Global - Invoked via IMediator | ||
public record CommandHandler : IRequestHandler<Command, List<DomainIdentity>> | ||
{ | ||
public async Task<List<DomainIdentity>> Handle(Command request, CancellationToken cancellationToken) | ||
{ | ||
foreach (var senderIdentity in request.Identities) | ||
{ | ||
var recipientsRelationshipIds = request.RelationshipAndMessages | ||
.Where(relationship => | ||
senderIdentity.PoolAlias == relationship.SenderPoolAlias && | ||
senderIdentity.ConfigurationIdentityAddress == relationship.SenderIdentityAddress) | ||
.Select(r => | ||
( | ||
r.RecipientIdentityAddress, | ||
r.RecipientPoolAlias | ||
)) | ||
.ToList(); | ||
|
||
|
||
var recipientIdentities = request.Identities | ||
.Where(recipient => recipientsRelationshipIds.Any(relationship => | ||
relationship.RecipientPoolAlias == recipient.PoolAlias && | ||
relationship.RecipientIdentityAddress == recipient.ConfigurationIdentityAddress)) | ||
.ToList(); | ||
|
||
|
||
foreach (var recipientIdentity in recipientIdentities) | ||
{ | ||
var sdkClient = Client.CreateForExistingIdentity(request.BaseUrlAddress, request.ClientCredentials, senderIdentity.UserCredentials); | ||
|
||
var messageResponse = await sdkClient.Messages.SendMessage(new SendMessageRequest | ||
{ | ||
Recipients = | ||
[ | ||
new SendMessageRequestRecipientInformation | ||
{ | ||
Address = recipientIdentity.IdentityAddress, | ||
EncryptedKey = ConvertibleString.FromUtf8(new string('A', 152)).BytesRepresentation | ||
} | ||
], | ||
Attachments = [], | ||
Body = ConvertibleString.FromUtf8("Message body").BytesRepresentation | ||
}); | ||
|
||
if (messageResponse.Result is null) continue; | ||
|
||
senderIdentity.Messages.Add((messageResponse.Result.Id, recipientIdentity)); | ||
} | ||
} | ||
|
||
return request.Identities; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters