Skip to content

Commit 5208553

Browse files
committed
feat(fdc3) - Implement GetInfo to FDC3 .NET client
1 parent 1d45031 commit 5208553

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed

src/fdc3/dotnet/DesktopAgent.Client/src/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client/Infrastructure/DesktopAgentClient.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,29 @@ public async Task<IAppMetadata> GetAppMetadata(IAppIdentifier app)
113113
throw new NotImplementedException();
114114
}
115115

116-
public Task<IImplementationMetadata> GetInfo()
116+
public async Task<IImplementationMetadata> GetInfo()
117117
{
118-
throw new NotImplementedException();
118+
var request = new GetInfoRequest
119+
{
120+
AppIdentifier = new Shared.Protocol.AppIdentifier
121+
{
122+
AppId = _appId,
123+
InstanceId = _instanceId
124+
}
125+
};
126+
127+
var response = await _messaging.InvokeJsonServiceAsync<GetInfoRequest, GetInfoResponse>(
128+
Fdc3Topic.GetInfo,
129+
request,
130+
_jsonSerializerOptions) ?? throw new Fdc3DesktopAgentException($"FDC3 client can't return the information about the initiator app; AppID: {_appId}; InstanceID: {_instanceId}.");
131+
132+
if (response.Error != null)
133+
{
134+
_logger.LogError($"{_appId} cannot return the {nameof(ImplementationMetadata)} due to: {response.Error}.");
135+
throw new Fdc3DesktopAgentException($"{_appId} cannot return the {nameof(ImplementationMetadata)} due to: {response.Error}.");
136+
}
137+
138+
return response.ImplementationMetadata!;
119139
}
120140

121141
public Task<IChannel> GetOrCreateChannel(string channelId)

src/fdc3/dotnet/DesktopAgent.Client/test/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests/EndToEndTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using FluentAssertions;
77
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Shared;
88
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Shared.Exceptions;
9+
using Castle.DynamicProxy.Generators;
10+
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Infrastructure;
11+
using MorganStanley.ComposeUI.Messaging.Abstractions;
912

1013
namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests;
1114

@@ -131,4 +134,28 @@ public async Task GetAppMetadata_returns_AppMetadata()
131134
result.Should().NotBeNull();
132135
result.Should().BeEquivalentTo(TestAppDirectoryData.DefaultApp1);
133136
}
137+
138+
[Fact]
139+
public async Task GetInfo_returns_ImplementationMetadata()
140+
{
141+
var result = await _desktopAgent.GetInfo();
142+
result.Should().NotBeNull();
143+
result.AppMetadata.Should().NotBeNull();
144+
result.AppMetadata.AppId.Should().Be("appId1");
145+
}
146+
147+
[Fact]
148+
public async Task GetInfo_throws_error_as_instance_id_not_found()
149+
{
150+
Environment.SetEnvironmentVariable(nameof(AppIdentifier.AppId), "nonExistentAppId");
151+
Environment.SetEnvironmentVariable(nameof(AppIdentifier.InstanceId), Guid.NewGuid().ToString());
152+
153+
var desktopAgent = new DesktopAgentClient(_clientServices.GetRequiredService<IMessaging>());
154+
155+
var action = async() => await desktopAgent.GetInfo();
156+
157+
await action.Should()
158+
.ThrowAsync<Fdc3DesktopAgentException>()
159+
.WithMessage($"*{Fdc3DesktopAgentErrors.MissingId}*");
160+
}
134161
}

src/fdc3/dotnet/DesktopAgent.Client/test/MorganStanley.ComposeUI.Fdc3.DesktopAgent.Client.Tests/Infrastructure/DesktopAgentClient.Tests.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,67 @@ public async Task GetAppMetadata_returns_AppIdentifier()
8585
result!.Should().BeEquivalentTo(new AppMetadata {AppId = "test-appId"});
8686
}
8787

88+
[Fact]
89+
public async Task GetInfo_throws_error_as_no_response_received()
90+
{
91+
var messagingMock = new Mock<IMessaging>();
92+
93+
messagingMock.Setup(
94+
_ => _.InvokeServiceAsync(
95+
It.IsAny<string>(),
96+
It.IsAny<string>(),
97+
It.IsAny<CancellationToken>()))
98+
.Returns(null);
99+
100+
var desktopAgent = new DesktopAgentClient(messagingMock.Object);
101+
102+
var action = async () => await desktopAgent.GetInfo();
103+
104+
await action.Should().ThrowAsync<Fdc3DesktopAgentException>()
105+
.WithMessage("*can't return the information about the initiator app*");
106+
}
107+
108+
[Fact]
109+
public async Task GetInfo_throws_error_as_error_response_received()
110+
{
111+
var messagingMock = new Mock<IMessaging>();
112+
113+
messagingMock.Setup(
114+
_ => _.InvokeServiceAsync(
115+
It.IsAny<string>(),
116+
It.IsAny<string>(),
117+
It.IsAny<CancellationToken>()))
118+
.Returns(new ValueTask<string?>(JsonSerializer.Serialize(new GetInfoResponse { Error = "test-error" })));
119+
120+
var desktopAgent = new DesktopAgentClient(messagingMock.Object);
121+
122+
var action = async () => await desktopAgent.GetInfo();
123+
124+
await action.Should().ThrowAsync<Fdc3DesktopAgentException>()
125+
.WithMessage("*test-error*");
126+
}
127+
128+
[Fact]
129+
public async Task GetInfo_returns_ImplementationMetadata()
130+
{
131+
var messagingMock = new Mock<IMessaging>();
132+
var implementationMetadata = new ImplementationMetadata {AppMetadata = new AppMetadata {AppId = "test_appId"}};
133+
134+
messagingMock.Setup(
135+
_ => _.InvokeServiceAsync(
136+
It.IsAny<string>(),
137+
It.IsAny<string>(),
138+
It.IsAny<CancellationToken>()))
139+
.Returns(new ValueTask<string?>(JsonSerializer.Serialize(new GetInfoResponse { ImplementationMetadata = implementationMetadata })));
140+
141+
var desktopAgent = new DesktopAgentClient(messagingMock.Object);
142+
143+
var result = await desktopAgent.GetInfo();
144+
145+
result.Should().NotBeNull();
146+
result.Should().BeEquivalentTo(implementationMetadata);
147+
}
148+
88149
public Task InitializeAsync()
89150
{
90151
Environment.SetEnvironmentVariable(nameof(AppIdentifier.AppId), "test-appId2");

0 commit comments

Comments
 (0)