public async Task OneParameterContext() { var call = ChannelType .InstanceMethod(nameof(IContract.OneParameterContext)) .CreateDelegate <Func <IContract, Message <int>, ServerCallContext, Task <Message> > >(Channel); Console.WriteLine(call.Method.Disassemble()); _serverCallContext .Protected() .SetupGet <Metadata>("RequestHeadersCore") .Returns(new Metadata()); _serverCallContext .Protected() .SetupGet <DateTime>("DeadlineCore") .Returns(DateTime.Now); _serverCallContext .Protected() .SetupGet <WriteOptions>("WriteOptionsCore") .Returns(WriteOptions.Default); _service .Setup(s => s.OneParameterContext(It.IsAny <CallOptions>(), 3)) .Callback <CallOptions, int>((options, _) => { options.CancellationToken.ShouldBe(_tokenSource.Token); }); var actual = await call(_service.Object, new Message <int>(3), _serverCallContext.Object).ConfigureAwait(false); actual.ShouldNotBeNull(); _service.VerifyAll(); }
public async Task DuplexStreamingConvert() { var call = ChannelType .InstanceMethod(nameof(IContract.DuplexStreamingConvert)) .CreateDelegate <Func <IContract, Message?, IAsyncEnumerable <int>, ServerCallContext, ValueTask <(Message?, IAsyncEnumerable <string>)> > >(Channel); Console.WriteLine(call.Method.Disassemble()); var input = new[] { 2 }.AsAsyncEnumerable();
public async Task Empty() { var call = ChannelType .InstanceMethod(nameof(IContract.Empty)) .CreateDelegate <Func <IContract, Message, ServerCallContext, Task <Message> > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.Empty()); var actual = await call(_service.Object, new Message(), null !).ConfigureAwait(false); actual.ShouldNotBeNull(); _service.VerifyAll(); }
public async Task UnaryNullableCancellationToken() { var call = ChannelType .InstanceMethod(nameof(IContract.UnaryNullableCancellationToken)) .CreateDelegate <Func <IContract, Message <TimeSpan>, ServerCallContext, Task <Message> > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.UnaryNullableCancellationToken(TimeSpan.FromSeconds(2), _tokenSource.Token)) .Returns(Task.CompletedTask); await call(_service.Object, new Message <TimeSpan>(TimeSpan.FromSeconds(2)), _serverCallContext.Object).ConfigureAwait(false); _service.VerifyAll(); }
public async Task DuplicateUnary2() { var call = ChannelType .InstanceMethod("DuplicateUnary2", typeof(IContract), typeof(Message <string>), typeof(ServerCallContext)) .CreateDelegate <Func <IContract, Message <string>, ServerCallContext, Task <Message <string> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.DuplicateUnary("a")) .Returns("b"); var actual = await call(_service.Object, new Message <string>("a"), null !).ConfigureAwait(false); actual.Value1.ShouldBe("b"); _service.VerifyAll(); }
public async Task ConcatThreeValueAsync() { var call = ChannelType .InstanceMethod(nameof(IContract.ConcatThreeValueAsync)) .CreateDelegate <Func <IContract, Message <int, string, long>, ServerCallContext, Task <Message <string> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.ConcatThreeValueAsync(1, "a", _tokenSource.Token, 3)) .Returns(Task.FromResult("1a3")); var actual = await call(_service.Object, new Message <int, string, long>(1, "a", 3), _serverCallContext.Object).ConfigureAwait(false); actual.Value1.ShouldBe("1a3"); _service.VerifyAll(); }
public async Task AddTwoValues() { var call = ChannelType .InstanceMethod(nameof(IContract.AddTwoValues)) .CreateDelegate <Func <IContract, Message <int, double>, ServerCallContext, Task <Message <double> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.AddTwoValues(1, 3.5)) .Returns(4.5); var actual = await call(_service.Object, new Message <int, double>(1, 3.5), null !).ConfigureAwait(false); actual.Value1.ShouldBe(4.5); _service.VerifyAll(); }
public async Task OneParameterAsync() { var call = ChannelType .InstanceMethod(nameof(IContract.OneParameterAsync)) .CreateDelegate <Func <IContract, Message <double>, ServerCallContext, Task <Message> > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.OneParameterAsync(3.5)) .Returns(Task.CompletedTask); var actual = await call(_service.Object, new Message <double>(3.5), null !).ConfigureAwait(false); actual.ShouldNotBeNull(); _service.VerifyAll(); }
public async Task ReturnValueTaskBoolAsync() { var call = ChannelType .InstanceMethod(nameof(IContract.ReturnValueTaskBoolAsync)) .CreateDelegate <Func <IContract, Message, ServerCallContext, Task <Message <bool> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.ReturnValueTaskBoolAsync()) .Returns(new ValueTask <bool>(Task.FromResult(true))); var actual = await call(_service.Object, new Message(), null !).ConfigureAwait(false); actual.Value1.ShouldBeTrue(); _service.VerifyAll(); }
public async Task Invoke() { var call = ChannelType .InstanceMethod(nameof(IGenericContract <int, string> .Invoke)) .CreateDelegate <Func <IGenericContract <int, string>, Message <int, string>, ServerCallContext, Task <Message <string> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); var serverContext = new Mock <ServerCallContext>(MockBehavior.Strict); _service .Setup(s => s.Invoke(3, "4")) .Returns("34"); var actual = await call(_service.Object, new Message <int, string>(3, "4"), serverContext.Object); actual.Value1.ShouldBe("34"); _service.VerifyAll(); }
public async Task DuplicateServerStreaming2() { var call = ChannelType .InstanceMethod("DuplicateServerStreaming2", typeof(IContract), typeof(Message <string>), typeof(ServerCallContext)) .CreateDelegate <Func <IContract, Message <string>, ServerCallContext, ValueTask <(Message?, IAsyncEnumerable <string>)> > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.DuplicateServerStreaming("b")) .Returns(new[] { "a" }.AsAsyncEnumerable()); var response = await call(_service.Object, new Message <string>("b"), _serverCallContext.Object).ConfigureAwait(false); response.Item1.ShouldBeNull(); var actual = await response.Item2.ToListAsync().ConfigureAwait(false); actual.ShouldBe(new[] { "a" }); _service.VerifyAll(); }
public async Task ServerStreamingRepeatValueValueTaskAsync() { var call = ChannelType .InstanceMethod(nameof(IContract.ServerStreamingRepeatValueValueTaskAsync)) .CreateDelegate <Func <IContract, Message <int, int>, ServerCallContext, ValueTask <(Message?, IAsyncEnumerable <int>)> > >(Channel); Console.WriteLine(call.Method.Disassemble()); _service .Setup(s => s.ServerStreamingRepeatValueValueTaskAsync(1, 2, _tokenSource.Token)) .Returns(new ValueTask <IAsyncEnumerable <int> >(new[] { 1, 2, 3 }.AsAsyncEnumerable())); var response = await call(_service.Object, new Message <int, int>(1, 2), _serverCallContext.Object).ConfigureAwait(false); response.Item1.ShouldBeNull(); var actual = await response.Item2.ToListAsync().ConfigureAwait(false); actual.ShouldBe(new[] { 1, 2, 3 }); _service.VerifyAll(); }
public async Task ClientStreamingEmptyValueTask() { var call = ChannelType .InstanceMethod(nameof(IContract.ClientStreamingEmptyValueTask)) .CreateDelegate <Func <IContract, Message?, IAsyncEnumerable <int>, ServerCallContext, Task <Message> > >(Channel); Console.WriteLine(call.Method.Disassemble()); var stream = new[] { 2 }.AsAsyncEnumerable(); _service .Setup(s => s.ClientStreamingEmptyValueTask(It.IsNotNull <IAsyncEnumerable <int> >())) .Returns <IAsyncEnumerable <int> >(async values => { var items = await values.ToListAsync().ConfigureAwait(false); items.ShouldBe(new[] { 2 }); }); await call(_service.Object, null, stream, _serverCallContext.Object).ConfigureAwait(false); _service.VerifyAll(); }
public async Task DuplicateClientStreaming2() { var call = ChannelType .InstanceMethod("DuplicateClientStreaming2", typeof(IContract), typeof(Message), typeof(IAsyncEnumerable <int>), typeof(ServerCallContext)) .CreateDelegate <Func <IContract, Message?, IAsyncEnumerable <int>, ServerCallContext, Task <Message <string> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); var stream = new[] { 1 }.AsAsyncEnumerable(); _service .Setup(s => s.DuplicateClientStreaming(It.IsNotNull <IAsyncEnumerable <int> >())) .Returns <IAsyncEnumerable <int> >(async values => { var items = await values.ToListAsync().ConfigureAwait(false); items.ShouldBe(new[] { 1 }); return("b"); }); var actual = await call(_service.Object, null, stream, _serverCallContext.Object).ConfigureAwait(false); actual.Value1.ShouldBe("b"); _service.VerifyAll(); }
public async Task ClientStreamingHeaderParameters() { var call = ChannelType .InstanceMethod(nameof(IContract.ClientStreamingHeaderParameters)) .CreateDelegate <Func <IContract, Message <int, string>, IAsyncEnumerable <int>, ServerCallContext, Task <Message <string> > > >(Channel); Console.WriteLine(call.Method.Disassemble()); var stream = new[] { 2 }.AsAsyncEnumerable(); _service .Setup(s => s.ClientStreamingHeaderParameters(It.IsNotNull <IAsyncEnumerable <int> >(), 1, "prefix")) .Returns <IAsyncEnumerable <int>, int, string>(async(values, m, p) => { var items = await values.ToListAsync().ConfigureAwait(false); items.ShouldBe(new[] { 2 }); return("2"); }); var actual = await call(_service.Object, new Message <int, string>(1, "prefix"), stream, _serverCallContext.Object).ConfigureAwait(false); actual.Value1.ShouldBe("2"); _service.VerifyAll(); }