Skip to content

Commit

Permalink
Merge pull request #406 from Cysharp/hotfix/GenerateRawStreamingResult
Browse files Browse the repository at this point in the history
Fix accessibility of MarshallingAsyncStreamReaderWriter
  • Loading branch information
mayuki authored Feb 3, 2021
2 parents 94379b7 + 69feeb2 commit dfae274
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MagicOnion
{
internal class MarshallingAsyncStreamReader<T> : IAsyncStreamReader<T>, IDisposable
public class MarshallingAsyncStreamReader<T> : IAsyncStreamReader<T>, IDisposable
{
readonly IAsyncStreamReader<byte[]> inner;
readonly MessagePackSerializerOptions options;
Expand Down Expand Up @@ -41,7 +41,7 @@ public void Dispose()
}
}

internal class MarshallingClientStreamWriter<T> : IClientStreamWriter<T>
public class MarshallingClientStreamWriter<T> : IClientStreamWriter<T>
{
readonly IClientStreamWriter<byte[]> inner;
readonly MessagePackSerializerOptions options;
Expand Down
4 changes: 2 additions & 2 deletions src/MagicOnion.Client/MarshallingAsyncStreamReaderWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MagicOnion
{
internal class MarshallingAsyncStreamReader<T> : IAsyncStreamReader<T>, IDisposable
public class MarshallingAsyncStreamReader<T> : IAsyncStreamReader<T>, IDisposable
{
readonly IAsyncStreamReader<byte[]> inner;
readonly MessagePackSerializerOptions options;
Expand Down Expand Up @@ -41,7 +41,7 @@ public void Dispose()
}
}

internal class MarshallingClientStreamWriter<T> : IClientStreamWriter<T>
public class MarshallingClientStreamWriter<T> : IClientStreamWriter<T>
{
readonly IClientStreamWriter<byte[]> inner;
readonly MessagePackSerializerOptions options;
Expand Down
56 changes: 56 additions & 0 deletions tests/MagicOnion.Generator.Tests/GenerateRawStreamingTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.CodeAnalysis;
using Xunit;
using Xunit.Abstractions;

namespace MagicOnion.Generator.Tests
{
public class GenerateRawStreamingTest
{
private readonly ITestOutputHelper _testOutputHelper;

public GenerateRawStreamingTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

[Fact]
public async Task StreamingResult()
{
using var tempWorkspace = TemporaryProjectWorkarea.Create();
tempWorkspace.AddFileToProject("IMyService.cs", @"
using System;
using MessagePack;
using MagicOnion;
using System.Threading.Tasks;
namespace TempProject
{
public interface IMyService : IService<IMyService>
{
Task<ClientStreamingResult<string, string>> ClientStreamingAsync();
Task<ServerStreamingResult<string>> ServerStreamingAsync();
Task<DuplexStreamingResult<string, string>> DuplexStreamingAsync();
}
}
");

var compiler = new MagicOnionCompiler(_testOutputHelper.WriteLine, CancellationToken.None);
await compiler.GenerateFileAsync(
tempWorkspace.CsProjectPath,
Path.Combine(tempWorkspace.OutputDirectory, "Generated.cs"),
true,
"TempProject.Generated",
"",
"MessagePack.Formatters"
);

var compilation = tempWorkspace.GetOutputCompilation().Compilation;
compilation.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error).Should().BeEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MagicOnion.Client\MagicOnion.Client.csproj" />
<ProjectReference Include="..\..\src\MagicOnion.GeneratorCore\MagicOnion.GeneratorCore.csproj" />
</ItemGroup>

Expand Down
29 changes: 18 additions & 11 deletions tests/MagicOnion.Generator.Tests/TemporaryProjectWorkarea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,24 @@ public OutputCompilation GetOutputCompilation()
Directory.EnumerateFiles(ProjectDirectory, "*.cs", SearchOption.AllDirectories)
.Concat(Directory.EnumerateFiles(OutputDirectory, "*.cs", SearchOption.AllDirectories))
.Select(x => CSharpSyntaxTree.ParseText(File.ReadAllText(x), CSharpParseOptions.Default, x)))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Private.CoreLib.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Runtime.Extensions.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Collections.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Linq.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Console.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Runtime.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Memory.dll")))
.AddReferences(MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "netstandard.dll")))
.AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
//.AddReferences(MetadataReference.CreateFromFile(typeof(MessagePack.MessagePackObjectAttribute).Assembly.Location))
//.AddReferences(MetadataReference.CreateFromFile(typeof(IMessagePackFormatter<>).Assembly.Location))
.AddReferences(
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Private.CoreLib.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Runtime.Extensions.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Collections.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Linq.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Console.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Runtime.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "System.Memory.dll")),
MetadataReference.CreateFromFile(Path.Combine(refAsmDir, "netstandard.dll")),
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),

MetadataReference.CreateFromFile(typeof(Grpc.Core.AsyncUnaryCall<>).Assembly.Location), // Grpc.Core.Api
MetadataReference.CreateFromFile(typeof(MagicOnion.Client.MagicOnionClient).Assembly.Location), // MagicOnion.Client
MetadataReference.CreateFromFile(typeof(MagicOnion.MagicOnionMarshallers).Assembly.Location), // MagicOnion.Shared
MetadataReference.CreateFromFile(typeof(MagicOnion.IService<>).Assembly.Location), // MagicOnion.Abstractions
MetadataReference.CreateFromFile(typeof(MessagePack.IFormatterResolver).Assembly.Location), // MessagePack
MetadataReference.CreateFromFile(typeof(MessagePack.MessagePackObjectAttribute).Assembly.Location) // MessagePack.Annotations
)
.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

return new OutputCompilation(compilation);
Expand Down

0 comments on commit dfae274

Please sign in to comment.