diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentRequest.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentRequest.cs index e396750af..b301443de 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentRequest.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentRequest.cs @@ -22,8 +22,8 @@ namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts; internal sealed class FindIntentRequest { /// - /// Unique identifier from the application which sent the RaiseIntentRequest type of message. - /// eg.: the instanceId of the application which can be queried from the window.object.composeui.fdc3.config, if it's a webapplication. + /// Unique identifier from the application which sent the FindIntentRequest type of message. + /// eg.: the instanceId of the application which can be queried from the window.object.composeui.fdc3.config, if it's a WebApplication. /// public string Fdc3InstanceId { get; set; } diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentsByContextRequest.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentsByContextRequest.cs index 391f26374..5080915bc 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentsByContextRequest.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/FindIntentsByContextRequest.cs @@ -23,7 +23,7 @@ internal sealed class FindIntentsByContextRequest { /// /// Unique identifier from the application which sent the FindIntentsByContextRequest type of message. - /// eg.: the instanceId of the application which can be queried from the window.object.composeui.fdc3.config, if it's a webapplication. + /// eg.: the instanceId of the application which can be queried from the window.object.composeui.fdc3.config, if it's a WebApplication. /// public string Fdc3InstanceId { get; set; } diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/RaiseIntentRequest.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/RaiseIntentRequest.cs index 7f8643639..d02040488 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/RaiseIntentRequest.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Contracts/RaiseIntentRequest.cs @@ -29,7 +29,7 @@ internal sealed class RaiseIntentRequest /// /// Unique identifier from the application which sent the RaiseIntentRequest type of message. - /// eg.: the instanceId of the application which can be queried from the window.object.composeui.fdc3.config, if it's a webapplication. + /// eg.: the instanceId of the application which can be queried from the window.object.composeui.fdc3.config, if it's a WebApplication. /// public string Fdc3InstanceId { get; set; } @@ -52,9 +52,4 @@ internal sealed class RaiseIntentRequest /// Information about the app that should resolve the raised intent. /// public AppIdentifier? TargetAppIdentifier { get; set; } - - /// - /// Contains error text if an error happened during executing the raiseIntent method. - /// - public string? Error { get; set; } } diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/Fdc3DesktopAgentErrors.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/Fdc3DesktopAgentErrors.cs index 501d6365f..29503176b 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/Fdc3DesktopAgentErrors.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/Fdc3DesktopAgentErrors.cs @@ -35,14 +35,4 @@ public static class Fdc3DesktopAgentErrors /// Indicates that getting the IntentResult from the backend, has no appropriate attribute. /// public const string ResponseHasNoAttribute = $"{nameof(ResponseHasNoAttribute)}"; - - /// - /// Indicates that could not start a module via raiseIntent, etc. - /// - public const string StartModuleFailure = $"{nameof(StartModuleFailure)}"; - - /// - /// Indicates that querying raised intent invocations does not contain an element for the intent. - /// - public const string MissingIntent = $"{nameof(MissingIntent)}"; } \ No newline at end of file diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/ThrowHelper.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/ThrowHelper.cs index 4eb15d89c..3b7597eb4 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/ThrowHelper.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Exceptions/ThrowHelper.cs @@ -25,14 +25,8 @@ public static Fdc3DesktopAgentException MissingAppFromRaisedIntentInvocations(st new(Fdc3DesktopAgentErrors.MissingId, $"Missing Fdc3InstanceId: {instanceId}, when module has added its intent listener and FDC3 is enabled by the application."); public static Fdc3DesktopAgentException MultipleIntentRegisteredToAnAppInstance(string intent) => - new(Fdc3DesktopAgentErrors.MultipleIntent, $"Multiplpe intent were registered to the running instance. Intent: {intent}."); + new(Fdc3DesktopAgentErrors.MultipleIntent, $"Multiple intents were registered to the running instance. Intent: {intent}."); public static Fdc3DesktopAgentException TargetInstanceUnavailable() => new(ResolveError.TargetAppUnavailable, $"Target app is unavailable when intent was raised."); - - public static Fdc3DesktopAgentException StartModuleFailure(Exception exception) => - new(Fdc3DesktopAgentErrors.StartModuleFailure, $"Could not start module when intent was raised.", exception); - - public static Fdc3DesktopAgentException MissingIntentForMessage(string messageId, string intent) => - new(Fdc3DesktopAgentErrors.MissingIntent, $"Could not found raised intent invocations for message: {messageId} with intent: {intent}"); } \ No newline at end of file diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Fdc3DesktopAgent.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Fdc3DesktopAgent.cs index 41297ed7d..c23ca9e50 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Fdc3DesktopAgent.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Fdc3DesktopAgent.cs @@ -32,6 +32,8 @@ using Icon = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.Icon; using IntentMetadata = Finos.Fdc3.AppDirectory.IntentMetadata; using Screenshot = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.Screenshot; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol; +using System.Collections.Generic; namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent; @@ -70,7 +72,7 @@ public async ValueTask AddUserChannel(UserChannel userChannel) public async Task StartAsync(CancellationToken cancellationToken) { var observable = _moduleLoader.LifetimeEvents.ToAsyncObservable(); - var subscription = await observable.SubscribeAsync(async (lifetimeEvent) => + var subscription = await observable.SubscribeAsync(async lifetimeEvent => { switch (lifetimeEvent) { @@ -126,24 +128,38 @@ public async ValueTask FindIntent(FindIntentRequest? request //This function returns null, if the app could not be accepted based on the intent (required), context (optional in request), resultType (optional in request) //else for consistency it will return a single element array containing the intentMetadata which is allowed by the request. - Func?> selector = (fdc3App) => + Func, IEnumerable?> selector = (fdc3App, _) => { - if (fdc3App.Interop?.Intents?.ListensFor == null || !fdc3App.Interop.Intents.ListensFor.TryGetValue(request.Intent!, out var intentMetadata)) return null; - if (request.Context != null && (intentMetadata.Contexts == null || !intentMetadata.Contexts.Contains(request.Context.Type)) && request.Context?.Type != ContextTypes.Nothing) return null; - if (request.ResultType != null && (intentMetadata.ResultType == null || !intentMetadata.ResultType.Contains(request.ResultType))) return null; - return new[] { intentMetadata }; + if (fdc3App.Interop?.Intents?.ListensFor == null + || !fdc3App.Interop.Intents.ListensFor.TryGetValue(request.Intent!, out var intentMetadata)) + { + return null; + } + + if (request.Context != null + && (intentMetadata.Contexts == null || !intentMetadata.Contexts.Contains(request.Context.Type)) + && request.Context?.Type != ContextTypes.Nothing) + { + return null; + } + + if (request.ResultType != null + && (intentMetadata.ResultType == null || !intentMetadata.ResultType.Contains(request.ResultType))) + { + return null; + } + + return [intentMetadata]; }; - var appIntents = await GetAppIntentsByRequest(selector, null, false); + var appIntents = await GetAppIntentsByRequest(selector, null); - if (!appIntents.Any()) + if (!appIntents.TryGetValue(request.Intent, out var appIntent)) { return FindIntentResponse.Failure(ResolveError.NoAppsFound); } - return appIntents.Count > 1 - ? FindIntentResponse.Failure(ResolveError.IntentDeliveryFailed) - : FindIntentResponse.Success(appIntents.Values.First()); + return FindIntentResponse.Success(appIntent); } public async ValueTask FindIntentsByContext(FindIntentsByContextRequest? request) @@ -155,15 +171,27 @@ public async ValueTask FindIntentsByContext(FindIn //This function returns null, if the app could not be accepted based on the context(optional in request), resultType (optional in request) //else for consistency it will return a collection containing the intentMetadata which is allowed by the request. - Func?> selector = (fdc3App) => + Func, IEnumerable?> selector = (fdc3App, _) => { var intentMetadataCollection = new List(); if (fdc3App.Interop?.Intents?.ListensFor?.Values != null) { foreach (var intentMetadata in fdc3App.Interop.Intents.ListensFor.Values) { - if (intentMetadata.Contexts == null || !intentMetadata.Contexts.Contains(request.Context?.Type) && request.Context?.Type != ContextTypes.Nothing) continue; - if (request.ResultType != null && (intentMetadata.ResultType == null || !intentMetadata.ResultType.Contains(request.ResultType))) continue; + if (intentMetadata.Contexts == null + || !intentMetadata.Contexts.Contains(request.Context?.Type) + && request.Context?.Type != ContextTypes.Nothing) + { + continue; + } + + if (request.ResultType != null + && (intentMetadata.ResultType == null + || !intentMetadata.ResultType.Contains(request.ResultType))) + { + continue; + } + intentMetadataCollection.Add(intentMetadata); } } @@ -176,7 +204,7 @@ public async ValueTask FindIntentsByContext(FindIn return null; }; - var appIntents = await GetAppIntentsByRequest(selector, null, false); + var appIntents = await GetAppIntentsByRequest(selector, null); if (!appIntents.Any()) { @@ -211,7 +239,6 @@ public async ValueTask GetIntentResult(GetIntentResultR } catch (TimeoutException) { - return GetIntentResultResponse.Failure(ResolveError.IntentDeliveryFailed); } } @@ -261,14 +288,15 @@ public async ValueTask> AddIntentListe resolver.AddIntentListener(request.Intent); var resolutions = new List(); - foreach (var raisedIntent in resolver.RaiseIntentResolutions.Where(invocation => invocation.Intent == request.Intent)) + foreach (var raisedIntent in resolver.RaiseIntentResolutions.Where( + invocation => invocation.Intent == request.Intent && !invocation.IsResolved)) { - var resolution = await RaiseIntentResolution( - raisedIntent.RaiseIntentMessageId, - raisedIntent.Intent, - raisedIntent.Context, - request.Fdc3InstanceId, - raisedIntent.OriginFdc3InstanceId); + var resolution = await GetRaiseIntentResolutionMessage( + raisedIntent.RaiseIntentMessageId, + raisedIntent.Intent, + raisedIntent.Context, + request.Fdc3InstanceId, + raisedIntent.OriginFdc3InstanceId); if (resolution != null) { @@ -282,19 +310,17 @@ public async ValueTask> AddIntentListe RaiseIntentResolutionMessages = resolutions }; } - else - { - var createdResolver = _raisedIntentResolutions.GetOrAdd( - new(request.Fdc3InstanceId), - new RaisedIntentRequestHandler()); - createdResolver.AddIntentListener(request.Intent); + var createdResolver = _raisedIntentResolutions.GetOrAdd( + new(request.Fdc3InstanceId), + new RaisedIntentRequestHandler(_loggerFactory.CreateLogger())); - return new() - { - Response = IntentListenerResponse.SubscribeSuccess(), - }; - } + createdResolver.AddIntentListener(request.Intent); + + return new() + { + Response = IntentListenerResponse.SubscribeSuccess(), + }; case SubscribeState.Unsubscribe: @@ -326,28 +352,41 @@ public async ValueTask> RaiseIntent(Raise }; } - if (!string.IsNullOrEmpty(request.Error)) - { - return new() - { - Response = RaiseIntentResponse.Failure(request.Error) - }; - } - //This function returns null, if the app could not be accepted based on the intent (required), context (optional in request), appIdentifier (optional in request) //else for consistency it will return a single element array containing the intentMetadata which is allowed by the request. - Func?> selector = (fdc3App) => + Func, IEnumerable?> selector = (fdc3App, appIntents) => { - if (fdc3App.Interop?.Intents?.ListensFor == null || !fdc3App.Interop.Intents.ListensFor.TryGetValue(request.Intent!, out var intentMetadata)) return null; - if (request.Context != null && (intentMetadata.Contexts == null || !intentMetadata.Contexts.Contains(request.Context.Type)) && request.Context?.Type != ContextTypes.Nothing) return null; - if (request.TargetAppIdentifier != null && (fdc3App.AppId != request.TargetAppIdentifier.AppId)) return null; - return new[] { intentMetadata }; + //If the user selects an application from the AppDirectory instead of the its running instance + if (request.Selected && appIntents.TryGetValue(request.Intent, out var result) && result.Apps.Any()) + { + return null; + } + + if (fdc3App.Interop?.Intents?.ListensFor == null + || !fdc3App.Interop.Intents.ListensFor.TryGetValue(request.Intent!, out var intentMetadata)) + { + return null; + } + + if (request.Context != null + && (intentMetadata.Contexts == null || !intentMetadata.Contexts.Contains(request.Context.Type)) + && request.Context?.Type != ContextTypes.Nothing) + { + return null; + } + + if (request.TargetAppIdentifier != null && (fdc3App.AppId != request.TargetAppIdentifier.AppId)) + { + return null; + } + + return [intentMetadata]; }; - var appIntents = await GetAppIntentsByRequest(selector, request.TargetAppIdentifier, request.Selected); + var appIntents = await GetAppIntentsByRequest(selector, request.TargetAppIdentifier); //No intents were found which would have the right information to handle the raised intent - if (!appIntents.Any()) + if (!appIntents.TryGetValue(request.Intent, out var appIntent) || !appIntent.Apps.Any()) { return new() { @@ -355,18 +394,6 @@ public async ValueTask> RaiseIntent(Raise }; } - //Here we have used a method, which could return multiple IAppIntents to multiple intents, this is for abstracting method to findIntent, findIntentsByContext, etc. - //Here we should get just one IAppIntent, as the intent field is required (at least fdc3.nothing) - if (appIntents.Count > 1) - { - return new() - { - Response = RaiseIntentResponse.Failure(ResolveError.IntentDeliveryFailed) - }; - } - - var appIntent = appIntents.Values.First(); - if (appIntent.Apps.Count() == 1) { return await RaiseIntentToApplication( @@ -378,7 +405,7 @@ public async ValueTask> RaiseIntent(Raise } //Resolve to one app via ResolverUI. - var result = await WaitForResolverUIAsync(request.Intent, appIntent.Apps); + var result = await WaitForResolverUiAsync(request.Intent, appIntent.Apps); if (result != null) { @@ -395,11 +422,11 @@ public async ValueTask> RaiseIntent(Raise { Response = RaiseIntentResponse.Failure(ResolveError.UserCancelledResolution) }; - } + } } - //TODO: Placeholder for the right implementation of returning the choosen application from the ResolverUI. - private async Task WaitForResolverUIAsync(string intent, IEnumerable apps) + //TODO: Placeholder for the right implementation of returning the chosen application from the ResolverUI. + private async Task WaitForResolverUiAsync(string intent, IEnumerable apps) { Task IsIntentListenerRegisteredAsync(AppMetadata appMetadata) { @@ -453,80 +480,77 @@ private async ValueTask> RaiseIntentToApp if (registeredFdc3App.IsIntentListenerRegistered(intent)) { - resolution = await RaiseIntentResolution(raisedIntentMessageId, intent, context, targetAppMetadata.InstanceId, sourceFdc3InstanceId); + resolution = await GetRaiseIntentResolutionMessage(raisedIntentMessageId, intent, context, targetAppMetadata.InstanceId, sourceFdc3InstanceId); } return new() { Response = RaiseIntentResponse.Success(raisedIntentMessageId, intent, targetAppMetadata), RaiseIntentResolutionMessages = resolution != null - ? new[] { resolution } + ? [resolution] : Enumerable.Empty() }; } - else + + try { - try - { - var fdc3InstanceId = Guid.NewGuid(); - var startRequest = new StartRequest( - targetAppMetadata.AppId, //TODO: possible remove some identifier like @"fdc3." - new List>() - { - { new(Fdc3StartupParameters.Fdc3InstanceId, fdc3InstanceId.ToString()) } - }); + var fdc3InstanceId = Guid.NewGuid(); + var startRequest = new StartRequest( + targetAppMetadata.AppId, //TODO: possible remove some identifier like @"fdc3." + [ + new(Fdc3StartupParameters.Fdc3InstanceId, fdc3InstanceId.ToString()) + ]); - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(); - if (_pendingStartRequests.TryAdd(startRequest, taskCompletionSource)) + if (_pendingStartRequests.TryAdd(startRequest, taskCompletionSource)) + { + var moduleInstance = await _moduleLoader.StartModule(startRequest); + + if (moduleInstance == null) { - var moduleInstance = await _moduleLoader.StartModule(startRequest); + var exception = ThrowHelper.TargetInstanceUnavailable(); - if (moduleInstance == null) + if (!_pendingStartRequests.TryRemove(startRequest, out _)) { - var exception = ThrowHelper.TargetInstanceUnavailable(); - - if (!_pendingStartRequests.TryRemove(startRequest, out _)) - { - _logger.LogWarning($"Could not remove {nameof(StartRequest)} from the pending requests. ModuleId: {startRequest.ModuleId}."); - } - - taskCompletionSource.TrySetException(exception); + _logger.LogWarning($"Could not remove {nameof(StartRequest)} from the pending requests. ModuleId: {startRequest.ModuleId}."); } - await taskCompletionSource.Task; + taskCompletionSource.TrySetException(exception); } - var raisedIntentMessageId = StoreRaisedIntentForTarget(messageId, fdc3InstanceId.ToString(), intent, context, sourceFdc3InstanceId); + await taskCompletionSource.Task; + } - var target = new AppMetadata() - { - AppId = targetAppMetadata.AppId, - InstanceId = fdc3InstanceId.ToString(), - Name = targetAppMetadata.Name, - Version = targetAppMetadata.Version, - Title = targetAppMetadata.Title, - Tooltip = targetAppMetadata.Tooltip, - Description = targetAppMetadata.Description, - Icons = targetAppMetadata.Icons.Select(Icon.GetIcon), - Screenshots = targetAppMetadata.Screenshots.Select(Screenshot.GetScreenshot), - ResultType = targetAppMetadata.ResultType - }; + var raisedIntentMessageId = StoreRaisedIntentForTarget(messageId, fdc3InstanceId.ToString(), intent, context, sourceFdc3InstanceId); - return new() - { - Response = RaiseIntentResponse.Success(raisedIntentMessageId, intent, target) - }; - } - catch (Fdc3DesktopAgentException exception) + var target = new AppMetadata { - _logger.LogError(exception, "Error while starting module."); + AppId = targetAppMetadata.AppId, + InstanceId = fdc3InstanceId.ToString(), + Name = targetAppMetadata.Name, + Version = targetAppMetadata.Version, + Title = targetAppMetadata.Title, + Tooltip = targetAppMetadata.Tooltip, + Description = targetAppMetadata.Description, + Icons = targetAppMetadata.Icons.Select(Icon.GetIcon), + Screenshots = targetAppMetadata.Screenshots.Select(Screenshot.GetScreenshot), + ResultType = targetAppMetadata.ResultType + }; - return new() - { - Response = RaiseIntentResponse.Failure(exception.ToString()), - }; - } + return new() + { + Response = RaiseIntentResponse.Success(raisedIntentMessageId, intent, target) + }; + } + catch (Fdc3DesktopAgentException exception) + { + _logger.LogError(exception, "Error while starting module."); + + return new() + { + Response = RaiseIntentResponse.Failure(exception.ToString()), + }; } } @@ -534,9 +558,12 @@ private async ValueTask> RaiseIntentToApp { RaiseIntentResolutionInvocation? resolution; while ( - !_raisedIntentResolutions.TryGetValue(new Guid(request.TargetAppIdentifier.InstanceId!), out var resolver) - || !resolver.TryGetRaisedIntentResult(request.MessageId, request.Intent, out resolution) - || (resolution.ResultChannelId == null && resolution.ResultChannelType == null && resolution.ResultContext == null && resolution.ResultVoid == null)) + !_raisedIntentResolutions.TryGetValue(new Guid(request.TargetAppIdentifier.InstanceId!), out var resolver) + || !resolver.TryGetRaisedIntentResult(request.MessageId, request.Intent, out resolution) + || (resolution.ResultChannelId == null + && resolution.ResultChannelType == null + && resolution.ResultContext == null + && resolution.ResultVoid == null)) { await Task.Delay(100); } @@ -552,30 +579,30 @@ private string StoreRaisedIntentForTarget( string sourceFdc3InstanceId) { var invocation = new RaiseIntentResolutionInvocation( - raiseIntentMessageId: messageId, - intent: intent, - originFdc3InstanceId: sourceFdc3InstanceId, - contextToHandle: context); + raiseIntentMessageId: messageId, + intent: intent, + originFdc3InstanceId: sourceFdc3InstanceId, + contextToHandle: context); _raisedIntentResolutions.AddOrUpdate( - new(targetFdc3InstanceId), - _ => - { - var resolver = new RaisedIntentRequestHandler(); - resolver.AddRaiseIntentToHandle(invocation); - return resolver; - }, - (key, oldValue) => oldValue.AddRaiseIntentToHandle(invocation)); + new(targetFdc3InstanceId), + _ => + { + var resolver = new RaisedIntentRequestHandler(_loggerFactory.CreateLogger()); + resolver.AddRaiseIntentToHandle(invocation); + return resolver; + }, + (key, oldValue) => oldValue.AddRaiseIntentToHandle(invocation)); return invocation.RaiseIntentMessageId; } - //Publishing intent resolution request to the fdc3 clients, they will receive the message and start their intenthandler appropriately, and send a store request back to the backend. - private Task RaiseIntentResolution(string raisedIntentMessageId, string intent, Context context, string targetId, string sourceFdc3InstanceId) + //Publishing intent resolution request to the fdc3 clients, they will receive the message and start their IntentHandler appropriately, and send a store request back to the backend. + private Task GetRaiseIntentResolutionMessage(string raisedIntentMessageId, string intent, Context context, string targetId, string sourceFdc3InstanceId) { if (_runningModules.TryGetValue(new(sourceFdc3InstanceId), out var sourceApp)) { - var sourceAppIdentifier = new AppIdentifier() + var sourceAppIdentifier = new AppIdentifier { AppId = sourceApp.AppId, InstanceId = sourceFdc3InstanceId @@ -586,11 +613,11 @@ private string StoreRaisedIntentForTarget( { Intent = intent, TargetModuleInstanceId = targetId, - Request = new RaiseIntentResolutionRequest() + Request = new RaiseIntentResolutionRequest { MessageId = raisedIntentMessageId, Context = context, - ContextMetadata = new ContextMetadata() + ContextMetadata = new ContextMetadata { Source = sourceAppIdentifier } @@ -602,20 +629,14 @@ private string StoreRaisedIntentForTarget( } private async Task> GetAppIntentsByRequest( - Func?> selector, - IAppIdentifier? targetAppIdentifier, - bool selected) + Func, IEnumerable?> selector, + IAppIdentifier? targetAppIdentifier) { var appIntents = new Dictionary(); if (targetAppIdentifier?.InstanceId == null) { appIntents = await GetAppIntentsFromAppDirectory(selector, targetAppIdentifier, appIntents); - - if (selected && appIntents.Count > 0) - { - return appIntents; - } } appIntents = GetAppIntentsFromRunningModules(selector, targetAppIdentifier, appIntents); @@ -623,35 +644,52 @@ private async Task> GetAppIntentsByRequest( return appIntents; } + + private async Task GetAppIntentsByRequest( + Action selector, + IAppIdentifier? targetAppIdentifier) + { + if (targetAppIdentifier?.InstanceId == null) + { + await GetAppIntentsFromAppDirectory(selector, targetAppIdentifier); + } + + GetAppIntentsFromRunningModules(selector, targetAppIdentifier); + } + private Dictionary GetAppIntentsFromRunningModules( - Func?> selector, + Func, IEnumerable?> selector, IAppIdentifier? targetAppIdentifier, Dictionary appIntents) { foreach (var app in _runningModules) { - if (targetAppIdentifier?.InstanceId != null + if (targetAppIdentifier?.InstanceId != null && Guid.TryParse(targetAppIdentifier.InstanceId, out var instanceId) && instanceId != app.Key) { continue; } - var intentMetadataCollection = selector(app.Value); + var intentMetadataCollection = selector(app.Value, appIntents); if (intentMetadataCollection == null) { continue; } - appIntents = GetAppIntentsFromIntentMetadaCollection(app.Value, app.Key.ToString(), intentMetadataCollection, appIntents); + appIntents = GetAppIntentsFromIntentMetadataCollection( + app.Value, + app.Key.ToString(), + intentMetadataCollection, + appIntents); } return appIntents; } private async Task> GetAppIntentsFromAppDirectory( - Func?> selector, + Func, IEnumerable?> selector, IAppIdentifier? targetAppIdentifier, Dictionary appIntents) { @@ -662,20 +700,20 @@ private async Task> GetAppIntentsFromAppDirectory( continue; } - var intentMetadataCollection = selector(app); + var intentMetadataCollection = selector(app, appIntents); if (intentMetadataCollection == null) { continue; } - appIntents = GetAppIntentsFromIntentMetadaCollection(app, null, intentMetadataCollection, appIntents); + appIntents = GetAppIntentsFromIntentMetadataCollection(app, null, intentMetadataCollection, appIntents); } return appIntents; } - private Dictionary GetAppIntentsFromIntentMetadaCollection( + private Dictionary GetAppIntentsFromIntentMetadataCollection( Fdc3App app, string? instanceId, IEnumerable intentMetadataCollection, @@ -685,6 +723,81 @@ private Dictionary GetAppIntentsFromIntentMetadaCollection( { var appMetadata = new AppMetadata() + { + AppId = app.AppId, + InstanceId = instanceId, + Name = app.Name, + Version = app.Version, + Title = app.Title, + Tooltip = app.ToolTip, + Description = app.Description, + Icons = app.Icons == null ? Enumerable.Empty() : app.Icons.Select(Icon.GetIcon), + Screenshots = app.Screenshots == null + ? Enumerable.Empty() + : app.Screenshots.Select(Screenshot.GetScreenshot), + ResultType = intentMetadata.ResultType + }; + + if (!appIntents.TryGetValue(intentMetadata.Name, out var appIntent)) + { + appIntent = new AppIntent + { + Intent = new Protocol.IntentMetadata + { Name = intentMetadata.Name, DisplayName = intentMetadata.DisplayName }, + Apps = Enumerable.Empty() + }; + + appIntents.Add(intentMetadata.Name, appIntent); + } + + appIntent.Apps = appIntent.Apps.Append(appMetadata); + } + + return appIntents; + } + + private async Task GetAppIntentsFromAppDirectory( + Action selector, + IAppIdentifier? targetAppIdentifier) + { + foreach (var app in await _appDirectory.GetApps()) + { + if (targetAppIdentifier != null && targetAppIdentifier.AppId != app.AppId) + { + continue; + } + + selector(app, null); + } + } + + private void GetAppIntentsFromRunningModules( + Action selector, + IAppIdentifier? targetAppIdentifier) + { + foreach (var app in _runningModules) + { + if (targetAppIdentifier?.InstanceId != null + && Guid.TryParse(targetAppIdentifier.InstanceId, out var instanceId) + && instanceId != app.Key) + { + continue; + } + + selector(app.Value, app.Key.ToString()); + } + } + + private Dictionary GetAppIntentsFromIntentMetadataCollection( + Fdc3App app, + string? instanceId, + IEnumerable intentMetadataCollection, + ref Dictionary appIntents) + { + foreach (var intentMetadata in intentMetadataCollection) + { + var appMetadata = + new AppMetadata { AppId = app.AppId, InstanceId = instanceId, @@ -695,12 +808,13 @@ private Dictionary GetAppIntentsFromIntentMetadaCollection( Description = app.Description, Icons = app.Icons == null ? Enumerable.Empty() : app.Icons.Select(Icon.GetIcon), Screenshots = app.Screenshots == null ? Enumerable.Empty() : app.Screenshots.Select(Screenshot.GetScreenshot), - ResultType = intentMetadata?.ResultType + ResultType = intentMetadata.ResultType }; - if (appIntents.ContainsKey(intentMetadata!.Name)) + // request.Intent and intentMetadata.Name should be equal: https://github.com/finos/fdc3-dotnet/blob/main/src/Fdc3.Json/Serialization/IntentsConverter.cs#L29-L32 + if (appIntents.ContainsKey(intentMetadata.Name)) { - appIntents[intentMetadata.Name] = new AppIntent() + appIntents[intentMetadata.Name] = new AppIntent { Intent = new Protocol.IntentMetadata { Name = intentMetadata.Name, DisplayName = intentMetadata.DisplayName }, Apps = appIntents[intentMetadata.Name].Apps.Append(appMetadata) @@ -710,10 +824,10 @@ private Dictionary GetAppIntentsFromIntentMetadaCollection( { appIntents.Add( intentMetadata.Name, - new AppIntent() + new AppIntent { Intent = new Protocol.IntentMetadata { Name = intentMetadata.Name, DisplayName = intentMetadata.DisplayName }, - Apps = new List() { appMetadata } + Apps = new List { appMetadata } }); } } @@ -723,10 +837,10 @@ private Dictionary GetAppIntentsFromIntentMetadaCollection( private Task RemoveModuleAsync(IModuleInstance instance) { - try + var fdc3InstanceId = GetFdc3InstanceId(instance); + + if (fdc3InstanceId != null) { - var fdc3InstanceId = GetFdc3InstanceId(instance); - if (!_runningModules.TryRemove(new(fdc3InstanceId), out _)) { _logger.LogError($"Could not remove the closed window with instanceId: {fdc3InstanceId}."); @@ -737,10 +851,6 @@ private Task RemoveModuleAsync(IModuleInstance instance) taskCompletionSource.SetException(ThrowHelper.TargetInstanceUnavailable()); } } - catch (Fdc3DesktopAgentException exception) - { - _logger.LogError(exception, $"Exception thrown while removing module: {instance.Manifest.Id}, {instance.Manifest.Name} from running instances in FDC3DesktopAgent."); - } return Task.CompletedTask; } @@ -757,9 +867,9 @@ private async Task AddOrUpdateModuleAsync(IModuleInstance instance) taskCompletionSource.SetResult(instance); } } - catch (AppNotFoundException) + catch (AppNotFoundException exception) { - _logger.LogError($"Could not retrieve app: {instance.Manifest.Id} from AppDirectory."); + _logger.LogError(exception, $"Could not retrieve app: {instance.Manifest.Id} from AppDirectory."); return; } @@ -767,8 +877,8 @@ private async Task AddOrUpdateModuleAsync(IModuleInstance instance) //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id _runningModules.GetOrAdd( - new(fdc3InstanceId), - _ => fdc3App); + new(fdc3InstanceId), + _ => fdc3App); } private bool IsFdc3StartedModule(IModuleInstance instance, out string instanceId) @@ -785,14 +895,14 @@ private bool IsFdc3StartedModule(IModuleInstance instance, out string instanceId return true; } - private string GetFdc3InstanceId(IModuleInstance instance) + private string? GetFdc3InstanceId(IModuleInstance instance) { if (!IsFdc3StartedModule(instance, out var fdc3InstanceId)) { - var startupProperties = instance.GetProperties().FirstOrDefault(p => p is Fdc3StartupProperties); + var startupProperties = instance.GetProperties().FirstOrDefault(property => property is Fdc3StartupProperties); return startupProperties == null - ? throw ThrowHelper.MissingFdc3InstanceId(instance.Manifest.Id) + ? null : ((Fdc3StartupProperties) startupProperties).InstanceId; } diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.cs index d0379b053..fdba69c2f 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.cs @@ -73,9 +73,9 @@ public async ValueTask HandleAddUserChannel(string id) internal ValueTask HandleFindChannel(FindChannelRequest? request, MessageContext context) { return ValueTask.FromResult( - _desktopAgent.FindChannel(request!.ChannelId, request!.ChannelType) - ? FindChannelResponse.Success - : FindChannelResponse.Failure(ChannelError.NoChannelFound)); + _desktopAgent.FindChannel(request!.ChannelId, request!.ChannelType) + ? FindChannelResponse.Success + : FindChannelResponse.Failure(ChannelError.NoChannelFound)); } internal async ValueTask HandleFindIntent(FindIntentRequest? request, MessageContext context) @@ -90,25 +90,18 @@ public async ValueTask HandleAddUserChannel(string id) internal async ValueTask HandleRaiseIntent(RaiseIntentRequest? request, MessageContext context) { - try + var result = await _desktopAgent.RaiseIntent(request); + if (result.RaiseIntentResolutionMessages.Any()) { - var result = await _desktopAgent.RaiseIntent(request); - if (result.RaiseIntentResolutionMessages.Any()) + foreach (var message in result.RaiseIntentResolutionMessages) { - foreach (var message in result.RaiseIntentResolutionMessages) - { - await _messageRouter.PublishAsync( - Fdc3Topic.RaiseIntentResolution(message.Intent, message.TargetModuleInstanceId), - MessageBuffer.Factory.CreateJson(message.Request, _jsonSerializerOptions)); - } + await _messageRouter.PublishAsync( + Fdc3Topic.RaiseIntentResolution(message.Intent, message.TargetModuleInstanceId), + MessageBuffer.Factory.CreateJson(message.Request, _jsonSerializerOptions)); } - - return result.Response; - } - catch (Fdc3DesktopAgentException) - { - throw; } + + return result.Response; } internal async ValueTask HandleAddIntentListener(IntentListenerRequest? request, MessageContext context) @@ -186,13 +179,13 @@ public async Task StopAsync(CancellationToken cancellationToken) { var unregisteringTasks = new ValueTask[] { - _messageRouter.UnregisterServiceAsync(Fdc3Topic.FindChannel, cancellationToken), - _messageRouter.UnregisterServiceAsync(Fdc3Topic.FindIntent, cancellationToken), - _messageRouter.UnregisterServiceAsync(Fdc3Topic.RaiseIntent, cancellationToken), - _messageRouter.UnregisterServiceAsync(Fdc3Topic.FindIntentsByContext, cancellationToken), - _messageRouter.UnregisterServiceAsync(Fdc3Topic.GetIntentResult, cancellationToken), - _messageRouter.UnregisterServiceAsync(Fdc3Topic.SendIntentResult, cancellationToken), - _messageRouter.UnregisterServiceAsync(Fdc3Topic.AddIntentListener, cancellationToken) + _messageRouter.UnregisterServiceAsync(Fdc3Topic.FindChannel, cancellationToken), + _messageRouter.UnregisterServiceAsync(Fdc3Topic.FindIntent, cancellationToken), + _messageRouter.UnregisterServiceAsync(Fdc3Topic.RaiseIntent, cancellationToken), + _messageRouter.UnregisterServiceAsync(Fdc3Topic.FindIntentsByContext, cancellationToken), + _messageRouter.UnregisterServiceAsync(Fdc3Topic.GetIntentResult, cancellationToken), + _messageRouter.UnregisterServiceAsync(Fdc3Topic.SendIntentResult, cancellationToken), + _messageRouter.UnregisterServiceAsync(Fdc3Topic.AddIntentListener, cancellationToken) }; await SafeWaitAsync(unregisteringTasks); diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaiseIntentResolutionInvocation.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaiseIntentResolutionInvocation.cs index 11c276cd4..fe226b6bc 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaiseIntentResolutionInvocation.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaiseIntentResolutionInvocation.cs @@ -50,4 +50,5 @@ public RaiseIntentResolutionInvocation( public ChannelType? ResultChannelType { get; set; } public bool? ResultVoid { get; set; } public string? ResultError { get; set; } + public bool IsResolved { get; set; } = false; } diff --git a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaisedIntentRequestHandler.cs b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaisedIntentRequestHandler.cs index 488b6deca..de1d35023 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaisedIntentRequestHandler.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Infrastructure/Internal/RaisedIntentRequestHandler.cs @@ -15,6 +15,8 @@ using Finos.Fdc3.Context; using Finos.Fdc3; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Exceptions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; @@ -24,13 +26,28 @@ internal class RaisedIntentRequestHandler private readonly object _raiseIntentInvocationsLock = new(); private readonly List _registeredIntentListeners = new(); private readonly List _raiseIntentResolutions = new(); + private readonly ILogger _logger; + public IEnumerable IntentListeners => _registeredIntentListeners; public IEnumerable RaiseIntentResolutions => _raiseIntentResolutions; + public RaisedIntentRequestHandler(ILogger? logger = null) + { + _logger = logger ?? NullLogger.Instance; + } + public RaisedIntentRequestHandler AddIntentListener(string intent) { lock (_intentListenersLock) { + if (_registeredIntentListeners.Contains(intent)) + { + if (_logger.IsEnabled(LogLevel.Warning)) + { + _logger.LogWarning($"Multiple IntentHandlers are registered to the intent: {intent}."); + } + } + _registeredIntentListeners.Add(intent); return this; } @@ -84,6 +101,7 @@ public RaisedIntentRequestHandler AddIntentResult( raisedIntentInvocation.ResultContext = context; raisedIntentInvocation.ResultVoid = voidResult; raisedIntentInvocation.ResultError = error; + raisedIntentInvocation.IsResolved = true; } else if (raisedIntentInvocations.Count() > 1) { @@ -98,7 +116,11 @@ public bool TryGetRaisedIntentResult(string messageId, string intent, out RaiseI { lock (_raiseIntentInvocationsLock) { - var raiseIntentInvocations = _raiseIntentResolutions.Where(raiseIntentInvocation => raiseIntentInvocation.RaiseIntentMessageId == messageId && raiseIntentInvocation.Intent == intent); + var raiseIntentInvocations = _raiseIntentResolutions.Where(raiseIntentInvocation => + raiseIntentInvocation.RaiseIntentMessageId == messageId + && raiseIntentInvocation.Intent == intent + && raiseIntentInvocation.IsResolved); + if (raiseIntentInvocations.Any()) { if (raiseIntentInvocations.Count() > 1) diff --git a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/EndToEndTests.cs b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/EndToEndTests.cs index d64c8db65..5ef088fc7 100644 --- a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/EndToEndTests.cs +++ b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/EndToEndTests.cs @@ -14,973 +14,960 @@ using System.Text.Json; +using Finos.Fdc3; +using Finos.Fdc3.Context; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Converters; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Exceptions; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.Helpers; using MorganStanley.ComposeUI.Messaging.Client.WebSocket; using MorganStanley.ComposeUI.ModuleLoader; -using Finos.Fdc3; -using Finos.Fdc3.Context; -using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata; -using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent; using AppIdentifier = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIdentifier; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; +using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent; +using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata; +using IntentMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.IntentMetadata; -namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests +namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests; + +public class EndToEndTests : IAsyncLifetime { - public class EndToEndTests : IAsyncLifetime - { - private IHost _host; - private IMessageRouter _messageRouter; - private ServiceProvider _clientServices; - private readonly Uri _webSocketUri = new("ws://localhost:7098/ws"); - private const string TestChannel = "testChannel"; - private readonly UserChannelTopics _topics = new UserChannelTopics(TestChannel); - private const string AccessToken = "token"; - private JsonSerializerOptions _options; - private IModuleLoader _moduleLoader; - private readonly object _runningAppsLock = new(); - private IDisposable _runningAppsObserver; - private readonly List _runningApps = new(); - - public async Task InitializeAsync() - { - // Create the backend side - IHostBuilder builder = new HostBuilder(); - builder.ConfigureServices( - services => - { - services.AddMessageRouterServer( - s => s.UseWebSockets( - opt => - { - opt.RootPath = _webSocketUri.AbsolutePath; - opt.Port = _webSocketUri.Port; - })); - services.AddMessageRouter(mr => mr.UseServer()); - - services.AddFdc3AppDirectory( - _ => _.Source = new Uri($"file:\\\\{Directory.GetCurrentDirectory()}\\TestUtils\\appDirectorySample.json")); - - services.AddModuleLoader(); - - services.AddFdc3DesktopAgent( - fdc3 => fdc3.Configure( - builder => - { - builder.ChannelId = TestChannel; - })); - }); + private const string TestChannel = "testChannel"; + private const string AccessToken = "token"; + private readonly List _runningApps = new(); + private readonly object _runningAppsLock = new(); + private readonly UserChannelTopics _topics = new(TestChannel); + private readonly Uri _webSocketUri = new("ws://localhost:7098/ws"); + private ServiceProvider _clientServices; + + private int _counter; + private IHost _host; + private IMessageRouter _messageRouter; + private IModuleLoader _moduleLoader; + private JsonSerializerOptions _options; + private IDisposable _runningAppsObserver; + + private MessageBuffer EmptyContextType => MessageBuffer.Factory.CreateJson(new GetCurrentContextRequest()); - _host = builder.Build(); - await _host.StartAsync(); + private MessageBuffer ContextType => + MessageBuffer.Factory.CreateJson(new GetCurrentContextRequest {ContextType = new Contact().Type}); - // Create a client acting in place of an application - _clientServices = new ServiceCollection() - .AddMessageRouter( - mr => mr.UseWebSocket( - new MessageRouterWebSocketOptions + private MessageBuffer OtherContextType => + MessageBuffer.Factory.CreateJson(new GetCurrentContextRequest {ContextType = new Email(null).Type}); + + private MessageBuffer FindRequest => MessageBuffer.Factory.CreateJson( + new FindChannelRequest {ChannelId = TestChannel, ChannelType = ChannelType.User}); + + private MessageBuffer FindNonExistingRequest => MessageBuffer.Factory.CreateJson( + new FindChannelRequest {ChannelId = "nonexisting", ChannelType = ChannelType.User}); + + public async Task InitializeAsync() + { + // Create the backend side + IHostBuilder builder = new HostBuilder(); + builder.ConfigureServices( + services => + { + services.AddMessageRouterServer( + s => s.UseWebSockets( + opt => { - Uri = _webSocketUri - })) - .BuildServiceProvider(); - - _messageRouter = _clientServices.GetRequiredService(); - - _moduleLoader = _host.Services.GetRequiredService(); - - _runningAppsObserver = _moduleLoader.LifetimeEvents.Subscribe((lifetimeEvent) => - { - lock (_runningAppsLock) - { - switch (lifetimeEvent.EventType) - { - case LifetimeEventType.Started: - _runningApps.Add(lifetimeEvent.Instance); - break; - - case LifetimeEventType.Stopped: - _runningApps.Remove(lifetimeEvent.Instance); - break; - } - } - }); - - var fdc3DesktopAgentMessageRouterService = _host.Services.GetRequiredService() as Fdc3DesktopAgentMessageRouterService; - _options = fdc3DesktopAgentMessageRouterService!.JsonMessageSerializerOptions; - } + opt.RootPath = _webSocketUri.AbsolutePath; + opt.Port = _webSocketUri.Port; + })); + services.AddMessageRouter(mr => mr.UseServer()); + + services.AddFdc3AppDirectory( + _ => _.Source = new Uri( + $"file:\\\\{Directory.GetCurrentDirectory()}\\TestUtils\\appDirectorySample.json")); + + services.AddModuleLoader(); + + services.AddFdc3DesktopAgent( + fdc3 => fdc3.Configure( + builder => { builder.ChannelId = TestChannel; })); + }); + + _host = builder.Build(); + await _host.StartAsync(); + + // Create a client acting in place of an application + _clientServices = new ServiceCollection() + .AddMessageRouter( + mr => mr.UseWebSocket( + new MessageRouterWebSocketOptions + { + Uri = _webSocketUri + })) + .BuildServiceProvider(); - public async Task DisposeAsync() - { - List runningApps; - _runningAppsObserver?.Dispose(); - lock (_runningAppsLock) - { - runningApps = _runningApps.Reverse().ToList(); - } - foreach (var instance in runningApps) + _messageRouter = _clientServices.GetRequiredService(); + + _moduleLoader = _host.Services.GetRequiredService(); + + _runningAppsObserver = _moduleLoader.LifetimeEvents.Subscribe( + lifetimeEvent => { - await _moduleLoader.StopModule(new StopRequest(instance.InstanceId)); - } - await _clientServices.DisposeAsync(); - await _host.StopAsync(); - _host.Dispose(); - } + lock (_runningAppsLock) + { + switch (lifetimeEvent.EventType) + { + case LifetimeEventType.Started: + _runningApps.Add(lifetimeEvent.Instance); + break; - [Fact] - public async void GetCurrentContextReturnsNullBeforeBroadcast() + case LifetimeEventType.Stopped: + _runningApps.Remove(lifetimeEvent.Instance); + break; + } + } + }); + + var fdc3DesktopAgentMessageRouterService = + _host.Services.GetRequiredService() as Fdc3DesktopAgentMessageRouterService; + _options = fdc3DesktopAgentMessageRouterService!.JsonMessageSerializerOptions; + } + + public async Task DisposeAsync() + { + List runningApps; + _runningAppsObserver?.Dispose(); + lock (_runningAppsLock) { - var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, EmptyContextType); - resultBuffer.Should().BeNull(); + runningApps = _runningApps.Reverse().ToList(); } - [Fact] - public async void GetCurrentContextReturnsAfterBroadcast() + foreach (var instance in runningApps) { - var ctx = GetContext(); + await _moduleLoader.StopModule(new StopRequest(instance.InstanceId)); + } - await _messageRouter.PublishAsync(_topics.Broadcast, ctx); + await _clientServices.DisposeAsync(); + await _host.StopAsync(); + _host.Dispose(); + } + + [Fact] + public async void GetCurrentContextReturnsNullBeforeBroadcast() + { + var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, EmptyContextType); + resultBuffer.Should().BeNull(); + } - await Task.Delay(100); + [Fact] + public async void GetCurrentContextReturnsAfterBroadcast() + { + var ctx = GetContext(); - var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, ContextType); + await _messageRouter.PublishAsync(_topics.Broadcast, ctx); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(); + await Task.Delay(100); - result.Should().BeEquivalentTo(ctx.ReadJson()); - } + var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, ContextType); - [Fact] - public async void GetCurrentContextReturnsAfterBroadcastWithNoType() - { - var ctx = GetContext(); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(); - await _messageRouter.PublishAsync(_topics.Broadcast, ctx); + result.Should().BeEquivalentTo(ctx.ReadJson()); + } - await Task.Delay(100); + [Fact] + public async void GetCurrentContextReturnsAfterBroadcastWithNoType() + { + var ctx = GetContext(); - var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, EmptyContextType); + await _messageRouter.PublishAsync(_topics.Broadcast, ctx); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(); + await Task.Delay(100); - result.Should().BeEquivalentTo(ctx.ReadJson()); - } + var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, EmptyContextType); - [Fact] - public async void DifferentGetCurrentContextReturnsNullAfterBroadcast() - { - var ctx = GetContext(); - await _messageRouter.PublishAsync(_topics.Broadcast, ctx); - await Task.Delay(100); - var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, OtherContextType); - resultBuffer.Should().BeNull(); - } + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(); - [Fact] - public async void FindUserChannelReturnsFoundTrueForExistingChannel() - { - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindChannel, FindRequest); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().BeEquivalentTo(FindChannelResponse.Success); - } + result.Should().BeEquivalentTo(ctx.ReadJson()); + } - [Fact] - public async void FindUserChannelReturnsNoChannelFoundForNonExistingChannel() - { - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindChannel, FindNonExistingRequest); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().BeEquivalentTo(FindChannelResponse.Failure(ChannelError.NoChannelFound)); - } + [Fact] + public async void DifferentGetCurrentContextReturnsNullAfterBroadcast() + { + var ctx = GetContext(); + await _messageRouter.PublishAsync(_topics.Broadcast, ctx); + await Task.Delay(100); + var resultBuffer = await _messageRouter.InvokeAsync(_topics.GetCurrentContext, OtherContextType); + resultBuffer.Should().BeNull(); + } - [Fact] - public async Task FindIntentReturnsAppIntent() - { - //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + [Fact] + public async void FindUserChannelReturnsFoundTrueForExistingChannel() + { + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindChannel, FindRequest); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().BeEquivalentTo(FindChannelResponse.Success); + } - var appId4IntentMetadata = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }; + [Fact] + public async void FindUserChannelReturnsNoChannelFoundForNonExistingChannel() + { + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindChannel, FindNonExistingRequest); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().BeEquivalentTo(FindChannelResponse.Failure(ChannelError.NoChannelFound)); + } - var request = new FindIntentRequest() - { - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadata4" - }; + [Fact] + public async Task FindIntentReturnsAppIntent() + { + //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - var expectedResponse = new FindIntentResponse() - { - AppIntent = new AppIntent() - { - Intent = appId4IntentMetadata, - Apps = new AppMetadata[] - { - new() { AppId = "appId4", Name = "app4", ResultType = null }, - new() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new() { AppId = "appId6", Name = "app6", ResultType = "resultType" } - } - } - }; + var appId4IntentMetadata = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}; - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + var request = new FindIntentRequest + { + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadata4" + }; - [Fact] - public async Task FindIntentReturnsIntentDeliveryFailureBecauseOfTheRequest() + var expectedResponse = new FindIntentResponse { - var expectedResponse = new FindIntentResponse() + AppIntent = new AppIntent { - Error = ResolveError.IntentDeliveryFailed - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntent, null); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + Intent = appId4IntentMetadata, + Apps = new AppMetadata[] + { + new() {AppId = "appId4", Name = "app4", ResultType = null}, + new() {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new() {AppId = "appId6", Name = "app6", ResultType = "resultType"} + } + } + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.FindIntent, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task FindIntentReturnsNoAppsFound() + [Fact] + public async Task FindIntentReturnsIntentDeliveryFailureBecauseOfTheRequest() + { + var expectedResponse = new FindIntentResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.IntentDeliveryFailed + }; - var request = new FindIntentRequest() - { - Fdc3InstanceId = originFdc3InstanceId, - Intent = "noAppShouldReturnIntent", - }; + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntent); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - var expectedResponse = new FindIntentResponse() - { - Error = ResolveError.NoAppsFound - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + [Fact] + public async Task FindIntentReturnsNoAppsFound() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - [Fact] - public async Task FindIntentReturnsIntentDeliveryFailureBecauseOfMultipleAppIntentFound() + var request = new FindIntentRequest { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Fdc3InstanceId = originFdc3InstanceId, + Intent = "noAppShouldReturnIntent" + }; - var request = new FindIntentRequest() - { - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadata8" - }; + var expectedResponse = new FindIntentResponse + { + Error = ResolveError.NoAppsFound + }; - var expectedResponse = new FindIntentResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.FindIntent, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task FindIntentsByContextReturnsAppIntent() - { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + [Fact] + public async Task FindIntentsByContextReturnsAppIntent() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - var request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = originFdc3InstanceId, - Context = new Context("context2"), - ResultType = "resultType" - }; + var request = new FindIntentsByContextRequest + { + Fdc3InstanceId = originFdc3InstanceId, + Context = new Context("context2"), + ResultType = "resultType" + }; - var appId5IntentMetadata = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }; + var appId5IntentMetadata = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}; - var expectedResponse = new FindIntentsByContextResponse() + var expectedResponse = new FindIntentsByContextResponse + { + AppIntents = new AppIntent[] { - AppIntents = new AppIntent[] + new() { - new() + Intent = appId5IntentMetadata, + Apps = new AppMetadata[] { - Intent = appId5IntentMetadata, - Apps = new AppMetadata[] - { - new() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new() { AppId = "appId6", Name = "app6", ResultType = "resultType" } - } + new() {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new() {AppId = "appId6", Name = "app6", ResultType = "resultType"} } } - }; + } + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.FindIntentsByContext, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntentsByContext, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + [Fact] + public async Task FindIntentsByContextReturnsMultipleAppIntents() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - [Fact] - public async Task FindIntentsByContextReturnsMultipleAppIntent() + var request = new FindIntentsByContextRequest { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Fdc3InstanceId = originFdc3InstanceId, + Context = new Context("context9"), + ResultType = "resultWrongApp" + }; - var request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = originFdc3InstanceId, - Context = new Context("context9"), - ResultType = "resultWrongApp" - }; - - var appId9IntentMetadata = new Protocol.IntentMetadata() { Name = "intentMetadata9", DisplayName = "displayName9" }; - var appId12IntentMetadata = new Protocol.IntentMetadata() { Name = "intentMetadata11", DisplayName = "displayName11" }; - var expectedResponse = new FindIntentsByContextResponse() + var appId9IntentMetadata = new IntentMetadata {Name = "intentMetadata9", DisplayName = "displayName9"}; + var appId12IntentMetadata = new IntentMetadata {Name = "intentMetadata11", DisplayName = "displayName11"}; + var expectedResponse = new FindIntentsByContextResponse + { + AppIntents = new[] { - AppIntents = new[] + new AppIntent + { + Intent = appId9IntentMetadata, + Apps = new[] { - new AppIntent() - { - Intent = appId9IntentMetadata, - Apps = new [] - { - new AppMetadata() { AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp" }, - } - }, - new AppIntent() - { - Intent = appId12IntentMetadata, - Apps = new [] - { - new AppMetadata(){ AppId = "appId12", Name = "app12", ResultType = "resultWrongApp" }, - } - } + new AppMetadata {AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp"} } - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntentsByContext, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } - - [Fact] - public async Task FindIntentsByContextReturnsIntentDeliveryFailureBecauseOfTheRequest() - { - var expectedResponse = new FindIntentsByContextResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntentsByContext, null); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + }, + new AppIntent + { + Intent = appId12IntentMetadata, + Apps = new[] + { + new AppMetadata {AppId = "appId12", Name = "app12", ResultType = "resultWrongApp"} + } + } + } + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.FindIntentsByContext, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task FindIntentsByContextReturnsNoAppsFound() + [Fact] + public async Task FindIntentsByContextReturnsIntentDeliveryFailureBecauseOfTheRequest() + { + var expectedResponse = new FindIntentsByContextResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.IntentDeliveryFailed + }; - var request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = originFdc3InstanceId, - Context = new Context("context2"), - ResultType = "noAppShouldReturn" - }; - - var expectedResponse = new FindIntentsByContextResponse() - { - Error = ResolveError.NoAppsFound - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntentsByContext, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.FindIntentsByContext); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task RaiseIntentReturnsIntentDeliveryFailureBecauseOfTheRequest() - { - var expectedResponse = new RaiseIntentResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, null); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + [Fact] + public async Task FindIntentsByContextReturnsNoAppsFound() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - [Fact] - public async Task RaiseIntentReturnsErrorAsMessageContainsError() + var request = new FindIntentsByContextRequest { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - - var request = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "dummy", - Selected = false, - Context = new Context(ContextTypes.Nothing), - Error = "dummyError" - }; + Fdc3InstanceId = originFdc3InstanceId, + Context = new Context("context2"), + ResultType = "noAppShouldReturn" + }; - var expectedResponse = new RaiseIntentResponse() - { - Error = "dummyError" - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } - - [Fact] - public async Task RaiseIntentReturnsNoAppsFound() + var expectedResponse = new FindIntentsByContextResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.NoAppsFound + }; - var request = new RaiseIntentRequest() - { - MessageId = 2, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "noIntentShouldHandle", - Selected = false, - Context = new Context(ContextTypes.Nothing) - }; - - var expectedResponse = new RaiseIntentResponse() - { - Error = ResolveError.NoAppsFound - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.FindIntentsByContext, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task RaiseIntentReturnsIntentDeliveryFailureAsMultipleAppIntentFound() + [Fact] + public async Task RaiseIntentReturnsIntentDeliveryFailureBecauseOfTheRequest() + { + var expectedResponse = new RaiseIntentResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.IntentDeliveryFailed + }; - var request = new RaiseIntentRequest() - { - MessageId = 2, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadata8", //wrongly set up AppDirectory on purpose - Selected = false, - Context = new Context(ContextTypes.Nothing) - }; + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - var expectedResponse = new RaiseIntentResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); - result.Should().BeEquivalentTo(expectedResponse); - } + [Fact] + public async Task RaiseIntentReturnsNoAppsFound() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + + var request = new RaiseIntentRequest + { + MessageId = 2, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "noIntentShouldHandle", + Selected = false, + Context = new Context(ContextTypes.Nothing) + }; + + var expectedResponse = new RaiseIntentResponse + { + Error = ResolveError.NoAppsFound + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.RaiseIntent, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task RaiseIntentReturnsAppIntentWithOneApp() - { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + [Fact] + public async Task RaiseIntentReturnsAppIntentWithOneApp() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + + var request = new RaiseIntentRequest + { + MessageId = 2, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadataCustom", + Selected = false, + Context = new Context("contextCustom") + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.RaiseIntent, + MessageBuffer.Factory.CreateJson(request, _options)); + var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); + var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); + app4Fdc3InstanceId.Should() + .Be(resultBuffer!.ReadJson(_options)!.AppMetadata!.First().InstanceId); + app4Fdc3InstanceId.Should().NotBeNull(); + + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + + var expectedResponse = new RaiseIntentResponse + { + MessageId = result!.MessageId, + Intent = "intentMetadataCustom", + AppMetadata = new AppMetadata[] + { + new() {AppId = "appId4", InstanceId = app4Fdc3InstanceId, Name = "app4", ResultType = null} + } + }; - var request = new RaiseIntentRequest() - { - MessageId = 2, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadataCustom", - Selected = false, - Context = new Context("contextCustom") - }; + result.Should().BeEquivalentTo(expectedResponse); + } - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(request, _options)); - var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); - var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); - app4Fdc3InstanceId.Should().Be(resultBuffer!.ReadJson(_options)!.AppMetadata!.First().InstanceId); - app4Fdc3InstanceId.Should().NotBeNull(); + [Fact] + public async Task RaiseIntentReturnsAppIntentWithOneExistingAppAndPublishesContextToHandle() + { + var origin = await _moduleLoader.StartModule(new StartRequest("appId1")); + var target = await _moduleLoader.StartModule(new StartRequest("appId4")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(origin); + var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); + + var addIntentListenerRequest = + MessageBuffer.Factory.CreateJson( + new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }, + _options); + + var addIntentListenerResult = await _messageRouter.InvokeAsync( + Fdc3Topic.AddIntentListener, + addIntentListenerRequest); + addIntentListenerResult.Should().NotBeNull(); + addIntentListenerResult!.ReadJson(_options) + .Should() + .BeEquivalentTo(IntentListenerResponse.SubscribeSuccess()); + + var request = new RaiseIntentRequest + { + MessageId = 2, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadataCustom", + Selected = false, + Context = new Context("contextCustom"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.RaiseIntent, + MessageBuffer.Factory.CreateJson(request, _options)); + + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + + var expectedResponse = new RaiseIntentResponse + { + MessageId = result!.MessageId, + Intent = "intentMetadataCustom", + AppMetadata = new AppMetadata[] + { + new() {AppId = "appId4", InstanceId = targetFdc3InstanceId, Name = "app4", ResultType = null} + } + }; - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); + result.Should().BeEquivalentTo(expectedResponse); + } - var expectedResponse = new RaiseIntentResponse() - { - MessageId = result!.MessageId, - Intent = "intentMetadataCustom", - AppMetadata = new AppMetadata[] + //TODO: Right now we are returning just one element, without the possibility of selecting via ResolverUI. + [Fact] + public async Task RaiseIntentReturnsAppIntentWithFirstApp() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + + var request = new RaiseIntentRequest + { + MessageId = 2, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2") + }; + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.RaiseIntent, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result.Should().NotBeNull(); + + var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); + var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); + + result!.AppMetadata.Should() + .BeEquivalentTo( + new AppMetadata[] { - new(){ AppId = "appId4", InstanceId = app4Fdc3InstanceId, Name = "app4", ResultType = null } - } - }; - - result.Should().BeEquivalentTo(expectedResponse); - } + new() {AppId = "appId4", InstanceId = app4Fdc3InstanceId, Name = "app4", ResultType = null} + }); + } - [Fact] - public async Task RaiseIntentReturnsAppIntentWithOneExistingAppAndPublishesContextToHandle() + [Fact] + public async Task StoreIntentResultReturnsIntentDeliveryFailureAsRequestIsNull() + { + var expectedResponse = new StoreIntentResultResponse { - var origin = await _moduleLoader.StartModule(new StartRequest("appId1")); - var target = await _moduleLoader.StartModule(new StartRequest("appId4")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(origin); - var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - - var addIntentListenerRequest = - MessageBuffer.Factory.CreateJson( - new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }, - _options); - - var addIntentListenerResult = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, addIntentListenerRequest); - addIntentListenerResult.Should().NotBeNull(); - addIntentListenerResult!.ReadJson(_options).Should().BeEquivalentTo(IntentListenerResponse.SubscribeSuccess()); - - var request = new RaiseIntentRequest() - { - MessageId = 2, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadataCustom", - Selected = false, - Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + Error = ResolveError.IntentDeliveryFailed + }; - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(request, _options)); - - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.SendIntentResult); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - var expectedResponse = new RaiseIntentResponse() - { - MessageId = result!.MessageId, - Intent = "intentMetadataCustom", - AppMetadata = new AppMetadata[] - { - new() { AppId = "appId4", InstanceId = targetFdc3InstanceId, Name = "app4", ResultType = null } - } - }; + [Fact] + public async Task StoreIntentResultReturnsIntentDeliveryFailureAsRequestNotContainsInformation() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - result.Should().BeEquivalentTo(expectedResponse); - } + var request = new StoreIntentResultRequest + { + MessageId = string.Empty, + Intent = "dummyIntent", + OriginFdc3InstanceId = originFdc3InstanceId, + TargetFdc3InstanceId = null + }; - //TODO: Right now we are returning just one element, without the possibility of selecting via ResolverUI. - [Fact] - public async Task RaiseIntentReturnsAppIntentWithFirstApp() + var expectedResponse = new StoreIntentResultResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.IntentDeliveryFailed + }; - var request = new RaiseIntentRequest() - { - MessageId = 2, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2") - }; + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.SendIntentResult, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result.Should().NotBeNull(); + [Fact] + public async Task StoreIntentResultReturnsSuccessfully() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 2, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadataCustom", + Selected = false, + Context = new Context("contextCustom") + }; + + var raiseIntentResultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.RaiseIntent, + MessageBuffer.Factory.CreateJson(raiseIntentRequest, _options)); + raiseIntentResultBuffer.Should().NotBeNull(); + var raiseIntentResult = raiseIntentResultBuffer!.ReadJson(_options); + raiseIntentResult!.AppMetadata.Should().HaveCount(1); + raiseIntentResult.AppMetadata!.First().InstanceId.Should().NotBeNull(); + + var testContext = new Context("testContextType"); + + var request = new StoreIntentResultRequest + { + MessageId = raiseIntentResult.MessageId!, + Intent = "intentMetadataCustom", + OriginFdc3InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!, + TargetFdc3InstanceId = originFdc3InstanceId, + Context = testContext + }; + + var expectedResponse = new StoreIntentResultResponse + { + Stored = true + }; + + var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); + var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); + app4Fdc3InstanceId.Should().Be(raiseIntentResult!.AppMetadata!.First().InstanceId); + + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.SendIntentResult, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); - var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); + [Fact] + public async Task GetIntentResultReturnsIntentDeliveryFailureAsRequestIsNull() + { + var expectedResponse = new GetIntentResultResponse + { + Error = ResolveError.IntentDeliveryFailed + }; - result!.AppMetadata.Should().BeEquivalentTo( - new AppMetadata[] - { - new() { AppId = "appId4", InstanceId = app4Fdc3InstanceId, Name = "app4", ResultType = null } - }); - } + var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.GetIntentResult); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - [Fact] - public async Task StoreIntentResultReturnsIntentDeliveryFailureAsRequestIsNull() + [Fact] + public async Task GetIntentResultReturnsIntentDeliveryFailureAsRequestDoesNotContainInformation() + { + var request = new GetIntentResultRequest { - var expectedResponse = new StoreIntentResultResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.SendIntentResult, null); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } + MessageId = "dummy", + Intent = "dummy", + TargetAppIdentifier = new AppIdentifier {AppId = "appId1"} + }; - [Fact] - public async Task StoreIntentResultReturnsIntentDeliveryFailureAsRequestNotContainsInformation() + var expectedResponse = new GetIntentResultResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.IntentDeliveryFailed + }; - var request = new StoreIntentResultRequest() - { - MessageId = string.Empty, - Intent = "dummyIntent", - OriginFdc3InstanceId = originFdc3InstanceId, - TargetFdc3InstanceId = null - }; + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.GetIntentResult, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - var expectedResponse = new StoreIntentResultResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; + [Fact] + public async Task GetIntentResultReturnsIntentDeliveryFailureAsNoIntentResultFound() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.SendIntentResult, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } + var request = new GetIntentResultRequest + { + MessageId = "dummy", + Intent = "testIntent", + TargetAppIdentifier = new AppIdentifier {AppId = "appId1", InstanceId = originFdc3InstanceId} + }; - [Fact] - public async Task StoreIntentResultReturnsSuccessfully() + var expectedResponse = new GetIntentResultResponse { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + Error = ResolveError.IntentDeliveryFailed + }; - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 2, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadataCustom", - Selected = false, - Context = new Context("contextCustom") - }; + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.GetIntentResult, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - var raiseIntentResultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(raiseIntentRequest, _options)); - raiseIntentResultBuffer.Should().NotBeNull(); - var raiseIntentResult = raiseIntentResultBuffer!.ReadJson(_options); - raiseIntentResult!.AppMetadata.Should().HaveCount(1); - raiseIntentResult.AppMetadata!.First().InstanceId.Should().NotBeNull(); + [Fact] + public async Task GetIntentResultReturnsSuccessfully() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - var testContext = new Context("testContextType"); + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 2, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadataCustom", + Selected = false, + Context = new Context("contextCustom") + }; - var request = new StoreIntentResultRequest() - { - MessageId = raiseIntentResult.MessageId!, - Intent = "intentMetadataCustom", - OriginFdc3InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!, - TargetFdc3InstanceId = originFdc3InstanceId, - Context = testContext - }; + var resultRaiseIntentBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.RaiseIntent, + MessageBuffer.Factory.CreateJson(raiseIntentRequest, _options)); + var raiseIntentResult = resultRaiseIntentBuffer!.ReadJson(_options); - var expectedResponse = new StoreIntentResultResponse() - { - Stored = true - }; + var testContext = new Context("testContextType"); - var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); - var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); - app4Fdc3InstanceId.Should().Be(raiseIntentResult!.AppMetadata!.First().InstanceId); + var storeIntentRequest = new StoreIntentResultRequest + { + MessageId = raiseIntentResult!.MessageId!, + Intent = "intentMetadataCustom", + OriginFdc3InstanceId = raiseIntentResult!.AppMetadata!.First().InstanceId!, + TargetFdc3InstanceId = originFdc3InstanceId, + Context = testContext + }; - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.SendIntentResult, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } + await _messageRouter.InvokeAsync( + Fdc3Topic.SendIntentResult, + MessageBuffer.Factory.CreateJson(storeIntentRequest, _options)); - [Fact] - public async Task GetIntentResultReturnsIntentDeliveryFailureAsRequestIsNull() + var request = new GetIntentResultRequest { - var expectedResponse = new GetIntentResultResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; + MessageId = raiseIntentResult!.MessageId!, + Intent = "intentMetadataCustom", + TargetAppIdentifier = new AppIdentifier + {AppId = "appId4", InstanceId = raiseIntentResult!.AppMetadata!.First().InstanceId!} + }; - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.GetIntentResult, null); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } - - [Fact] - public async Task GetIntentResultReturnsIntentDeliveryFailureAsRequestDoesNotContainInformation() + var expectedResponse = new GetIntentResultResponse { - var request = new GetIntentResultRequest() - { - MessageId = "dummy", - Intent = "dummy", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1" } - }; + Context = testContext + }; - var expectedResponse = new GetIntentResultResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; + var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); + var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); + app4Fdc3InstanceId.Should().Be(raiseIntentResult!.AppMetadata!.First().InstanceId); - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.GetIntentResult, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } - - [Fact] - public async Task GetIntentResultReturnsIntentDeliveryFailureAsNoIntentResultFound() - { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + var resultBuffer = await _messageRouter.InvokeAsync( + Fdc3Topic.GetIntentResult, + MessageBuffer.Factory.CreateJson(request, _options)); + resultBuffer.Should().NotBeNull(); + var result = resultBuffer!.ReadJson(_options); + result!.Should().BeEquivalentTo(expectedResponse); + } - var request = new GetIntentResultRequest() - { - MessageId = "dummy", - Intent = "testIntent", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = originFdc3InstanceId } - }; + [Fact] + public async Task AddIntentListenerReturnsPayloadNullError() + { + var result = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener); + result.Should().NotBeNull(); + result!.ReadJson(_options) + .Should() + .BeEquivalentTo(IntentListenerResponse.Failure(Fdc3DesktopAgentErrors.PayloadNull)); + } - var expectedResponse = new GetIntentResultResponse() - { - Error = ResolveError.IntentDeliveryFailed - }; + [Fact] + public async Task AddIntentListenerReturnsMissingIdError() + { + var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + var request = new IntentListenerRequest + {Intent = "dummy", Fdc3InstanceId = originFdc3InstanceId, State = SubscribeState.Unsubscribe}; + var expectedResponse = await _messageRouter.InvokeAsync( + Fdc3Topic.AddIntentListener, + MessageBuffer.Factory.CreateJson(request, _options)); + expectedResponse.Should().NotBeNull(); + expectedResponse!.ReadJson(_options) + .Should() + .BeEquivalentTo(IntentListenerResponse.Failure(Fdc3DesktopAgentErrors.MissingId)); + } - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.GetIntentResult, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } + [Fact] + public async Task AddIntentListenerSubscribesWithExistingAppPerRaisedIntent() + { + //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id + var origin = await _moduleLoader.StartModule(new StartRequest("appId1")); + var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(origin); - [Fact] - public async Task GetIntentResultReturnsSuccessfully() - { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); + //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id + var target = await _moduleLoader.StartModule(new StartRequest("appId4")); + var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() + var raiseIntentRequest = MessageBuffer.Factory.CreateJson( + new RaiseIntentRequest { - MessageId = 2, + MessageId = 1, Fdc3InstanceId = originFdc3InstanceId, Intent = "intentMetadataCustom", Selected = false, - Context = new Context("contextCustom") - }; + Context = new Context("contextCustom"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }, + _options); - var resultRaiseIntentBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, MessageBuffer.Factory.CreateJson(raiseIntentRequest, _options)); - var raiseIntentResult = resultRaiseIntentBuffer!.ReadJson(_options); + var raiseIntentResult = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, raiseIntentRequest); - var testContext = new Context("testContextType"); + raiseIntentResult.Should().NotBeNull(); + var raiseIntentResponse = raiseIntentResult!.ReadJson(_options)!; + raiseIntentResponse.AppMetadata.Should().HaveCount(1); + raiseIntentResponse.AppMetadata!.First()!.AppId.Should().Be("appId4"); - var storeIntentRequest = new StoreIntentResultRequest() + var addIntentListenerRequest = MessageBuffer.Factory.CreateJson( + new IntentListenerRequest { - MessageId = raiseIntentResult!.MessageId!, Intent = "intentMetadataCustom", - OriginFdc3InstanceId = raiseIntentResult!.AppMetadata!.First().InstanceId!, - TargetFdc3InstanceId = originFdc3InstanceId, - Context = testContext - }; + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }, + _options); + + var addIntentListenerResult = await _messageRouter.InvokeAsync( + Fdc3Topic.AddIntentListener, + addIntentListenerRequest); + addIntentListenerResult.Should().NotBeNull(); + + var addIntentListenerResponse = addIntentListenerResult!.ReadJson(_options); + addIntentListenerResponse!.Stored.Should().BeTrue(); + + var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); + var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); + app4Fdc3InstanceId.Should() + .Be(raiseIntentResult!.ReadJson(_options)!.AppMetadata!.First().InstanceId); + } - await _messageRouter.InvokeAsync(Fdc3Topic.SendIntentResult, MessageBuffer.Factory.CreateJson(storeIntentRequest, _options)); + [Fact] + public async Task AddIntentListenerSubscribesWithNewApp() + { + //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id + var target = await _moduleLoader.StartModule(new StartRequest("appId4")); + var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var request = new GetIntentResultRequest() + var addIntentListenerRequest = MessageBuffer.Factory.CreateJson( + new IntentListenerRequest { - MessageId = raiseIntentResult!.MessageId!, Intent = "intentMetadataCustom", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = raiseIntentResult!.AppMetadata!.First().InstanceId! } - }; - - var expectedResponse = new GetIntentResultResponse() - { - Context = testContext - }; - - var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); - var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); - app4Fdc3InstanceId.Should().Be(raiseIntentResult!.AppMetadata!.First().InstanceId); - - var resultBuffer = await _messageRouter.InvokeAsync(Fdc3Topic.GetIntentResult, MessageBuffer.Factory.CreateJson(request, _options)); - resultBuffer.Should().NotBeNull(); - var result = resultBuffer!.ReadJson(_options); - result!.Should().BeEquivalentTo(expectedResponse); - } - - [Fact] - public async Task AddIntentListenerReturnsPayloadNullError() - { - var result = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, null, new()); - result.Should().NotBeNull(); - result!.ReadJson(_options).Should().BeEquivalentTo(IntentListenerResponse.Failure(Fdc3DesktopAgentErrors.PayloadNull)); - } - - [Fact] - public async Task AddIntentListenerReturnsMissingIdError() - { - var instance = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - var request = new IntentListenerRequest() { Intent = "dummy", Fdc3InstanceId = originFdc3InstanceId, State = SubscribeState.Unsubscribe }; - var expectedResponse = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, MessageBuffer.Factory.CreateJson(request, _options)); - expectedResponse.Should().NotBeNull(); - expectedResponse!.ReadJson(_options).Should().BeEquivalentTo(IntentListenerResponse.Failure(Fdc3DesktopAgentErrors.MissingId)); - } - - [Fact] - public async Task AddIntentListenerSubscribesWithExistingAppPerRaisedIntent() - { - //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id - var origin = await _moduleLoader.StartModule(new StartRequest("appId1")); - var originFdc3InstanceId = Fdc3InstanceIdRetriever.Get(origin); - - //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id - var target = await _moduleLoader.StartModule(new StartRequest("appId4")); - var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - - var raiseIntentRequest = MessageBuffer.Factory.CreateJson( - new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadataCustom", - Selected = false, - Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }, _options); - - var raiseIntentResult = await _messageRouter.InvokeAsync(Fdc3Topic.RaiseIntent, raiseIntentRequest); - - raiseIntentResult.Should().NotBeNull(); - var raiseIntentResponse = raiseIntentResult!.ReadJson(_options)!; - raiseIntentResponse.AppMetadata.Should().HaveCount(1); - raiseIntentResponse.AppMetadata!.First()!.AppId.Should().Be("appId4"); - - var addIntentListenerRequest = MessageBuffer.Factory.CreateJson( - new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }, _options); - - var addIntentListenerResult = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, addIntentListenerRequest); - addIntentListenerResult.Should().NotBeNull(); - - var addIntentListenerResponse = addIntentListenerResult!.ReadJson(_options); - addIntentListenerResponse!.Stored.Should().BeTrue(); - - var app4 = _runningApps.First(application => application.Manifest.Id == "appId4"); - var app4Fdc3InstanceId = Fdc3InstanceIdRetriever.Get(app4); - app4Fdc3InstanceId.Should().Be(raiseIntentResult!.ReadJson(_options)!.AppMetadata!.First().InstanceId); - } - - [Fact] - public async Task AddIntentListenerSubscribesWithNewApp() - { - //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id - var target = await _moduleLoader.StartModule(new StartRequest("appId4")); - var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - - var addIntentListenerRequest = MessageBuffer.Factory.CreateJson( - new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }, _options); - - var addIntentListenerResult = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, addIntentListenerRequest); - addIntentListenerResult.Should().NotBeNull(); - - var addIntentListenerResponse = addIntentListenerResult!.ReadJson(_options); - addIntentListenerResponse!.Stored.Should().BeTrue(); - } - - [Fact] - public async Task AddIntentListenerUnsubscribes() - { - //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id - var target = await _moduleLoader.StartModule(new StartRequest("appId4")); - var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - - var addIntentListenerRequest = MessageBuffer.Factory.CreateJson( - new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }, _options); - - var addIntentListenerResult = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, addIntentListenerRequest); - addIntentListenerResult.Should().NotBeNull(); - - var addIntentListnerResponse = addIntentListenerResult!.ReadJson(_options); - addIntentListnerResponse!.Stored.Should().BeTrue(); - - addIntentListenerRequest = MessageBuffer.Factory.CreateJson( - new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Unsubscribe - }, _options); - - addIntentListenerResult = await _messageRouter.InvokeAsync(Fdc3Topic.AddIntentListener, addIntentListenerRequest); - addIntentListenerResult.Should().NotBeNull(); + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }, + _options); + + var addIntentListenerResult = await _messageRouter.InvokeAsync( + Fdc3Topic.AddIntentListener, + addIntentListenerRequest); + addIntentListenerResult.Should().NotBeNull(); + + var addIntentListenerResponse = addIntentListenerResult!.ReadJson(_options); + addIntentListenerResponse!.Stored.Should().BeTrue(); + } - addIntentListnerResponse = addIntentListenerResult!.ReadJson(_options); - addIntentListnerResponse!.Stored.Should().BeFalse(); - addIntentListnerResponse!.Error.Should().BeNull(); - } + [Fact] + public async Task AddIntentListenerUnsubscribes() + { + //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id + var target = await _moduleLoader.StartModule(new StartRequest("appId4")); + var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - private int _counter = 0; + var addIntentListenerRequest = MessageBuffer.Factory.CreateJson( + new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }, + _options); - private MessageBuffer EmptyContextType => MessageBuffer.Factory.CreateJson(new GetCurrentContextRequest()); + var addIntentListenerResult = await _messageRouter.InvokeAsync( + Fdc3Topic.AddIntentListener, + addIntentListenerRequest); + addIntentListenerResult.Should().NotBeNull(); - private MessageBuffer ContextType => - MessageBuffer.Factory.CreateJson(new GetCurrentContextRequest { ContextType = new Contact().Type }); + var addIntentListnerResponse = addIntentListenerResult!.ReadJson(_options); + addIntentListnerResponse!.Stored.Should().BeTrue(); - private MessageBuffer OtherContextType => - MessageBuffer.Factory.CreateJson(new GetCurrentContextRequest { ContextType = new Email(null).Type }); + addIntentListenerRequest = MessageBuffer.Factory.CreateJson( + new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Unsubscribe + }, + _options); + + addIntentListenerResult = await _messageRouter.InvokeAsync( + Fdc3Topic.AddIntentListener, + addIntentListenerRequest); + addIntentListenerResult.Should().NotBeNull(); + + addIntentListnerResponse = addIntentListenerResult!.ReadJson(_options); + addIntentListnerResponse!.Stored.Should().BeFalse(); + addIntentListnerResponse!.Error.Should().BeNull(); + } - private MessageBuffer GetContext() => MessageBuffer.Factory.CreateJson( + private MessageBuffer GetContext() + { + return MessageBuffer.Factory.CreateJson( new Contact( - new ContactID() { Email = $"test{_counter}@test.org", FdsId = $"test{_counter++}" }, - "Testy Tester")); - - private MessageBuffer FindRequest => MessageBuffer.Factory.CreateJson( - new FindChannelRequest { ChannelId = TestChannel, ChannelType = ChannelType.User }); - - private MessageBuffer FindNonExistingRequest => MessageBuffer.Factory.CreateJson( - new FindChannelRequest { ChannelId = "nonexisting", ChannelType = ChannelType.User }); + new ContactID {Email = $"test{_counter}@test.org", FdsId = $"test{_counter++}"}, + name: "Testy Tester")); } } \ No newline at end of file diff --git a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Fdc3DesktopAgentTests.cs b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Fdc3DesktopAgentTests.cs index 65ddc9821..2ae517e6d 100644 --- a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Fdc3DesktopAgentTests.cs +++ b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Fdc3DesktopAgentTests.cs @@ -13,38 +13,54 @@ */ -using MorganStanley.ComposeUI.Fdc3.AppDirectory; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.TestUtils; +using Finos.Fdc3; using Finos.Fdc3.AppDirectory; -using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata; -using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent; -using AppIdentifier = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIdentifier; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection; +using Finos.Fdc3.Context; using Microsoft.Extensions.Logging.Abstractions; -using Finos.Fdc3; +using MorganStanley.ComposeUI.Fdc3.AppDirectory; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts; -using Finos.Fdc3.Context; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.Helpers; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Exceptions; -using MorganStanley.ComposeUI.ModuleLoader; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.Helpers; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.TestUtils; +using MorganStanley.ComposeUI.ModuleLoader; +using AppIdentifier = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIdentifier; +using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent; +using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata; +using IntentMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.IntentMetadata; namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests; public class Fdc3DesktopAgentTests : IAsyncLifetime { - private readonly MockModuleLoader _mockModuleLoader = new(); private readonly IAppDirectory _appDirectory = new AppDirectory.AppDirectory( - new AppDirectoryOptions() + new AppDirectoryOptions { Source = new Uri($"file:\\\\{Directory.GetCurrentDirectory()}\\TestUtils\\appDirectorySample.json") }); + private readonly IFdc3DesktopAgentBridge _fdc3; + private readonly MockModuleLoader _mockModuleLoader = new(); public Fdc3DesktopAgentTests() { - _fdc3 = new Fdc3DesktopAgent(_appDirectory, _mockModuleLoader.Object, new Fdc3DesktopAgentOptions(), NullLoggerFactory.Instance); + _fdc3 = new Fdc3DesktopAgent( + _appDirectory, + _mockModuleLoader.Object, + new Fdc3DesktopAgentOptions(), + NullLoggerFactory.Instance); + } + + public async Task InitializeAsync() + { + await _fdc3.StartAsync(CancellationToken.None); + } + + public async Task DisposeAsync() + { + await _fdc3.StopAsync(CancellationToken.None); } [Fact] @@ -62,14 +78,14 @@ public async Task AddUserChannel_wont_throw_and_adds_channel() var action = async () => await _fdc3.AddUserChannel(mockUserChannel.Object); await action.Should().NotThrowAsync(); - var channelExists = _fdc3.FindChannel("test", ChannelType.User); + var channelExists = _fdc3.FindChannel(channelId: "test", ChannelType.User); channelExists.Should().BeTrue(); } [Fact] public void FindChannel_returns_false() { - var result = _fdc3.FindChannel("testChannelId", ChannelType.User); + var result = _fdc3.FindChannel(channelId: "testChannelId", ChannelType.User); result.Should().BeFalse(); } @@ -86,14 +102,14 @@ public async Task FindChannel_returns_true() NullLogger.Instance); await _fdc3.AddUserChannel(mockUserChannel.Object); - var result = _fdc3.FindChannel("testChannelId", ChannelType.User); + var result = _fdc3.FindChannel(channelId: "testChannelId", ChannelType.User); result.Should().BeTrue(); } [Fact] public async Task FindIntent_returns_NoAppsFound() { - var request = new FindIntentRequest() + var request = new FindIntentRequest { Intent = "testIntent", Fdc3InstanceId = Guid.NewGuid().ToString() @@ -104,24 +120,10 @@ public async Task FindIntent_returns_NoAppsFound() result.Error.Should().Be(ResolveError.NoAppsFound); } - [Fact] - public async Task FindIntent_returns_IntentDeliveryFailed() - { - var request = new FindIntentRequest() - { - Intent = "intentMetadata8", //wrongly setup MockAppDirectory in purpose - Fdc3InstanceId = Guid.NewGuid().ToString() - }; - - var result = await _fdc3.FindIntent(request); - result.Should().NotBeNull(); - result.Error.Should().Be(ResolveError.IntentDeliveryFailed); - } - [Fact] public async Task FindIntent_returns() { - var request = new FindIntentRequest() + var request = new FindIntentRequest { Intent = "intentMetadata4", Context = new Context("context2"), @@ -131,22 +133,23 @@ public async Task FindIntent_returns() var result = await _fdc3.FindIntent(request); result.Should().NotBeNull(); - result.AppIntent.Should().BeEquivalentTo( - new AppIntent() - { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new[] - { - new AppMetadata() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new AppMetadata() { AppId = "appId6", Name = "app6", ResultType = "resultType"}, - } - }); + result.AppIntent.Should() + .BeEquivalentTo( + new AppIntent + { + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new[] + { + new AppMetadata {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new AppMetadata {AppId = "appId6", Name = "app6", ResultType = "resultType"} + } + }); } [Fact] public async Task FindIntentsByContext_returns_NoAppsFound() { - var request = new FindIntentsByContextRequest() + var request = new FindIntentsByContextRequest { Fdc3InstanceId = Guid.NewGuid().ToString(), Context = new Context("context9"), //This relates to multiple appId @@ -160,7 +163,7 @@ public async Task FindIntentsByContext_returns_NoAppsFound() [Fact] public async Task FindIntentsByContext_returns() { - var request = new FindIntentsByContextRequest() + var request = new FindIntentsByContextRequest { Fdc3InstanceId = Guid.NewGuid().ToString(), Context = new Context(ContextTypes.Nothing), @@ -170,27 +173,28 @@ public async Task FindIntentsByContext_returns() var result = await _fdc3.FindIntentsByContext(request); result.Should().NotBeNull(); - result.AppIntents.Should().BeEquivalentTo( - new[] + result.AppIntents.Should() + .BeEquivalentTo( + new[] + { + new AppIntent { - new AppIntent() + Intent = new IntentMetadata {Name = "intentMetadata9", DisplayName = "displayName9"}, + Apps = new[] { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata9", DisplayName = "displayName9" }, - Apps = new [] - { - new AppMetadata() { AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp" }, - } - }, - - new AppIntent() + new AppMetadata {AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp"} + } + }, + + new AppIntent + { + Intent = new IntentMetadata {Name = "intentMetadata11", DisplayName = "displayName11"}, + Apps = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata11", DisplayName = "displayName11" }, - Apps = new [] - { - new AppMetadata() { AppId = "appId12", Name = "app12", ResultType = "resultWrongApp" } - } - }, - }); + new AppMetadata {AppId = "appId12", Name = "app12", ResultType = "resultWrongApp"} + } + } + }); } [Fact] @@ -200,26 +204,26 @@ public async Task GetIntentResult_returns() var originFdc3InstanceId = Guid.NewGuid().ToString(); var context = new Context("test"); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); var raiseIntentRequest = - new RaiseIntentRequest() + new RaiseIntentRequest { MessageId = int.MaxValue, Fdc3InstanceId = Guid.NewGuid().ToString(), Intent = "intentMetadata4", Selected = false, Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var raiseIntentResponse = await _fdc3.RaiseIntent(raiseIntentRequest); raiseIntentResponse.Should().NotBeNull(); - raiseIntentResponse!.Response.AppMetadata.Should().HaveCount(1); + raiseIntentResponse.Response.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResponse.Response.MessageId!, Intent = "intentMetadata4", @@ -231,11 +235,12 @@ public async Task GetIntentResult_returns() var storeResult = await _fdc3.StoreIntentResult(storeIntentRequest); storeResult.Should().NotBeNull(); - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = raiseIntentResponse.Response.MessageId!, Intent = "intentMetadata4", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = raiseIntentResponse.Response.AppMetadata!.First().InstanceId! } + TargetAppIdentifier = new AppIdentifier + {AppId = "appId1", InstanceId = raiseIntentResponse.Response.AppMetadata!.First().InstanceId!} }; var result = await _fdc3.GetIntentResult(getIntentResultRequest); @@ -248,25 +253,25 @@ public async Task GetIntentResult_fails() { await _fdc3.StartAsync(CancellationToken.None); var originFdc3InstanceId = Guid.NewGuid().ToString(); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); var context = new Context("test"); - var raiseIntentRequest = new RaiseIntentRequest() + var raiseIntentRequest = new RaiseIntentRequest { MessageId = int.MaxValue, Fdc3InstanceId = Guid.NewGuid().ToString(), Intent = "intentMetadata4", Selected = false, Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var raiseIntentResponse = await _fdc3.RaiseIntent(raiseIntentRequest); - raiseIntentResponse!.Response.AppMetadata.Should().HaveCount(1); + raiseIntentResponse.Response.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResponse.Response.MessageId!, Intent = "intentMetadata4", @@ -278,22 +283,23 @@ public async Task GetIntentResult_fails() var storeResponse = await _fdc3.StoreIntentResult(storeIntentRequest); storeResponse.Error.Should().BeNull(); - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = raiseIntentResponse.Response.MessageId!, Intent = "dummy", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = raiseIntentResponse.Response.AppMetadata!.First().InstanceId! }, + TargetAppIdentifier = new AppIdentifier + {AppId = "appId1", InstanceId = raiseIntentResponse.Response.AppMetadata!.First().InstanceId!}, Version = "1.0" }; var result = await _fdc3.GetIntentResult(getIntentResultRequest); - result.Should().BeEquivalentTo(new GetIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed }); + result.Should().BeEquivalentTo(new GetIntentResultResponse {Error = ResolveError.IntentDeliveryFailed}); } [Fact] public async Task StoreIntentResult_throws() { - var request = new StoreIntentResultRequest() + var request = new StoreIntentResultRequest { MessageId = "dummy", Intent = "dummy", @@ -313,22 +319,22 @@ await action.Should() public async Task StoreIntentResult_returns() { await _fdc3.StartAsync(CancellationToken.None); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() + var raiseIntentRequest = new RaiseIntentRequest { MessageId = int.MaxValue, Fdc3InstanceId = Guid.NewGuid().ToString(), Intent = "intentMetadata4", Selected = false, Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var raiseIntentResponse = await _fdc3.RaiseIntent(raiseIntentRequest); - raiseIntentResponse!.Response.AppMetadata.Should().HaveCount(1); + raiseIntentResponse.Response.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResponse!.Response.MessageId!, Intent = "intentMetadata4", @@ -340,7 +346,7 @@ public async Task StoreIntentResult_returns() var result = await _fdc3.StoreIntentResult(storeIntentRequest); result.Should().NotBeNull(); - result.Should().BeEquivalentTo(new StoreIntentResultResponse() { Stored = true }); + result.Should().BeEquivalentTo(new StoreIntentResultResponse {Stored = true}); } [Fact] @@ -356,24 +362,24 @@ public async Task AddIntentListener_subscribes() var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() + var raiseIntentRequest = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = originFdc3InstanceId, Intent = "intentMetadataCustom", Selected = false, Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var raiseIntentResponse = await _fdc3.RaiseIntent(raiseIntentRequest); raiseIntentResponse.Should().NotBeNull(); - raiseIntentResponse!.Response.AppMetadata.Should().HaveCount(1); - raiseIntentResponse!.Response.AppMetadata!.First()!.AppId.Should().Be("appId4"); - raiseIntentResponse!.Response.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); - raiseIntentResponse!.RaiseIntentResolutionMessages.Should().BeEmpty(); + raiseIntentResponse.Response.AppMetadata.Should().HaveCount(1); + raiseIntentResponse.Response.AppMetadata!.First().AppId.Should().Be("appId4"); + raiseIntentResponse.Response.AppMetadata!.First().InstanceId.Should().Be(targetFdc3InstanceId); + raiseIntentResponse.RaiseIntentResolutionMessages.Should().BeEmpty(); - var addIntentListenerRequest = new IntentListenerRequest() + var addIntentListenerRequest = new IntentListenerRequest { Intent = "intentMetadataCustom", Fdc3InstanceId = targetFdc3InstanceId, @@ -383,8 +389,8 @@ public async Task AddIntentListener_subscribes() var addIntentListenerResponse = await _fdc3.AddIntentListener(addIntentListenerRequest); addIntentListenerResponse.Should().NotBeNull(); - addIntentListenerResponse!.Response.Stored.Should().BeTrue(); - addIntentListenerResponse!.RaiseIntentResolutionMessages.Should().NotBeEmpty(); + addIntentListenerResponse.Response.Stored.Should().BeTrue(); + addIntentListenerResponse.RaiseIntentResolutionMessages.Should().NotBeEmpty(); } [Fact] @@ -400,24 +406,24 @@ public async Task AddIntentListener_unsubscribes() var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() + var raiseIntentRequest = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = originFdc3InstanceId, Intent = "intentMetadataCustom", Selected = false, Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var raiseIntentResponse = await _fdc3.RaiseIntent(raiseIntentRequest); raiseIntentResponse.Should().NotBeNull(); - raiseIntentResponse!.Response.AppMetadata.Should().HaveCount(1); - raiseIntentResponse!.Response.AppMetadata!.First()!.AppId.Should().Be("appId4"); - raiseIntentResponse!.Response.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); - raiseIntentResponse!.RaiseIntentResolutionMessages.Should().BeEmpty(); + raiseIntentResponse.Response.AppMetadata.Should().HaveCount(1); + raiseIntentResponse.Response.AppMetadata!.First()!.AppId.Should().Be("appId4"); + raiseIntentResponse.Response.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); + raiseIntentResponse.RaiseIntentResolutionMessages.Should().BeEmpty(); - var addIntentListenerRequest1 = new IntentListenerRequest() + var addIntentListenerRequest1 = new IntentListenerRequest { Intent = "intentMetadataCustom", Fdc3InstanceId = targetFdc3InstanceId, @@ -426,10 +432,10 @@ public async Task AddIntentListener_unsubscribes() var addIntentListenerResponse1 = await _fdc3.AddIntentListener(addIntentListenerRequest1); addIntentListenerResponse1.Should().NotBeNull(); - addIntentListenerResponse1!.Response.Stored.Should().BeTrue(); - addIntentListenerResponse1!.RaiseIntentResolutionMessages.Should().NotBeEmpty(); + addIntentListenerResponse1.Response.Stored.Should().BeTrue(); + addIntentListenerResponse1.RaiseIntentResolutionMessages.Should().NotBeEmpty(); - var addIntentListenerRequest2 = new IntentListenerRequest() + var addIntentListenerRequest2 = new IntentListenerRequest { Intent = "intentMetadataCustom", Fdc3InstanceId = targetFdc3InstanceId, @@ -438,14 +444,14 @@ public async Task AddIntentListener_unsubscribes() var addIntentListenerResponse2 = await _fdc3.AddIntentListener(addIntentListenerRequest2); addIntentListenerResponse2.Should().NotBeNull(); - addIntentListenerResponse2!.Response.Stored.Should().BeFalse(); - addIntentListenerResponse2!.RaiseIntentResolutionMessages.Should().BeEmpty(); + addIntentListenerResponse2.Response.Stored.Should().BeFalse(); + addIntentListenerResponse2.RaiseIntentResolutionMessages.Should().BeEmpty(); } [Fact] public async Task AddIntentListener_unsubscribe_fails() { - var addIntentListenerRequest = new IntentListenerRequest() + var addIntentListenerRequest = new IntentListenerRequest { Intent = "intentMetadataCustom", Fdc3InstanceId = Guid.NewGuid().ToString(), @@ -454,15 +460,15 @@ public async Task AddIntentListener_unsubscribe_fails() var addIntentListenerResponse = await _fdc3.AddIntentListener(addIntentListenerRequest); addIntentListenerResponse.Should().NotBeNull(); - addIntentListenerResponse!.Response.Stored.Should().BeFalse(); - addIntentListenerResponse!.RaiseIntentResolutionMessages.Should().BeEmpty(); - addIntentListenerResponse!.Response.Error.Should().Be(Fdc3DesktopAgentErrors.MissingId); + addIntentListenerResponse.Response.Stored.Should().BeFalse(); + addIntentListenerResponse.RaiseIntentResolutionMessages.Should().BeEmpty(); + addIntentListenerResponse.Response.Error.Should().Be(Fdc3DesktopAgentErrors.MissingId); } [Fact] public async Task RaiseIntent_returns_NoAppsFound() { - var request = new RaiseIntentRequest() + var request = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = Guid.NewGuid().ToString(), @@ -473,48 +479,14 @@ public async Task RaiseIntent_returns_NoAppsFound() var result = await _fdc3.RaiseIntent(request); result.Should().NotBeNull(); - result!.Response.Error.Should().Be(ResolveError.NoAppsFound); - } - - [Fact] - public async Task RaiseIntent_returns_IntentDeliveryFailed() - { - var request = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata8", - Selected = false, - Context = new Context("context7") - }; - - var result = await _fdc3.RaiseIntent(request); - result.Should().NotBeNull(); - result!.Response.Error.Should().Be(ResolveError.IntentDeliveryFailed); - } - - [Fact] - public async Task RaiseIntent_fails_as_request_specifies_error() - { - var request = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "someIntent", - Selected = false, - Error = "Some weird error" - }; - - var result = await _fdc3.RaiseIntent(request); - - result!.Response.Error.Should().Be("Some weird error"); + result.Response.Error.Should().Be(ResolveError.NoAppsFound); } //TODO: Right now we are returning just one element, without the possibility of selecting via ResolverUI. [Fact] public async Task RaiseIntent_returns_first_app() { - var request = new RaiseIntentRequest() + var request = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = Guid.NewGuid().ToString(), @@ -525,26 +497,9 @@ public async Task RaiseIntent_returns_first_app() var result = await _fdc3.RaiseIntent(request); result.Should().NotBeNull(); - result!.RaiseIntentResolutionMessages.Should().BeEmpty(); - result!.Response!.AppMetadata.Should().HaveCount(1); - result!.Response.AppMetadata!.First().AppId.Should().Be("appId4"); - } - - [Fact] - public async Task RaiseIntent_fails_as_multiple_AppIntent_found() - { - var request = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata8", //wrongly setup AppDirectory on purpose - Selected = false, - Context = new Context("context7") - }; - - var result = await _fdc3.RaiseIntent(request); - result.Should().NotBeNull(); - result!.Response.Error.Should().Be(ResolveError.IntentDeliveryFailed); + result.RaiseIntentResolutionMessages.Should().BeEmpty(); + result.Response.AppMetadata.Should().HaveCount(1); + result.Response.AppMetadata!.First().AppId.Should().Be("appId4"); } [Fact] @@ -560,47 +515,37 @@ public async Task RaiseIntent_returns_one_running_app() var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var addIntentListenerRequest = new IntentListenerRequest() + var addIntentListenerRequest = new IntentListenerRequest { Intent = "intentMetadataCustom", Fdc3InstanceId = targetFdc3InstanceId, State = SubscribeState.Subscribe }; - var addIntentListnerResponse = await _fdc3.AddIntentListener(addIntentListenerRequest); - addIntentListnerResponse.Should().NotBeNull(); - addIntentListnerResponse!.Response.Stored.Should().BeTrue(); - addIntentListnerResponse.RaiseIntentResolutionMessages.Should().BeEmpty(); + var addIntentListenerResponse = await _fdc3.AddIntentListener(addIntentListenerRequest); + addIntentListenerResponse.Should().NotBeNull(); + addIntentListenerResponse.Response.Stored.Should().BeTrue(); + addIntentListenerResponse.RaiseIntentResolutionMessages.Should().BeEmpty(); - var request = new RaiseIntentRequest() + var request = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = originFdc3InstanceId, Intent = "intentMetadataCustom", Selected = false, Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var result = await _fdc3.RaiseIntent(request); result.Should().NotBeNull(); - result!.Response.AppMetadata.Should().HaveCount(1); - result!.Response.AppMetadata!.First()!.AppId.Should().Be("appId4"); - result!.Response.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); + result.Response.AppMetadata.Should().HaveCount(1); + result.Response.AppMetadata!.First().AppId.Should().Be("appId4"); + result.Response.AppMetadata!.First().InstanceId.Should().Be(targetFdc3InstanceId); result.RaiseIntentResolutionMessages.Should().NotBeEmpty(); - result!.Response!.Intent.Should().Be("intentMetadataCustom"); - result!.RaiseIntentResolutionMessages!.Should().HaveCount(1); - result!.RaiseIntentResolutionMessages!.First().TargetModuleInstanceId.Should().Be(targetFdc3InstanceId); - } - - public async Task InitializeAsync() - { - await _fdc3.StartAsync(CancellationToken.None); - } - - public async Task DisposeAsync() - { - await _fdc3.StopAsync(CancellationToken.None); + result.Response.Intent.Should().Be("intentMetadataCustom"); + result.RaiseIntentResolutionMessages.Should().HaveCount(1); + result.RaiseIntentResolutionMessages.First().TargetModuleInstanceId.Should().Be(targetFdc3InstanceId); } -} +} \ No newline at end of file diff --git a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs index 321323d08..671dbf085 100644 --- a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs +++ b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs @@ -12,46 +12,64 @@ * and limitations under the License. */ +using Finos.Fdc3; +using Finos.Fdc3.AppDirectory; +using Finos.Fdc3.Context; using Microsoft.Extensions.Logging.Abstractions; using MorganStanley.ComposeUI.Fdc3.AppDirectory; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Exceptions; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.Helpers; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.TestUtils; using MorganStanley.ComposeUI.ModuleLoader; -using Finos.Fdc3; -using Finos.Fdc3.AppDirectory; -using Finos.Fdc3.Context; -using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata; -using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent; using AppIdentifier = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIdentifier; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; +using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent; +using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata; +using IntentMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.IntentMetadata; namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests.Infrastructure.Internal; public class Fdc3DesktopAgentMessageRouterServiceTests : IAsyncLifetime { - private readonly Mock _mockMessageRouter = new(); - private readonly MockModuleLoader _mockModuleLoader = new(); + private const string TestChannel = "testChannel"; + private readonly IAppDirectory _appDirectory = new AppDirectory.AppDirectory( - new AppDirectoryOptions() + new AppDirectoryOptions { Source = new Uri($"file:\\\\{Directory.GetCurrentDirectory()}\\TestUtils\\appDirectorySample.json") }); private readonly Fdc3DesktopAgentMessageRouterService _fdc3; - private const string TestChannel = "testChannel"; + private readonly Mock _mockMessageRouter = new(); + private readonly MockModuleLoader _mockModuleLoader = new(); public Fdc3DesktopAgentMessageRouterServiceTests() { - _fdc3 = new( + _fdc3 = new Fdc3DesktopAgentMessageRouterService( _mockMessageRouter.Object, - new Fdc3DesktopAgent(_appDirectory, _mockModuleLoader.Object, new Fdc3DesktopAgentOptions(), NullLoggerFactory.Instance), + new Fdc3DesktopAgent( + _appDirectory, + _mockModuleLoader.Object, + new Fdc3DesktopAgentOptions(), + NullLoggerFactory.Instance), new Fdc3DesktopAgentOptions(), NullLoggerFactory.Instance); } + private FindChannelRequest FindTestChannel => new() {ChannelId = "testChannel", ChannelType = ChannelType.User}; + + public async Task InitializeAsync() + { + await _fdc3.StartAsync(CancellationToken.None); + } + + public async Task DisposeAsync() + { + await _fdc3.StopAsync(CancellationToken.None); + } + [Fact] public async void UserChannelAddedCanBeFound() { @@ -66,15 +84,15 @@ public async void UserChannelAddedCanBeFound() [Fact] public async Task RaiseIntent_returns_one_app_by_AppIdentifier() { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4" } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4"} + }; var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); result.Should().NotBeNull(); @@ -86,7 +104,7 @@ public async Task RaiseIntent_returns_one_app_by_AppIdentifier() [Fact] public async Task RaiseIntent_fails_by_request_delivery_error() { - var result = await _fdc3.HandleRaiseIntent(null, new MessageContext()); + var result = await _fdc3.HandleRaiseIntent(request: null, new MessageContext()); result.Should().NotBeNull(); result!.Error.Should().Be(ResolveError.IntentDeliveryFailed); } @@ -94,7 +112,7 @@ public async Task RaiseIntent_fails_by_request_delivery_error() [Fact] public async Task RaiseIntent_returns_one_app_by_Context() { - var request = new RaiseIntentRequest() + var request = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = Guid.NewGuid().ToString(), @@ -111,38 +129,50 @@ public async Task RaiseIntent_returns_one_app_by_Context() } [Fact] - public async Task RaiseIntent_returns_one_app_by_AppIdentifier_and_saves_context_to_resolve_it_when_registers_its_intentHandler() + public async Task + RaiseIntent_returns_one_app_by_AppIdentifier_and_saves_context_to_resolve_it_when_registers_its_intentHandler() { await _fdc3.StartAsync(CancellationToken.None); //TODO: should add some identifier to the query => "fdc3:" + instance.Manifest.Id var instance = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(instance); - var request = new RaiseIntentRequest() + var request = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = Guid.NewGuid().ToString(), Intent = "intentMetadataCustom", Selected = false, Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var result = await _fdc3.HandleRaiseIntent(request, new MessageContext()); result.Should().NotBeNull(); result!.AppMetadata.Should().HaveCount(1); - result!.AppMetadata!.First()!.AppId.Should().Be("appId4"); - result!.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); + result!.AppMetadata!.First().AppId.Should().Be("appId4"); + result!.AppMetadata!.First().InstanceId.Should().Be(targetFdc3InstanceId); _mockMessageRouter.Verify( - _ => _.InvokeAsync(Fdc3Topic.AddIntentListener, It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + _ => _.InvokeAsync( + Fdc3Topic.AddIntentListener, + It.IsAny(), + It.IsAny(), + It.IsAny()), + Times.Never); _mockMessageRouter.Verify( - _ => _.InvokeAsync(Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + _ => _.InvokeAsync( + Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), + It.IsAny(), + It.IsAny(), + It.IsAny()), + Times.Never); } [Fact] - public async Task RaiseIntent_returns_one_app_by_AppIdentifier_and_publishes_context_to_resolve_it_when_registers_its_intentHandler() + public async Task + RaiseIntent_returns_one_app_by_AppIdentifier_and_publishes_context_to_resolve_it_when_registers_its_intentHandler() { await _fdc3.StartAsync(CancellationToken.None); @@ -154,35 +184,41 @@ public async Task RaiseIntent_returns_one_app_by_AppIdentifier_and_publishes_con var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var addIntentListenerRequest = new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }; + var addIntentListenerRequest = new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }; - var addIntentListenerResult = await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); + var addIntentListenerResult = + await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); addIntentListenerResult.Should().NotBeNull(); addIntentListenerResult!.Stored.Should().BeTrue(); - var request = new RaiseIntentRequest() + var request = new RaiseIntentRequest { MessageId = 1, Fdc3InstanceId = originFdc3InstanceId, Intent = "intentMetadataCustom", Selected = false, Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var result = await _fdc3.HandleRaiseIntent(request, new MessageContext()); result.Should().NotBeNull(); result!.AppMetadata.Should().HaveCount(1); - result!.AppMetadata!.First()!.AppId.Should().Be("appId4"); - result!.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); + result!.AppMetadata!.First().AppId.Should().Be("appId4"); + result!.AppMetadata!.First().InstanceId.Should().Be(targetFdc3InstanceId); _mockMessageRouter.Verify( - _ => _.PublishAsync(Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + _ => _.PublishAsync( + Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), + It.IsAny(), + It.IsAny(), + It.IsAny()), + Times.Once); } //TODO: Right now we are returning just one element, without the possibility of selecting via ResolverUI. @@ -190,19 +226,19 @@ public async Task RaiseIntent_returns_one_app_by_AppIdentifier_and_publishes_con public async Task RaiseIntent_returns_first_app_by_Context() { var instanceId = Guid.NewGuid().ToString(); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = instanceId, - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2") - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = instanceId, + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2") + }; var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); result.Should().NotBeNull(); result!.AppMetadata.Should().HaveCount(1); - result!.AppMetadata!.First().AppId.Should().Be("appId4"); + result.AppMetadata!.First().AppId.Should().Be("appId4"); } //TODO: Right now we are returning just one element, without the possibility of selecting via ResolverUI. @@ -210,14 +246,14 @@ public async Task RaiseIntent_returns_first_app_by_Context() public async Task RaiseIntent_returns_first_app_by_Context_if_fdc3_nothing() { var instanceId = Guid.NewGuid().ToString(); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = instanceId, - Intent = "intentMetadata4", - Selected = false, - Context = new Context(ContextTypes.Nothing) - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = instanceId, + Intent = "intentMetadata4", + Selected = false, + Context = new Context(ContextTypes.Nothing) + }; var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); result.Should().NotBeNull(); @@ -228,15 +264,15 @@ public async Task RaiseIntent_returns_first_app_by_Context_if_fdc3_nothing() [Fact] public async Task RaiseIntent_fails_as_no_apps_found_by_AppIdentifier() { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "testIntent", - Selected = false, - Context = new Context("contextType"), - TargetAppIdentifier = new AppIdentifier() { AppId = "noAppShouldReturn" } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "testIntent", + Selected = false, + Context = new Context("contextType"), + TargetAppIdentifier = new AppIdentifier {AppId = "noAppShouldReturn"} + }; var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); result.Should().NotBeNull(); @@ -246,14 +282,14 @@ public async Task RaiseIntent_fails_as_no_apps_found_by_AppIdentifier() [Fact] public async Task RaiseIntent_fails_as_no_apps_found_by_Context() { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("noAppShouldReturn") - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("noAppShouldReturn") + }; var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); result.Should().NotBeNull(); @@ -263,98 +299,67 @@ public async Task RaiseIntent_fails_as_no_apps_found_by_Context() [Fact] public async Task RaiseIntent_fails_as_no_apps_found_by_Intent() { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "noAppShouldReturn", - Selected = false, - Context = new Context("context2") - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "noAppShouldReturn", + Selected = false, + Context = new Context("context2") + }; var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); result.Should().NotBeNull(); result!.Error.Should().Be(ResolveError.NoAppsFound); } - [Fact] - public async Task RaiseIntent_fails_as_multiple_IAppIntents_found() - { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata8", - Selected = false, - Context = new Context("context7") - }; - - var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); - result.Should().NotBeNull(); - result!.Error.Should().Be(ResolveError.IntentDeliveryFailed); - } - - [Fact] - public async Task RaiseIntent_fails_as_request_specifies_error() - { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "someIntent", - Selected = false, - Error = "Some weird error" - }; - - var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); - result!.Error.Should().Be("Some weird error"); - } - [Fact] public async Task StoreIntentResult_fails_due_the_request() { - var result = await _fdc3.HandleStoreIntentResult(null, new MessageContext()); + var result = await _fdc3.HandleStoreIntentResult(request: null, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new StoreIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed, Stored = false }); + result!.Should() + .BeEquivalentTo(new StoreIntentResultResponse {Error = ResolveError.IntentDeliveryFailed, Stored = false}); } [Fact] public async Task StoreIntentResult_fails_due_the_request_contains_no_information() { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4" } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4"} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "dummy", OriginFdc3InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!, TargetFdc3InstanceId = null, ChannelId = "dummyChannelId", - ChannelType = ChannelType.User, + ChannelType = ChannelType.User }; var result = await _fdc3.HandleStoreIntentResult(storeIntentRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new StoreIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed, Stored = false }); + result!.Should() + .BeEquivalentTo(new StoreIntentResultResponse {Error = ResolveError.IntentDeliveryFailed, Stored = false}); } [Fact] public async Task StoreIntentResult_fails_due_the_previosly_no_saved_raiseIntent_could_handle() { var originFdc3InstanceId = Guid.NewGuid().ToString(); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = "dummy", Intent = "dummy", @@ -374,16 +379,16 @@ await action.Should() public async Task StoreIntentResult_succeeds_with_channel() { await _fdc3.StartAsync(CancellationToken.None); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() + var raiseIntentRequest = new RaiseIntentRequest { MessageId = int.MaxValue, Fdc3InstanceId = Guid.NewGuid().ToString(), Intent = "intentMetadata4", Selected = false, Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); @@ -392,7 +397,7 @@ public async Task StoreIntentResult_succeeds_with_channel() raiseIntentResult.AppMetadata.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult!.MessageId!, Intent = "intentMetadata4", @@ -404,27 +409,27 @@ public async Task StoreIntentResult_succeeds_with_channel() var result = await _fdc3.HandleStoreIntentResult(storeIntentRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new StoreIntentResultResponse() { Stored = true }); + result!.Should().BeEquivalentTo(new StoreIntentResultResponse {Stored = true}); } [Fact] public async Task StoreIntentResult_succeeds_with_context() { - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = true, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4" } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = true, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4"} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", @@ -437,31 +442,31 @@ public async Task StoreIntentResult_succeeds_with_context() var result = await _fdc3.HandleStoreIntentResult(storeIntentRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new StoreIntentResultResponse() { Stored = true }); + result!.Should().BeEquivalentTo(new StoreIntentResultResponse {Stored = true}); } [Fact] public async Task StoreIntentResult_succeeds_with_voidResult() { await _fdc3.StartAsync(CancellationToken.None); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", @@ -475,48 +480,48 @@ public async Task StoreIntentResult_succeeds_with_voidResult() var result = await _fdc3.HandleStoreIntentResult(storeIntentRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new StoreIntentResultResponse() { Stored = true }); + result!.Should().BeEquivalentTo(new StoreIntentResultResponse {Stored = true}); } [Fact] public async Task GetIntentResult_fails_due_the_request() { - var result = await _fdc3.HandleGetIntentResult(null, new MessageContext()); + var result = await _fdc3.HandleGetIntentResult(request: null, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new GetIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed }); + result!.Should().BeEquivalentTo(new GetIntentResultResponse {Error = ResolveError.IntentDeliveryFailed}); } [Fact] public async Task GetIntentResult_fails_intent_not_found() { //Version should be the Intent's schema version - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = "dummy", Intent = "dummy", - TargetAppIdentifier = new AppIdentifier() { AppId = "dummy", InstanceId = Guid.NewGuid().ToString() }, + TargetAppIdentifier = new AppIdentifier {AppId = "dummy", InstanceId = Guid.NewGuid().ToString()}, Version = "1.0" }; var result = await _fdc3.HandleGetIntentResult(getIntentResultRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new GetIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed }); + result!.Should().BeEquivalentTo(new GetIntentResultResponse {Error = ResolveError.IntentDeliveryFailed}); } [Fact] public async Task GetIntentResult_fails_due_InstanceId_is_null() { - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = "dummy", Intent = "dummy", - TargetAppIdentifier = new AppIdentifier() { AppId = "dummy" }, + TargetAppIdentifier = new AppIdentifier {AppId = "dummy"}, Version = "1.0" }; var result = await _fdc3.HandleGetIntentResult(getIntentResultRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new GetIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed }); + result!.Should().BeEquivalentTo(new GetIntentResultResponse {Error = ResolveError.IntentDeliveryFailed}); } [Fact] @@ -524,26 +529,26 @@ public async Task GetIntentResult_fails_due_no_intent_found() { await _fdc3.StartAsync(CancellationToken.None); var originFdc3InstanceId = Guid.NewGuid().ToString(); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); var context = new Context("test"); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", @@ -556,17 +561,18 @@ public async Task GetIntentResult_fails_due_no_intent_found() storeResult.Should().NotBeNull(); storeResult!.Should().BeEquivalentTo(StoreIntentResultResponse.Success()); - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "dummy", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId! }, + TargetAppIdentifier = new AppIdentifier + {AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!}, Version = "1.0" }; var result = await _fdc3.HandleGetIntentResult(getIntentResultRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(new GetIntentResultResponse() { Error = ResolveError.IntentDeliveryFailed }); + result!.Should().BeEquivalentTo(new GetIntentResultResponse {Error = ResolveError.IntentDeliveryFailed}); } [Fact] @@ -575,24 +581,24 @@ public async Task GetIntentResult_succeeds_with_context() await _fdc3.StartAsync(CancellationToken.None); var originFdc3InstanceId = Guid.NewGuid().ToString(); var context = new Context("test"); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", @@ -605,11 +611,12 @@ public async Task GetIntentResult_succeeds_with_context() storeResult.Should().NotBeNull(); storeResult!.Should().BeEquivalentTo(StoreIntentResultResponse.Success()); - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId! } + TargetAppIdentifier = new AppIdentifier + {AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!} }; var result = await _fdc3.HandleGetIntentResult(getIntentResultRequest, new MessageContext()); @@ -624,24 +631,24 @@ public async Task GetIntentResult_succeeds_with_channel() var originFdc3InstanceId = Guid.NewGuid().ToString(); var channelType = ChannelType.User; var channelId = "dummyChannelId"; - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest =new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", @@ -655,16 +662,18 @@ public async Task GetIntentResult_succeeds_with_channel() storeResult.Should().NotBeNull(); storeResult!.Should().BeEquivalentTo(StoreIntentResultResponse.Success()); - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId! } + TargetAppIdentifier = new AppIdentifier + {AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!} }; var result = await _fdc3.HandleGetIntentResult(getIntentResultRequest, new MessageContext()); result.Should().NotBeNull(); - result!.Should().BeEquivalentTo(GetIntentResultResponse.Success(channelType: channelType, channelId: channelId)); + result!.Should() + .BeEquivalentTo(GetIntentResultResponse.Success(channelType: channelType, channelId: channelId)); } [Fact] @@ -673,24 +682,24 @@ public async Task GetIntentResult_succeeds_with_voidResult() await _fdc3.StartAsync(CancellationToken.None); var originFdc3InstanceId = Guid.NewGuid().ToString(); - var target = await _mockModuleLoader.Object.StartModule(new("appId4")); + var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = int.MaxValue, - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Selected = false, - Context = new Context("context2"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = int.MaxValue, + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Selected = false, + Context = new Context("context2"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - var storeIntentRequest = new StoreIntentResultRequest() + var storeIntentRequest = new StoreIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", @@ -703,11 +712,12 @@ public async Task GetIntentResult_succeeds_with_voidResult() storeResult.Should().NotBeNull(); storeResult!.Should().BeEquivalentTo(StoreIntentResultResponse.Success()); - var getIntentResultRequest = new GetIntentResultRequest() + var getIntentResultRequest = new GetIntentResultRequest { MessageId = raiseIntentResult.MessageId!, Intent = "intentMetadata4", - TargetAppIdentifier = new AppIdentifier() { AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId! } + TargetAppIdentifier = new AppIdentifier + {AppId = "appId1", InstanceId = raiseIntentResult.AppMetadata!.First().InstanceId!} }; var result = await _fdc3.HandleGetIntentResult(getIntentResultRequest, new MessageContext()); @@ -718,7 +728,7 @@ public async Task GetIntentResult_succeeds_with_voidResult() [Fact] public async Task AddIntentListener_fails_due_no_payload() { - var result = await _fdc3.HandleAddIntentListener(null, new()); + var result = await _fdc3.HandleAddIntentListener(request: null, new MessageContext()); result.Should().NotBeNull(); result!.Should().BeEquivalentTo(IntentListenerResponse.Failure(Fdc3DesktopAgentErrors.PayloadNull)); } @@ -726,14 +736,14 @@ public async Task AddIntentListener_fails_due_no_payload() [Fact] public async Task AddIntentListener_fails_due_missing_id() { - var request = new IntentListenerRequest() + var request = new IntentListenerRequest { Intent = "dummy", Fdc3InstanceId = Guid.NewGuid().ToString(), State = SubscribeState.Unsubscribe }; - var result = await _fdc3.HandleAddIntentListener(request, new()); + var result = await _fdc3.HandleAddIntentListener(request, new MessageContext()); result.Should().NotBeNull(); result!.Should().BeEquivalentTo(IntentListenerResponse.Failure(Fdc3DesktopAgentErrors.MissingId)); } @@ -751,35 +761,40 @@ public async Task AddIntentListener_subscribes_to_existing_raised_intent() var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadataCustom", - Selected = false, - Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadataCustom", + Selected = false, + Context = new Context("contextCustom"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - raiseIntentResult!.AppMetadata!.First()!.AppId.Should().Be("appId4"); - raiseIntentResult!.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); + raiseIntentResult.AppMetadata!.First()!.AppId.Should().Be("appId4"); + raiseIntentResult.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); - var addIntentListenerRequest = new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }; + var addIntentListenerRequest = new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }; - var addIntentListenerResult = await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); + var addIntentListenerResult = + await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); addIntentListenerResult.Should().NotBeNull(); addIntentListenerResult!.Stored.Should().BeTrue(); _mockMessageRouter.Verify( - _ => _.PublishAsync(Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), It.IsAny(), It.IsAny(), It.IsAny())); + _ => _.PublishAsync( + Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), + It.IsAny(), + It.IsAny(), + It.IsAny())); } [Fact] @@ -795,35 +810,40 @@ public async Task AddIntentListener_subscribes() var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var addIntentListenerRequest = new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }; + var addIntentListenerRequest = new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }; - var addIntentListenerResult = await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); + var addIntentListenerResult = + await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); addIntentListenerResult.Should().NotBeNull(); addIntentListenerResult!.Stored.Should().BeTrue(); - var raiseIntentRequest = new RaiseIntentRequest() - { - MessageId = 1, - Fdc3InstanceId = originFdc3InstanceId, - Intent = "intentMetadataCustom", - Selected = false, - Context = new Context("contextCustom"), - TargetAppIdentifier = new AppIdentifier() { AppId = "appId4", InstanceId = targetFdc3InstanceId } - }; + var raiseIntentRequest = new RaiseIntentRequest + { + MessageId = 1, + Fdc3InstanceId = originFdc3InstanceId, + Intent = "intentMetadataCustom", + Selected = false, + Context = new Context("contextCustom"), + TargetAppIdentifier = new AppIdentifier {AppId = "appId4", InstanceId = targetFdc3InstanceId} + }; var raiseIntentResult = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext()); raiseIntentResult.Should().NotBeNull(); raiseIntentResult!.AppMetadata.Should().HaveCount(1); - raiseIntentResult!.AppMetadata!.First()!.AppId.Should().Be("appId4"); - raiseIntentResult!.AppMetadata!.First()!.InstanceId.Should().Be(targetFdc3InstanceId); + raiseIntentResult!.AppMetadata!.First().AppId.Should().Be("appId4"); + raiseIntentResult!.AppMetadata!.First().InstanceId.Should().Be(targetFdc3InstanceId); _mockMessageRouter.Verify( - _ => _.PublishAsync(Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), It.IsAny(), It.IsAny(), It.IsAny())); + _ => _.PublishAsync( + Fdc3Topic.RaiseIntentResolution("intentMetadataCustom", targetFdc3InstanceId), + It.IsAny(), + It.IsAny(), + It.IsAny())); } [Fact] @@ -838,32 +858,31 @@ public async Task AddIntentListener_unsubscribes() var target = await _mockModuleLoader.Object.StartModule(new StartRequest("appId4")); var targetFdc3InstanceId = Fdc3InstanceIdRetriever.Get(target); - var addIntentListenerRequest = new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Subscribe - }; + var addIntentListenerRequest = new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Subscribe + }; - var addIntentListenerResult = await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); + var addIntentListenerResult = + await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); addIntentListenerResult.Should().NotBeNull(); addIntentListenerResult!.Stored.Should().BeTrue(); - addIntentListenerRequest = new IntentListenerRequest() - { - Intent = "intentMetadataCustom", - Fdc3InstanceId = targetFdc3InstanceId, - State = SubscribeState.Unsubscribe - }; + addIntentListenerRequest = new IntentListenerRequest + { + Intent = "intentMetadataCustom", + Fdc3InstanceId = targetFdc3InstanceId, + State = SubscribeState.Unsubscribe + }; addIntentListenerResult = await _fdc3.HandleAddIntentListener(addIntentListenerRequest, new MessageContext()); addIntentListenerResult.Should().NotBeNull(); addIntentListenerResult!.Stored.Should().BeFalse(); - addIntentListenerResult!.Error.Should().BeNull(); + addIntentListenerResult.Error.Should().BeNull(); } - private FindChannelRequest FindTestChannel => new FindChannelRequest() { ChannelId = "testChannel", ChannelType = ChannelType.User }; - [Theory] [ClassData(typeof(FindIntentTheoryData))] @@ -899,278 +918,288 @@ public async Task FindIntentsByContext_edge_case_tests(FindIntentsByContextTestC result!.Should().BeEquivalentTo(testCase.ExpectedResponse); } - public async Task InitializeAsync() - { - await _fdc3.StartAsync(CancellationToken.None); - } - - public async Task DisposeAsync() - { - await _fdc3.StopAsync(CancellationToken.None); - } - public class FindIntentsByContextTheoryData : TheoryData { public FindIntentsByContextTheoryData() { // Returning one AppIntent with one app by just passing Context - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("contextCustom") - },//This relates to the appId4 only - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("contextCustom") + }, //This relates to the appId4 only + ExpectedResponse = new FindIntentsByContextResponse { - new AppIntent() + AppIntents = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadataCustom", DisplayName = "intentMetadataCustom" }, - Apps = new [] + new AppIntent { - new AppMetadata(){ AppId ="appId4", Name = "app4", ResultType = null } + Intent = new IntentMetadata + {Name = "intentMetadataCustom", DisplayName = "intentMetadataCustom"}, + Apps = new[] + { + new AppMetadata {AppId = "appId4", Name = "app4", ResultType = null} + } } } - } - }, - ExpectedAppIntentsCount = 1 - }); + }, + ExpectedAppIntentsCount = 1 + }); // Returning one AppIntent with multiple app by just passing Context - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("context2") - }, //This relates to the appId4, appId5, appId6, - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("context2") + }, //This relates to the appId4, appId5, appId6, + ExpectedResponse = new FindIntentsByContextResponse { - new AppIntent() + AppIntents = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new AppMetadata[] + new AppIntent { - new() { AppId = "appId4", Name = "app4", ResultType = null }, - new() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new() { AppId = "appId6", Name = "app6", ResultType = "resultType" } + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new AppMetadata[] + { + new() {AppId = "appId4", Name = "app4", ResultType = null}, + new() {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new() {AppId = "appId6", Name = "app6", ResultType = "resultType"} + } } } - } - }, - ExpectedAppIntentsCount = 1 - }); - - // Returning multiple appIntent by just passing Context - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("context9") - },//This relates to the wrongappId9 and an another wrongAppId9 with 2 individual IntentMetadata - ExpectedResponse = new FindIntentsByContextResponse() + }, + ExpectedAppIntentsCount = 1 + }); + + // Returning multiple appIntents by just passing Context + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("context9") + }, //This relates to the wrongappId9 and an another wrongAppId9 with 2 individual IntentMetadata + ExpectedResponse = new FindIntentsByContextResponse { - new AppIntent() + AppIntents = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata9", DisplayName = "displayName9" }, - Apps = new [] + new AppIntent { - new AppMetadata() + Intent = new IntentMetadata {Name = "intentMetadata9", DisplayName = "displayName9"}, + Apps = new[] { - AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp" - }, - } - }, - new AppIntent() - { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata10", DisplayName = "displayName10" }, - Apps = new [] + new AppMetadata + { + AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp" + } + } + }, + new AppIntent { - new AppMetadata(){ AppId = "appId11", Name = "app11", ResultType = "channel" }, - } - }, - new AppIntent() - { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata11", DisplayName = "displayName11" }, - Apps = new [] + Intent = new IntentMetadata {Name = "intentMetadata10", DisplayName = "displayName10"}, + Apps = new[] + { + new AppMetadata + {AppId = "appId11", Name = "app11", ResultType = "channel"} + } + }, + new AppIntent { - new AppMetadata() { AppId = "appId12", Name = "app12", ResultType = "resultWrongApp"}, + Intent = new IntentMetadata {Name = "intentMetadata11", DisplayName = "displayName11"}, + Apps = new[] + { + new AppMetadata {AppId = "appId12", Name = "app12", ResultType = "resultWrongApp"} + } } } - } - }, - ExpectedAppIntentsCount = 3 - }); + }, + ExpectedAppIntentsCount = 3 + }); // Returning error no apps found by just passing Context - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("noAppShouldReturn") - },// no app should have this context type - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - Error = ResolveError.NoAppsFound - }, - ExpectedAppIntentsCount = 0 - }); + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("noAppShouldReturn") + }, // no app should have this context type + ExpectedResponse = new FindIntentsByContextResponse + { + Error = ResolveError.NoAppsFound + }, + ExpectedAppIntentsCount = 0 + }); // Returning one AppIntent with one app by ResultType - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("context2"), //This relates to multiple appId - ResultType = "resultType" - }, - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("context2"), //This relates to multiple appId + ResultType = "resultType" + }, + ExpectedResponse = new FindIntentsByContextResponse { - new AppIntent(){ - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata4", DisplayName = "displayName4" }, // it should just return appId5 - Apps = new [] + AppIntents = new[] + { + new AppIntent { - new AppMetadata(){ AppId = "appId5", Name = "app5", ResultType = "resultType" } + Intent = new IntentMetadata + { + Name = "intentMetadata4", DisplayName = "displayName4" + }, // it should just return appId5 + Apps = new[] + { + new AppMetadata + {AppId = "appId5", Name = "app5", ResultType = "resultType"} + } } } - } - }, - ExpectedAppIntentsCount = 1 - }); + }, + ExpectedAppIntentsCount = 1 + }); // Returning one AppIntent with multiple apps by ResultType - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("context2"), //This relates to multiple appId - ResultType = "resultType" - }, - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("context2"), //This relates to multiple appId + ResultType = "resultType" + }, + ExpectedResponse = new FindIntentsByContextResponse { - new AppIntent() + AppIntents = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new[] + new AppIntent { - new AppMetadata(){ AppId ="appId5", Name = "app5", ResultType = "resultType" }, - new AppMetadata(){ AppId ="appId6", Name = "app6", ResultType = "resultType" } + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new[] + { + new AppMetadata + {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new AppMetadata {AppId = "appId6", Name = "app6", ResultType = "resultType"} + } } - }, - } - }, - ExpectedAppIntentsCount = 1 - }); - - // Returning multiple AppIntent by ResultType - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("context9"), //This relates to multiple appId - ResultType = "resultWrongApp" - }, - ExpectedResponse = new FindIntentsByContextResponse() + } + }, + ExpectedAppIntentsCount = 1 + }); + + // Returning multiple AppIntents by ResultType + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("context9"), //This relates to multiple appId + ResultType = "resultWrongApp" + }, + ExpectedResponse = new FindIntentsByContextResponse { - new AppIntent() + AppIntents = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata9", DisplayName = "displayName9" }, - Apps = new [] + new AppIntent { - new AppMetadata() { AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp" }, - } - }, - new AppIntent() - { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata11", DisplayName = "displayName11" }, - Apps = new [] + Intent = new IntentMetadata {Name = "intentMetadata9", DisplayName = "displayName9"}, + Apps = new[] + { + new AppMetadata + {AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp"} + } + }, + new AppIntent { - new AppMetadata() { AppId = "appId12", Name = "app12", ResultType = "resultWrongApp" } + Intent = new IntentMetadata {Name = "intentMetadata11", DisplayName = "displayName11"}, + Apps = new[] + { + new AppMetadata {AppId = "appId12", Name = "app12", ResultType = "resultWrongApp"} + } } } - } - }, - ExpectedAppIntentsCount = 2 - }); + }, + ExpectedAppIntentsCount = 2 + }); // Returning no apps found error by using ResultType - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context("context9"), //This relates to multiple appId - ResultType = "noAppShouldReturn" - }, - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - Error = ResolveError.NoAppsFound - }, - ExpectedAppIntentsCount = 0 - }); + Request = new FindIntentsByContextRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context("context9"), //This relates to multiple appId + ResultType = "noAppShouldReturn" + }, + ExpectedResponse = new FindIntentsByContextResponse + { + Error = ResolveError.NoAppsFound + }, + ExpectedAppIntentsCount = 0 + }); // Returning intent delivery error - AddRow(new FindIntentsByContextTestCase() - { - Request = null, - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - Error = ResolveError.IntentDeliveryFailed - }, - ExpectedAppIntentsCount = 0 - }); + Request = null, + ExpectedResponse = new FindIntentsByContextResponse + { + Error = ResolveError.IntentDeliveryFailed + }, + ExpectedAppIntentsCount = 0 + }); // Returning all the apps that are using the ResultType by adding fdc3.nothing. - AddRow(new FindIntentsByContextTestCase() - { - Request = new FindIntentsByContextRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Context = new Context(ContextTypes.Nothing), - ResultType = "resultWrongApp" - }, - ExpectedResponse = new FindIntentsByContextResponse() + AddRow( + new FindIntentsByContextTestCase { - AppIntents = new[] + Request = new FindIntentsByContextRequest { - new AppIntent() + Fdc3InstanceId = Guid.NewGuid().ToString(), + Context = new Context(ContextTypes.Nothing), + ResultType = "resultWrongApp" + }, + ExpectedResponse = new FindIntentsByContextResponse + { + AppIntents = new[] { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata9", DisplayName = "displayName9" }, - Apps = new [] + new AppIntent { - new AppMetadata() { AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp" }, - } - }, + Intent = new IntentMetadata {Name = "intentMetadata9", DisplayName = "displayName9"}, + Apps = new[] + { + new AppMetadata + {AppId = "wrongappId9", Name = "app9", ResultType = "resultWrongApp"} + } + }, - new AppIntent() - { - Intent = new Protocol.IntentMetadata () { Name = "intentMetadata11", DisplayName = "displayName11" }, - Apps = new [] + new AppIntent { - new AppMetadata() { AppId = "appId12", Name = "app12", ResultType = "resultWrongApp" } + Intent = new IntentMetadata {Name = "intentMetadata11", DisplayName = "displayName11"}, + Apps = new[] + { + new AppMetadata {AppId = "appId12", Name = "app12", ResultType = "resultWrongApp"} + } } - }, - } - }, - ExpectedAppIntentsCount = 2 - }); + } + }, + ExpectedAppIntentsCount = 2 + }); } } @@ -1185,34 +1214,15 @@ private class FindIntentTheoryData : TheoryData { public FindIntentTheoryData() { - //As per the documentation : https://github.com/morganstanley/fdc3-dotnet/blob/main/src/Fdc3/IIntentMetadata.cs - //name is unique for the intents, so it should be unique for every app, or the app should have the same intentMetadata? - //if so we should return multiple appIntents and do not return error message for the client. - //We have setup a test case for wrongappId9 which contains wrongly setted up intentMetadata. AddRow( - new FindIntentTestCase() + new FindIntentTestCase { ExpectedAppCount = 0, - ExpectedResponse = new FindIntentResponse() - { - Error = ResolveError.IntentDeliveryFailed - }, - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata8" - } - }); - - AddRow( - new FindIntentTestCase() - { - ExpectedAppCount = 0, - ExpectedResponse = new FindIntentResponse() + ExpectedResponse = new FindIntentResponse { Error = ResolveError.NoAppsFound }, - Request = new FindIntentRequest() + Request = new FindIntentRequest { Fdc3InstanceId = Guid.NewGuid().ToString(), Intent = "intentMetadata2", @@ -1221,198 +1231,207 @@ public FindIntentTheoryData() }); AddRow( - new FindIntentTestCase() + new FindIntentTestCase { ExpectedAppCount = 0, - ExpectedResponse = new FindIntentResponse() + ExpectedResponse = new FindIntentResponse { Error = ResolveError.IntentDeliveryFailed }, Request = null }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata7", - Context = new Context("context8"), - ResultType = "resultType2" - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata7", + Context = new Context("context8"), + ResultType = "resultType2" + }, + ExpectedResponse = new FindIntentResponse { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadat7", DisplayName = "displayName7" }, - Apps = new[] + AppIntent = new AppIntent { - new AppMetadata(){ AppId = "appId7", Name = "app7", ResultType = "resultType2" } + Intent = new IntentMetadata {Name = "intentMetadata7", DisplayName = "displayName7"}, + Apps = new[] + { + new AppMetadata + {AppId = "appId7", Name = "app7", ResultType = "resultType2"} + } } - } - }, - ExpectedAppCount = 1 - }); + }, + ExpectedAppCount = 1 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Context = new Context("context2"), - ResultType = "resultType" - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new[] + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Context = new Context("context2"), + ResultType = "resultType" + }, + ExpectedResponse = new FindIntentResponse + { + AppIntent = new AppIntent { - new AppMetadata() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new AppMetadata() { AppId = "appId6", Name = "app6", ResultType = "resultType"}, - + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new[] + { + new AppMetadata {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new AppMetadata {AppId = "appId6", Name = "app6", ResultType = "resultType"} + } } - } - }, - ExpectedAppCount = 2 - }); + }, + ExpectedAppCount = 2 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata7", - ResultType = "resultType2" - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadat7", DisplayName = "displayName7" }, - Apps = new[] + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata7", + ResultType = "resultType2" + }, + ExpectedResponse = new FindIntentResponse + { + AppIntent = new AppIntent { - new AppMetadata() { AppId = "appId7", Name = "app7", ResultType = "resultType2"} + Intent = new IntentMetadata {Name = "intentMetadata7", DisplayName = "displayName7"}, + Apps = new[] + { + new AppMetadata + {AppId = "appId7", Name = "app7", ResultType = "resultType2"} + } } - } - }, - ExpectedAppCount = 1 - }); + }, + ExpectedAppCount = 1 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - ResultType = "resultType" - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new[] + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + ResultType = "resultType" + }, + ExpectedResponse = new FindIntentResponse + { + AppIntent = new AppIntent { - new AppMetadata() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new AppMetadata() { AppId = "appId6", Name = "app6", ResultType = "resultType" }, + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new[] + { + new AppMetadata {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new AppMetadata {AppId = "appId6", Name = "app6", ResultType = "resultType"} + } } - } - }, - ExpectedAppCount = 2 - }); + }, + ExpectedAppCount = 2 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata1", - Context = new Context("context1") - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata1", + Context = new Context("context1") + }, + ExpectedResponse = new FindIntentResponse { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata1", DisplayName = "displayName1" }, - Apps = new[] + AppIntent = new AppIntent { - new AppMetadata() { AppId = "appId1", Name = "app1", ResultType = null } + Intent = new IntentMetadata {Name = "intentMetadata1", DisplayName = "displayName1"}, + Apps = new[] + { + new AppMetadata {AppId = "appId1", Name = "app1", ResultType = null} + } } - } - }, - ExpectedAppCount = 1 - }); + }, + ExpectedAppCount = 1 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4", - Context = new Context("context2") - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4", + Context = new Context("context2") + }, + ExpectedResponse = new FindIntentResponse { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new AppMetadata[] + AppIntent = new AppIntent + { + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new AppMetadata[] { - new() { AppId = "appId4", Name = "app4", ResultType = null }, - new() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new() { AppId = "appId6", Name = "app6", ResultType = "resultType" } + new() {AppId = "appId4", Name = "app4", ResultType = null}, + new() {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new() {AppId = "appId6", Name = "app6", ResultType = "resultType"} } - } - }, - ExpectedAppCount = 3 - }); + } + }, + ExpectedAppCount = 3 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata2" - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata2" + }, + ExpectedResponse = new FindIntentResponse { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata2", DisplayName = "displayName2" }, - Apps = new[] + AppIntent = new AppIntent { - new AppMetadata() { AppId = "appId2", Name = "app2", ResultType = null } + Intent = new IntentMetadata {Name = "intentMetadata2", DisplayName = "displayName2"}, + Apps = new[] + { + new AppMetadata {AppId = "appId2", Name = "app2", ResultType = null} + } } - } - }, - ExpectedAppCount = 1 - }); + }, + ExpectedAppCount = 1 + }); - AddRow(new FindIntentTestCase() - { - Request = new FindIntentRequest() - { - Fdc3InstanceId = Guid.NewGuid().ToString(), - Intent = "intentMetadata4" - }, - ExpectedResponse = new FindIntentResponse() + AddRow( + new FindIntentTestCase { - AppIntent = new AppIntent() + Request = new FindIntentRequest + { + Fdc3InstanceId = Guid.NewGuid().ToString(), + Intent = "intentMetadata4" + }, + ExpectedResponse = new FindIntentResponse { - Intent = new Protocol.IntentMetadata() { Name = "intentMetadata4", DisplayName = "displayName4" }, - Apps = new AppMetadata[] + AppIntent = new AppIntent + { + Intent = new IntentMetadata {Name = "intentMetadata4", DisplayName = "displayName4"}, + Apps = new AppMetadata[] { - new() { AppId = "appId4", Name = "app4", ResultType = null }, - new() { AppId = "appId5", Name = "app5", ResultType = "resultType" }, - new() { AppId = "appId6", Name = "app6", ResultType = "resultType" } + new() {AppId = "appId4", Name = "app4", ResultType = null}, + new() {AppId = "appId5", Name = "app5", ResultType = "resultType"}, + new() {AppId = "appId6", Name = "app6", ResultType = "resultType"} } - } - }, - ExpectedAppCount = 3 - }); + } + }, + ExpectedAppCount = 3 + }); } } @@ -1422,4 +1441,4 @@ public class FindIntentTestCase internal FindIntentResponse ExpectedResponse { get; set; } public int ExpectedAppCount { get; set; } } -} +} \ No newline at end of file diff --git a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/TestUtils/appDirectorySample.json b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/TestUtils/appDirectorySample.json index 4e30d8dcb..812256270 100644 --- a/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/TestUtils/appDirectorySample.json +++ b/src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/TestUtils/appDirectorySample.json @@ -145,7 +145,7 @@ "intents": { "listensFor": { "intentMetadata7": { - "name": "intentMetadat7", + "name": "intentMetadata7", "displayName": "displayName7", "contexts": [ "context8" @@ -175,7 +175,7 @@ "intents": { "listensFor": { "intentMetadata8": { - "name": "intentMetadat8", + "name": "intentMetadata8", "displayName": "displayName8", "contexts": [ "context7" @@ -240,7 +240,7 @@ "interop": { "intents": { "listensFor": { - "intentMetadata10": { + "intentMetadata11": { "name": "intentMetadata11", "displayName": "displayName11", "contexts": [ diff --git a/src/fdc3/js/composeui-fdc3/src/infrastructure/messages/Fdc3RaiseIntentRequest.ts b/src/fdc3/js/composeui-fdc3/src/infrastructure/messages/Fdc3RaiseIntentRequest.ts index e9e56324e..d8c7947fd 100644 --- a/src/fdc3/js/composeui-fdc3/src/infrastructure/messages/Fdc3RaiseIntentRequest.ts +++ b/src/fdc3/js/composeui-fdc3/src/infrastructure/messages/Fdc3RaiseIntentRequest.ts @@ -21,7 +21,6 @@ export class Fdc3RaiseIntentRequest { public readonly intent: string, public readonly selected: boolean, public readonly context: Context, - public readonly targetAppIdentifier?: AppIdentifier, - public readonly error?: string) { + public readonly targetAppIdentifier?: AppIdentifier) { } } \ No newline at end of file