Skip to content

Commit

Permalink
Add test for IAsyncEnumerable<T> in MessagePack with a [Union] type
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Sep 2, 2020
1 parent 2d4cac7 commit d9171bf
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/StreamJsonRpc.Tests/JsonRpcMessagePackLengthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using MessagePack;
using MessagePack.Formatters;
using MessagePack.Resolvers;
using Microsoft;
using Microsoft.VisualStudio.Threading;
using StreamJsonRpc;
using StreamJsonRpc.Protocol;
Expand All @@ -33,6 +33,8 @@ internal interface IMessagePackServer
Task AcceptUnionTypeAsync(UnionBaseClass value, CancellationToken cancellationToken);

Task ProgressUnionType(IProgress<UnionBaseClass> progress, CancellationToken cancellationToken);

IAsyncEnumerable<UnionBaseClass> GetAsyncEnumerableOfUnionType(CancellationToken cancellationToken);
}

[Fact]
Expand Down Expand Up @@ -350,6 +352,23 @@ public async Task UnionType_AsIProgressTypeArgument()
Assert.IsType<UnionDerivedClass>(await reportSource.Task.WithCancellation(this.TimeoutToken));
}

[Fact]
public async Task UnionType_AsAsyncEnumerableTypeArgument()
{
var server = new MessagePackServer();
this.serverRpc.AllowModificationWhileListening = true;
this.serverRpc.AddLocalRpcTarget(server);
var clientProxy = this.clientRpc.Attach<IMessagePackServer>();

UnionBaseClass? actualItem = null;
await foreach (UnionBaseClass item in clientProxy.GetAsyncEnumerableOfUnionType(this.TimeoutToken))
{
actualItem = item;
}

Assert.IsType<UnionDerivedClass>(actualItem);
}

protected override void InitializeFormattersAndHandlers(bool controlledFlushingClient)
{
this.serverMessageFormatter = new MessagePackFormatter();
Expand Down Expand Up @@ -429,6 +448,12 @@ public Task ProgressUnionType(IProgress<UnionBaseClass> progress, CancellationTo
progress.Report(new UnionDerivedClass());
return Task.CompletedTask;
}

public async IAsyncEnumerable<UnionBaseClass> GetAsyncEnumerableOfUnionType([EnumeratorCancellation] CancellationToken cancellationToken)
{
await Task.Yield();
yield return new UnionDerivedClass();
}
}

private class DelayedFlushingHandler : LengthHeaderMessageHandler, IControlledFlushHandler
Expand Down

0 comments on commit d9171bf

Please sign in to comment.