public async Task Return_Nested() { 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<MyObject>>> A(); UnaryResult<MyGenericObject<MyGenericObject<MyGenericObject<MyObject>>>> B(); UnaryResult<MyGenericObject<MyGenericObject<MyGenericObject<int>>>> B(); } [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 Parameters_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<Nil> GetEnumAsync(MyGenericObject<MyGenericObject<MyEnum>> arg0); } 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 GenerateEnumFormatter_Return_Nullable() { using var tempWorkspace = TemporaryProjectWorkarea.Create(); tempWorkspace.AddFileToProject("IMyService.cs", @" using System; using MessagePack; using MagicOnion; namespace TempProject { public interface IMyService : IService<IMyService> { UnaryResult<MyEnum?> GetEnumAsync(); } public enum MyEnum { A, B, C } } "); 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(); symbols.Should().Contain(x => x.Name.EndsWith("MyEnumFormatter")); }
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(); }
public async Task Return_Nested() { 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<MyObject>>> A(); UnaryResult<MyGenericObject<MyGenericObject<MyGenericObject<MyObject>>>> B(); UnaryResult<MyGenericObject<MyGenericObject<MyGenericObject<int>>>> C(); } [MessagePackObject] public class MyObject { } [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(); 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>", }); }