예제 #1
0
        public async Task PollOnceAsync()
        {
            var client = new FakeOperationsClient();

            client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                Value = "result"
            });
            var initial = await Operation <StringValue> .PollOnceFromNameAsync("op", client);

            Assert.False(initial.IsCompleted);
            client.FakeClock.Advance(TimeSpan.FromSeconds(2));
            var polled = await initial.PollOnceAsync();

            Assert.False(polled.IsCompleted);
            client.FakeClock.Advance(TimeSpan.FromSeconds(2));
            polled = await polled.PollOnceAsync();

            Assert.True(polled.IsCompleted);
            Assert.Equal("result", polled.Result.Value);
            Assert.Equal(3, client.RequestCount);
        }
예제 #2
0
        public async Task PollUntilCompletedAsync_NullMetadata()
        {
            var client = new FakeOperationsClient {
                GenerateMetadata = false
            };
            var expectedMetadata = new List <Timestamp> {
                null, null, null
            };
            List <Timestamp> actualMetadata = new List <Timestamp>();
            await client.FakeScheduler.RunAsync(async() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue, Timestamp> .PollOnceFromNameAsync("op", client).Result;
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=0, then at t=2, then another at t=4
                var completedOperation = await initial.PollUntilCompletedAsync(settings, metadataCallback: actualMetadata.Add);
                Assert.Equal("result", completedOperation.Result.Value);
            });

            Assert.Equal(4, client.RequestCount);
            Assert.Equal(expectedMetadata, actualMetadata);
        }