-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix visibility checks when generating proxies based on internal interfaces #804
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/StreamJsonRpc.Tests.ExternalAssembly/IInternalGenericInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to update the test name to describe the scenario better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't my name self-explanatory? ;) |
||
{ | ||
JsonRpc.Attach<IRemoteService.ICallback>(new MemoryStream()); | ||
} | ||
|
||
[Fact] | ||
|
@@ -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. | ||
|
@@ -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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to recurse into interfaces implemented by these base types or do we only care about the interfaces declared directly by the original starting point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I copied this code from another place in the library without thinking. This code will never be hit because proxies are always based on interfaces, not classes. I'll delete.