Skip to content

Commit

Permalink
Add test for more complex internal type references in generated proxy
Browse files Browse the repository at this point in the history
This repros microsoft#789
  • Loading branch information
AArnott committed Jun 10, 2022
1 parent c3a4664 commit af40eb6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace StreamJsonRpc.Tests.ExternalAssembly
{
using System.Threading.Tasks;

internal interface IInternalGenericInterface<TOptions>
{
Task<TOptions> GetOptionsAsync(InternalStruct id, CancellationToken cancellationToken);
}
}
9 changes: 9 additions & 0 deletions test/StreamJsonRpc.Tests.ExternalAssembly/InternalStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace StreamJsonRpc.Tests.ExternalAssembly
{
internal struct InternalStruct
{
}
}
34 changes: 25 additions & 9 deletions test/StreamJsonRpc.Tests/JsonRpcProxyGenerationTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft;
using Microsoft.VisualStudio.Threading;
using Nerdbank;
using StreamJsonRpc;
using Xunit;
using Xunit.Abstractions;
using ExAssembly = StreamJsonRpc.Tests.ExternalAssembly;

public class JsonRpcProxyGenerationTests : TestBase
{
Expand Down Expand Up @@ -137,14 +134,27 @@ public interface IServerWithGenericMethod
Task AddAsync<T>(T a, T b);
}

internal interface IServerInternal : StreamJsonRpc.Tests.ExternalAssembly.ISomeInternalProxyInterface, IServerInternalWithInternalTypesFromOtherAssemblies
internal interface IServerInternal : ExAssembly.ISomeInternalProxyInterface, IServerInternalWithInternalTypesFromOtherAssemblies
{
Task<int> AddAsync(int a, int b);
}

internal interface IServerInternalWithInternalTypesFromOtherAssemblies
{
Task<StreamJsonRpc.Tests.ExternalAssembly.SomeOtherInternalType> SomeMethodAsync();
Task<ExAssembly.SomeOtherInternalType> SomeMethodAsync();
}

internal interface IRemoteService
{
internal interface ICallback : ExAssembly.IInternalGenericInterface<ExAssembly.SomeOtherInternalType?>
{
}
}

[Fact]
public void Tomas_Internal()
{
JsonRpc.Attach<IRemoteService.ICallback>(new MemoryStream());
}

[Fact]
Expand Down Expand Up @@ -428,7 +438,7 @@ public async Task InternalInterface()
var clientRpc = JsonRpc.Attach(streams.Item1);

// Try the first internal interface, which is external to this test assembly
var proxy1 = clientRpc.Attach<StreamJsonRpc.Tests.ExternalAssembly.ISomeInternalProxyInterface>();
var proxy1 = clientRpc.Attach<ExAssembly.ISomeInternalProxyInterface>();
Assert.Equal(-1, await proxy1.SubtractAsync(1, 2).WithCancellation(this.TimeoutToken));

// Now create a proxy for another interface that is internal within this assembly, but derives from the external assembly's internal interface.
Expand Down Expand Up @@ -815,11 +825,17 @@ internal class ServerOfInternalInterface : IServerInternal
{
public Task<int> AddAsync(int a, int b) => Task.FromResult(a + b);

public Task<StreamJsonRpc.Tests.ExternalAssembly.SomeOtherInternalType> SomeMethodAsync()
public Task<ExAssembly.SomeOtherInternalType> SomeMethodAsync()
{
return Task.FromResult(new StreamJsonRpc.Tests.ExternalAssembly.SomeOtherInternalType());
return Task.FromResult(new ExAssembly.SomeOtherInternalType());
}

public Task<int> SubtractAsync(int a, int b) => Task.FromResult(a - b);
}

internal class Callback : IRemoteService.ICallback
{
public Task<ExAssembly.SomeOtherInternalType?> GetOptionsAsync(ExAssembly.InternalStruct id, CancellationToken cancellationToken)
=> Task.FromResult<ExAssembly.SomeOtherInternalType?>(null);
}
}

0 comments on commit af40eb6

Please sign in to comment.