Esempio n. 1
0
        public async Task TestTask()
        {
            const string expected = "expected";
            var          single   = Observable.AsyncSingle(async() => await Task.FromResult(expected));

            Assert.Equal(expected, await single);
        }
Esempio n. 2
0
        public async Task TestFunc()
        {
            const string expected = "expected";
            var          single   = Observable.AsyncSingle(() => expected);

            Assert.Equal(expected, await single);
        }
Esempio n. 3
0
        public async Task TestLazy()
        {
            const string expected = "expected";
            var          lazy     = new Lazy <string>(() => expected);
            var          single   = Observable.AsyncSingle(lazy);

            Assert.False(lazy.IsValueCreated);
            Assert.Equal(expected, await single);
            Assert.True(lazy.IsValueCreated);
        }
Esempio n. 4
0
        public void TestProvider()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddTransient <SingleObservableTest>()
                                  .BuildServiceProvider();
            var single   = Observable.AsyncSingle(() => string.Empty, serviceProvider);
            var instance = single.ServiceProvider.GetService <SingleObservableTest>();

            Assert.NotNull(instance);
        }
Esempio n. 5
0
        public async Task TestDisposing()
        {
            const string expected = "expected";
            var          single   = Observable.AsyncSingle(() => expected);

            Assert.Equal(expected, await single);
            var disposable = (IDisposable)single;

            disposable.Dispose();
            await Assert.ThrowsAsync <ObjectDisposedException>(async() => await single);
        }
Esempio n. 6
0
        public async Task TestUnsubscription()
        {
            const string expected   = "expected";
            var          taskSource = new TaskCompletionSource <string>();
            var          single     = Observable.AsyncSingle(async() => await taskSource.Task);
            var          disposable = single.Subscribe(new MockObserver <string>());

            disposable.Dispose();
            disposable.Dispose();
            taskSource.SetResult(expected);
            Assert.Equal(expected, await single);
        }
Esempio n. 7
0
        public async Task TestAccessingCache(
            Func <IProviderObservable <Entity>, IProviderObservable <Entity> > function)
        {
            var entity = new Entity {
                Id = 1, Name = "name", Description = "description"
            };

            this.cache.Set(Key, entity);
            var lazyEntity   = new Lazy <Entity>(() => entity);
            var resultEntity = await function(Observable.AsyncSingle(lazyEntity, this.provider));

            Assert.Equal(entity, resultEntity, new PropertyComparer <Entity>());
            Assert.False(lazyEntity.IsValueCreated);
        }