示例#1
0
        public async Task Should_WaitForValueAsync()
        {
            var lazy = new UpdatableLazy <string>(() =>
            {
                Task.Delay(ShortDelay).Wait();
                return(TestValue);
            });

            Assert.AreEqual(TestValue, await lazy.GetValueAsync());
        }
示例#2
0
        public async Task Should_RetryAsync()
        {
            var counter = 0;
            var lazy    = new UpdatableLazy <string>(() =>
            {
                if (counter++ < DefaultMaxRetries - 1)
                {
                    throw new Exception();
                }

                return(TestValue);
            }, DefaultMaxRetries);

            Assert.AreEqual(TestValue, await lazy.GetValueAsync());
            Assert.AreEqual(DefaultMaxRetries, counter);
        }