示例#1
0
        public async Task <Num> Sum(ServerCallContext context, IAsyncStreamReader <Num> requestStream)
        {
            long sum = 0;
            await requestStream.ForEach(async num =>
            {
                sum += num.Num_;
            });

            return(Num.CreateBuilder().SetNum_(sum).Build());
        }
示例#2
0
        public void Sum()
        {
            var clientStreamingResult = client.Sum();
            var numList = new List <long> {
                10, 20, 30
            }.ConvertAll(
                n => Num.CreateBuilder().SetNum_(n).Build());

            numList.Subscribe(clientStreamingResult.Inputs);

            Assert.AreEqual(60, clientStreamingResult.Task.Result.Num_);
        }
示例#3
0
        public void Sum()
        {
            var res = client.Sum();

            foreach (var num in new long[] { 10, 20, 30 })
            {
                res.Inputs.OnNext(Num.CreateBuilder().SetNum_(num).Build());
            }
            res.Inputs.OnCompleted();

            Assert.AreEqual(60, res.Task.Result.Num_);
        }
        public async Task Sum()
        {
            using (var call = client.Sum())
            {
                var numbers = new List <long> {
                    10, 20, 30
                }.ConvertAll(
                    n => Num.CreateBuilder().SetNum_(n).Build());

                await call.RequestStream.WriteAllAsync(numbers);

                var result = await call.ResponseAsync;
                Assert.AreEqual(60, result.Num_);
            }
        }
示例#5
0
        public void Sum()
        {
            Task.Run(async() =>
            {
                var call    = client.Sum();
                var numbers = new List <long> {
                    10, 20, 30
                }.ConvertAll(
                    n => Num.CreateBuilder().SetNum_(n).Build());

                await call.RequestStream.WriteAll(numbers);
                var result = await call.Result;
                Assert.AreEqual(60, result.Num_);
            }).Wait();
        }
示例#6
0
        public IObserver <Num> Sum(IObserver <Num> responseObserver)
        {
            var recorder = new RecordingObserver <Num>();

            Task.Factory.StartNew(() => {
                List <Num> inputs = recorder.ToList().Result;

                long sum = 0;
                foreach (Num num in inputs)
                {
                    sum += num.Num_;
                }

                responseObserver.OnNext(Num.CreateBuilder().SetNum_(sum).Build());
                responseObserver.OnCompleted();
            });
            return(recorder);
        }