Ejemplo n.º 1
0
        public async Task ToStringForCreatedValue()
        {
            var lazy  = new AsyncLazy <int>(() => Task.FromResult <int>(3));
            var value = await lazy.GetValueAsync();

            string result = lazy.ToString();

            Assert.Equal(value.ToString(), result);
        }
Ejemplo n.º 2
0
        public void ToStringForUncreatedValue()
        {
            var    lazy   = new AsyncLazy <object>(() => Task.FromResult <object>(null));
            string result = lazy.ToString();

            Assert.NotNull(result);
            Assert.NotEqual(string.Empty, result);
            Assert.False(lazy.IsValueCreated);
        }
Ejemplo n.º 3
0
        public void ToStringForFaultedValue()
        {
            var lazy = new AsyncLazy <int>(delegate
            {
                throw new ApplicationException();
            });

            lazy.GetValueAsync().Forget();
            Assert.True(lazy.IsValueCreated);
            string result = lazy.ToString();

            Assert.NotNull(result);
            Assert.NotEqual(string.Empty, result);
        }