Skip to content

Commit

Permalink
fix(resolver-ui) - Moved namespaces,files; renamed classes,interfaces…
Browse files Browse the repository at this point in the history
…, created MVVM model for ResolverUI
  • Loading branch information
lilla28 committed Jun 17, 2024
1 parent cb5ce55 commit 5cd8e8d
Show file tree
Hide file tree
Showing 29 changed files with 367 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using Finos.Fdc3;
using AppMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppMetadata;
using AppIntent = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.AppIntent;

namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts;

Expand All @@ -34,7 +33,7 @@ internal sealed class RaiseIntentResponse
public string? Intent { get; set; }

/// <summary>
/// Apps that could handle the raiseIntent.
/// App that can handle the raiseIntent.
/// </summary>
public AppMetadata? AppMetadata { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts;
/// <summary>
/// Request for the ResolverUI to get the response from the user.
/// </summary>
public class ResolverUiRequest
public class ResolverUIRequest
{
/// <summary>
/// Possible list of AppMetadata that can resolve the raised intent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts;
/// <summary>
/// Response from the service which provides the ResolverUI's functionality.
/// </summary>
public class ResolverUiResponse
public class ResolverUIResponse
{
/// <summary>
/// The chosen app to send the raised intent to handle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Fdc3DesktopAgentBuilder UseMessageRouter(
builder.ServiceCollection.Configure<Fdc3DesktopAgentOptions>(configureOptions);

Check warning on line 29 in src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/DependencyInjection/Fdc3DesktopAgentBuilderExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/DependencyInjection/Fdc3DesktopAgentBuilderExtensions.cs#L29

Added line #L29 was not covered by tests
}

builder.ServiceCollection.AddSingleton<IResolverUiCommunicator, ResolverUiMessageRouterCommunicator>();
builder.ServiceCollection.AddSingleton<IResolverUICommunicator, ResolverUiMessageRouterCommunicator>();
builder.ServiceCollection.AddHostedService<Fdc3DesktopAgentMessageRouterService>();

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent;
internal class Fdc3DesktopAgent : IFdc3DesktopAgentBridge
{
private readonly ILogger<Fdc3DesktopAgent> _logger;
private readonly IResolverUiCommunicator _resolverUi;
private readonly IResolverUICommunicator _resolverUI;
private readonly List<UserChannel> _userChannels = new();
private readonly ILoggerFactory _loggerFactory;
private readonly Fdc3DesktopAgentOptions _options;
Expand All @@ -53,13 +53,13 @@ public Fdc3DesktopAgent(
IAppDirectory appDirectory,
IModuleLoader moduleLoader,
IOptions<Fdc3DesktopAgentOptions> options,
IResolverUiCommunicator resolverUi,
IResolverUICommunicator resolverUI,
ILoggerFactory? loggerFactory = null)
{
_appDirectory = appDirectory;
_moduleLoader = moduleLoader;
_options = options.Value;
_resolverUi = resolverUi;
_resolverUI = resolverUI;
_loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
_logger = _loggerFactory.CreateLogger<Fdc3DesktopAgent>() ?? NullLogger<Fdc3DesktopAgent>.Instance;
}
Expand Down Expand Up @@ -426,13 +426,13 @@ public async ValueTask<RaiseIntentResult<RaiseIntentResponse>> RaiseIntent(Raise
};
}

private async Task<ResolverUiResponse?> WaitForResolverUiAsync(IEnumerable<AppMetadata> apps)
private async Task<ResolverUIResponse?> WaitForResolverUiAsync(IEnumerable<AppMetadata> apps)
{
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(2));

try
{
return await _resolverUi.SendResolverUiRequest(apps, cancellationTokenSource.Token);
return await _resolverUI.SendResolverUIRequest(apps, cancellationTokenSource.Token);
}
catch(TimeoutException exception)

Check warning on line 437 in src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs

View check run for this annotation

Codecov / codecov/patch

src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs#L437

Added line #L437 was not covered by tests
{
Expand All @@ -441,7 +441,7 @@ public async ValueTask<RaiseIntentResult<RaiseIntentResponse>> RaiseIntent(Raise
_logger.LogDebug(exception, "MessageRouter didn't receive response from the ResolverUi.");

Check warning on line 441 in src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs

View check run for this annotation

Codecov / codecov/patch

src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs#L441

Added line #L441 was not covered by tests
}

return new ResolverUiResponse()
return new ResolverUIResponse()

Check warning on line 444 in src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs

View check run for this annotation

Codecov / codecov/patch

src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs#L444

Added line #L444 was not covered by tests
{
Error = ResolveError.ResolverTimeout
};

Check warning on line 447 in src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs

View check run for this annotation

Codecov / codecov/patch

src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs#L446-L447

Added lines #L446 - L447 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent;

public interface IResolverUiCommunicator
public interface IResolverUICommunicator
{
/// <summary>
/// Sends a request for the shell to show a window, aka ResolverUI, with the appropriate AppMetadata that can solve the raised intent.
/// </summary>
/// <param name="appMetadata"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<ResolverUiResponse?> SendResolverUiRequest(IEnumerable<IAppMetadata> appMetadata, CancellationToken cancellationToken = default);
public Task<ResolverUIResponse?> SendResolverUIRequest(IEnumerable<IAppMetadata> appMetadata, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal;

internal class ResolverUiMessageRouterCommunicator : IResolverUiCommunicator
internal class ResolverUiMessageRouterCommunicator : IResolverUICommunicator
{
private readonly IMessageRouter _messageRouter;
private readonly JsonSerializerOptions _jsonMessageSerializerOptions = new()
Expand All @@ -39,9 +39,9 @@ public ResolverUiMessageRouterCommunicator(
_logger = logger ?? NullLogger<ResolverUiMessageRouterCommunicator>.Instance;
}

public async Task<ResolverUiResponse?> SendResolverUiRequest(IEnumerable<IAppMetadata> appMetadata, CancellationToken cancellationToken = default)
public async Task<ResolverUIResponse?> SendResolverUIRequest(IEnumerable<IAppMetadata> appMetadata, CancellationToken cancellationToken = default)
{
var request = new ResolverUiRequest
var request = new ResolverUIRequest
{
AppMetadata = appMetadata
};
Expand All @@ -56,7 +56,7 @@ public ResolverUiMessageRouterCommunicator(
return null;
}

var response = responseBuffer.ReadJson<ResolverUiResponse>(_jsonMessageSerializerOptions);
var response = responseBuffer.ReadJson<ResolverUIResponse>(_jsonMessageSerializerOptions);

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public class Fdc3DesktopAgentTests : IAsyncLifetime

private readonly IFdc3DesktopAgentBridge _fdc3;
private readonly MockModuleLoader _mockModuleLoader = new();
private readonly Mock<IResolverUiCommunicator> _mockResolverUiCommunicator = new();
private readonly Mock<IResolverUICommunicator> _mockResolverUICommunicator = new();

public Fdc3DesktopAgentTests()
{
_fdc3 = new Fdc3DesktopAgent(
_appDirectory,
_mockModuleLoader.Object,
new Fdc3DesktopAgentOptions(),
_mockResolverUiCommunicator.Object,
_mockResolverUICommunicator.Object,
NullLoggerFactory.Instance);
}

Expand Down Expand Up @@ -496,7 +496,7 @@ public async Task RaiseIntent_calls_ResolverUi()
};

var result = await _fdc3.RaiseIntent(request);
_mockResolverUiCommunicator.Verify(_ => _.SendResolverUiRequest(It.IsAny<IEnumerable<IAppMetadata>>(), It.IsAny<CancellationToken>()));
_mockResolverUICommunicator.Verify(_ => _.SendResolverUIRequest(It.IsAny<IEnumerable<IAppMetadata>>(), It.IsAny<CancellationToken>()));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Fdc3DesktopAgentMessageRouterServiceTests : IAsyncLifetime

private readonly Fdc3DesktopAgentMessageRouterService _fdc3;
private readonly Mock<IMessageRouter> _mockMessageRouter = new();
private readonly Mock<IResolverUiCommunicator> _mockResolverUiCommunicator = new();
private readonly Mock<IResolverUICommunicator> _mockResolverUICommunicator = new();
private readonly MockModuleLoader _mockModuleLoader = new();

public Fdc3DesktopAgentMessageRouterServiceTests()
Expand All @@ -54,7 +54,7 @@ public Fdc3DesktopAgentMessageRouterServiceTests()
_appDirectory,
_mockModuleLoader.Object,
new Fdc3DesktopAgentOptions(),
_mockResolverUiCommunicator.Object,
_mockResolverUICommunicator.Object,
NullLoggerFactory.Instance),
new Fdc3DesktopAgentOptions(),
NullLoggerFactory.Instance);
Expand Down Expand Up @@ -237,7 +237,7 @@ public async Task RaiseIntent_calls_ResolverUi_by_Context_filter()
};

var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext());
_mockResolverUiCommunicator.Verify(_ => _.SendResolverUiRequest(It.IsAny<IEnumerable<IAppMetadata>>(), It.IsAny<CancellationToken>()));
_mockResolverUICommunicator.Verify(_ => _.SendResolverUIRequest(It.IsAny<IEnumerable<IAppMetadata>>(), It.IsAny<CancellationToken>()));
}

[Fact]
Expand All @@ -254,7 +254,7 @@ public async Task RaiseIntent_calls_ResolverUi_by_Context_filter_if_fdc3_nothing
};

var result = await _fdc3.HandleRaiseIntent(raiseIntentRequest, new MessageContext());
_mockResolverUiCommunicator.Verify(_ => _.SendResolverUiRequest(It.IsAny<IEnumerable<IAppMetadata>>(), It.IsAny<CancellationToken>()));
_mockResolverUICommunicator.Verify(_ => _.SendResolverUIRequest(It.IsAny<IEnumerable<IAppMetadata>>(), It.IsAny<CancellationToken>()));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ResolverUiMessageRouterCommunicatorTests
};

[Fact]
public async Task SendResolverUiRequest_will_return_null()
public async Task SendResolverUIRequest_will_return_null()
{
var messageRouterMock = new Mock<IMessageRouter>();
messageRouterMock.Setup(
Expand All @@ -40,15 +40,15 @@ public async Task SendResolverUiRequest_will_return_null()
It.IsAny<CancellationToken>()))
.Returns(null);

var resolverUiMessageRouterCommunicator = new ResolverUiMessageRouterCommunicator(messageRouterMock.Object);
var resolverUIMessageRouterCommunicator = new ResolverUiMessageRouterCommunicator(messageRouterMock.Object);

var response = await resolverUiMessageRouterCommunicator.SendResolverUiRequest(It.IsAny<IEnumerable<IAppMetadata>>());
var response = await resolverUIMessageRouterCommunicator.SendResolverUIRequest(It.IsAny<IEnumerable<IAppMetadata>>());

response.Should().BeNull();
}

[Fact]
public async Task SendResolverUiRequest_will_return_response()
public async Task SendResolverUIRequest_will_return_response()
{
var messageRouterMock = new Mock<IMessageRouter>();
messageRouterMock.Setup(
Expand All @@ -58,14 +58,14 @@ public async Task SendResolverUiRequest_will_return_response()
It.IsAny<InvokeOptions>(),
It.IsAny<CancellationToken>()))
.Returns(ValueTask.FromResult<MessageBuffer?>(
MessageBuffer.Factory.CreateJson(new ResolverUiResponse()
MessageBuffer.Factory.CreateJson(new ResolverUIResponse()
{
AppMetadata = new AppMetadata(){ AppId = "testAppId" }
}, _jsonSerializerOptions)));

var resolverUiMessageRouterCommunicator = new ResolverUiMessageRouterCommunicator(messageRouterMock.Object);
var resolverUIMessageRouterCommunicator = new ResolverUiMessageRouterCommunicator(messageRouterMock.Object);

var response = await resolverUiMessageRouterCommunicator.SendResolverUiRequest(It.IsAny<IEnumerable<IAppMetadata>>());
var response = await resolverUIMessageRouterCommunicator.SendResolverUIRequest(It.IsAny<IEnumerable<IAppMetadata>>());

response.Should().NotBeNull();
response!.AppMetadata.Should().NotBeNull();
Expand Down
9 changes: 4 additions & 5 deletions src/shell/dotnet/Shell/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MorganStanley.ComposeUI.Fdc3.AppDirectory;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;
using MorganStanley.ComposeUI.Messaging;
using MorganStanley.ComposeUI.ModuleLoader;
using MorganStanley.ComposeUI.Shell.Abstractions;
using MorganStanley.ComposeUI.Shell.Fdc3;
using MorganStanley.ComposeUI.Shell.Fdc3.ResolverUi;
using MorganStanley.ComposeUI.Shell.Fdc3.ResolverUI;
using MorganStanley.ComposeUI.Shell.Messaging;
using MorganStanley.ComposeUI.Shell.Modules;
using MorganStanley.ComposeUI.Shell.Utilities;
Expand Down Expand Up @@ -200,9 +199,9 @@ void ConfigureFdc3()
{
services.AddFdc3DesktopAgent(desktopAgent => desktopAgent.UseMessageRouter());

Check warning on line 200 in src/shell/dotnet/Shell/App.xaml.cs

View check run for this annotation

Codecov / codecov/patch

src/shell/dotnet/Shell/App.xaml.cs#L200

Added line #L200 was not covered by tests
services.AddFdc3AppDirectory();
services.AddSingleton<Fdc3ResolverUiWindowWpf>();
services.AddSingleton<IResolverUiWindow>(p => p.GetRequiredService<Fdc3ResolverUiWindowWpf>());
services.AddHostedService<Fdc3ResolverUiService>();
services.AddSingleton<Fdc3ResolverUIWindow>();
services.AddSingleton<IResolverUIProjector>(p => p.GetRequiredService<Fdc3ResolverUIWindow>());
services.AddHostedService<Fdc3ResolverUIService>();

Check warning on line 204 in src/shell/dotnet/Shell/App.xaml.cs

View check run for this annotation

Codecov / codecov/patch

src/shell/dotnet/Shell/App.xaml.cs#L202-L204

Added lines #L202 - L204 were not covered by tests
services.Configure<Fdc3Options>(fdc3ConfigurationSection);
services.Configure<Fdc3DesktopAgentOptions>(
fdc3ConfigurationSection.GetSection(nameof(fdc3Options.DesktopAgent)));
Expand Down
Loading

0 comments on commit 5cd8e8d

Please sign in to comment.