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(); }
public async Task Invalid_Return_RawStreaming_NonTask() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using System.Threading.Tasks; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { ClientStreamingResult<string, string> ClientStreamingAsync(); ServerStreamingResult<string> ServerStreamingAsync(); DuplexStreamingResult<string, string> DuplexStreamingAsync(); } } "); var compiler = new MagicOnionCompiler(_testOutputHelper.WriteLine, CancellationToken.None); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await compiler.GenerateFileAsync( tempWorkspace.CsProjectPath, Path.Combine(tempWorkspace.OutputDirectory, "Generated.cs"), true, "TempProject.Generated", "", "MessagePack.Formatters" ); }); }
public async Task Return_TaskOfUnaryResultOfT() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using System.Threading.Tasks; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { Task<UnaryResult<int>> A(); } } "); 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.GetCompilationErrors().Should().BeEmpty(); }
public async Task Return_Nested_Enum() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<MyGenericObject<MyGenericObject<MyEnum>>> GetEnumAsync(); } public enum MyEnum { A, B, C } [MessagePackObject] public class MyGenericObject<T> { } } // Pseudo generated MessagePackFormatter using mpc (MessagePack.Generator) namespace MessagePack.Formatters.TempProject { public class MyGenericObjectFormatter<T> : MessagePack.Formatters.IMessagePackFormatter<global::TempProject.MyGenericObject<T>> { public void Serialize(ref MessagePackWriter writer, global::TempProject.MyGenericObject<T> value, MessagePackSerializerOptions options) => throw new NotImplementedException(); public global::TempProject.MyGenericObject<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) => throw new NotImplementedException(); } } "); 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.GetCompilationErrors().Should().BeEmpty(); var symbols = compilation.GetNamedTypeSymbolsFromGenerated(); symbols.Should().Contain(x => x.Name.EndsWith("MyEnumFormatter")); compilation.GetResolverKnownFormatterTypes().Should().Contain(new[] { "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyEnum>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyGenericObject<global::TempProject.MyEnum>>", }); }
public async Task GenerateEnumFormatter_Parameter() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<Nil> GetEnumAsync(MyEnum a); } public enum MyEnum { A, B, C } } "); var compiler = new MagicOnionCompiler(_testOutputHelper.WriteLine, CancellationToken.None); await compiler.GenerateFileAsync(tempWorkspace.CsProjectPath, tempWorkspace.OutputDirectory, true, "TempProject.Generated", ""); var compilation = tempWorkspace.GetOutputCompilation(); var symbols = compilation.GetNamedTypeSymbolsFromGenerated(); symbols.Should().Contain(x => x.Name.EndsWith("MyEnumFormatter")); }
public async Task Return_MultipleTypeArgs() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<MyGenericObject<int, MyObject>> A(); UnaryResult<MyGenericObject<MyObject, int>> B(); } [MessagePackObject] public class MyObject { } [MessagePackObject] public class MyGenericObject<T1, T2> { } } // Pseudo generated MessagePackFormatter using mpc (MessagePack.Generator) namespace MessagePack.Formatters.TempProject { public class MyGenericObjectFormatter<T1, T2> : MessagePack.Formatters.IMessagePackFormatter<global::TempProject.MyGenericObject<T1, T2>> { public void Serialize(ref MessagePackWriter writer, global::TempProject.MyGenericObject<T1, T2> value, MessagePackSerializerOptions options) => throw new NotImplementedException(); public global::TempProject.MyGenericObject<T1, T2> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) => throw new NotImplementedException(); } } "); 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.GetCompilationErrors().Should().BeEmpty(); compilation.GetResolverKnownFormatterTypes().Should().Contain(new[] { "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<int, global::TempProject.MyObject>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyObject, int>", }); }
public async Task Parameters_Nested() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<Nil> A(MyGenericObject<MyGenericObject<MyObject>> a); UnaryResult<Nil> B(MyGenericObject<MyGenericObject<MyGenericObject<MyObject>>> a); UnaryResult<Nil> B(MyGenericObject<MyGenericObject<MyGenericObject<int>>> a); } [MessagePackObject] public class MyObject { } [MessagePackObject] public class MyGenericObject<T> { } } "); 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.GetResolverKnownFormatterTypes().Should().Contain(new[] { "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyGenericObject<global::TempProject.MyObject>>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyGenericObject<global::TempProject.MyGenericObject<global::TempProject.MyObject>>>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyGenericObject<global::TempProject.MyGenericObject<int>>>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<int>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyObject>", }); }
public async Task Return_Nested_Enum() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<MyGenericObject<MyGenericObject<MyEnum>>> GetEnumAsync(); } public enum MyEnum { A, B, C } [MessagePackObject] public class MyGenericObject<T> { } } "); 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(); var symbols = compilation.GetNamedTypeSymbolsFromGenerated(); symbols.Should().Contain(x => x.Name.EndsWith("MyEnumFormatter")); compilation.GetResolverKnownFormatterTypes().Should().Contain(new[] { "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyEnum>", "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyGenericObject<global::TempProject.MyEnum>>", }); }
public async Task Parameters_Nested_Array() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using System.Threading.Tasks; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<Nil> GetValuesAsync(MyGenericObject<MyNestedGenericObject[]> arg0); } public class MyGenericObject<T> { } public class MyNestedGenericObject { } } "); var compiler = new MagicOnionCompiler(_testOutputHelper.WriteLine, CancellationToken.None); await compiler.GenerateFileAsync( tempWorkspace.CsProjectPath, tempWorkspace.OutputDirectory, true, "TempProject.Generated", "", "MessagePack.Formatters" ); var compilation = tempWorkspace.GetOutputCompilation(); var symbols = compilation.GetNamedTypeSymbolsFromGenerated(); compilation.GetResolverKnownFormatterTypes().Should().Contain(new[] { "global::MessagePack.Formatters.TempProject.MyGenericObjectFormatter<global::TempProject.MyNestedGenericObject[]>", "global::MessagePack.Formatters.ArrayFormatter<global::TempProject.MyNestedGenericObject>" }); }
public async Task Return_ListFormatter_UserType() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using System.Collections.Generic; using System.Threading.Tasks; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<List<MyResponse>> GetValuesAsync(); } public class MyResponse { } } "); var compiler = new MagicOnionCompiler(_testOutputHelper.WriteLine, CancellationToken.None); await compiler.GenerateFileAsync( tempWorkspace.CsProjectPath, tempWorkspace.OutputDirectory, true, "TempProject.Generated", "", "MessagePack.Formatters" ); var compilation = tempWorkspace.GetOutputCompilation(); compilation.GetCompilationErrors().Should().BeEmpty(); var symbols = compilation.GetNamedTypeSymbolsFromGenerated(); compilation.GetResolverKnownFormatterTypes().Should().Contain(new[] { "global::MessagePack.Formatters.ListFormatter<global::TempProject.MyResponse>", }); }
public async Task HubReceiver_1() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using System.Threading.Tasks; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyHubReceiver { void OnMessage(MyObject a); } public interface IMyHub : IStreamingHub<IMyHub, IMyHubReceiver> { Task A(MyObject a); } [MessagePackObject] public class MyObject { } } "); 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.GetCompilationErrors().Should().BeEmpty(); }
public async Task Return_ArrayFormatter_KnownType() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using System.Threading.Tasks; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<string[]> GetStringValuesAsync(); UnaryResult<int[]> GetIntValuesAsync(); UnaryResult<Int32[]> GetInt32ValuesAsync(); UnaryResult<float[]> GetSingleValuesAsync(); UnaryResult<bool[]> GetBooleanValuesAsync(); } } "); var compiler = new MagicOnionCompiler(_testOutputHelper.WriteLine, CancellationToken.None); await compiler.GenerateFileAsync( tempWorkspace.CsProjectPath, tempWorkspace.OutputDirectory, true, "TempProject.Generated", "", "MessagePack.Formatters" ); var compilation = tempWorkspace.GetOutputCompilation(); compilation.GetCompilationErrors().Should().BeEmpty(); var symbols = compilation.GetNamedTypeSymbolsFromGenerated(); compilation.GetResolverKnownFormatterTypes().Should().BeEmpty(); }