示例#1
0
        public void NullingViewModelShouldUnloadIt()
        {
            var vm      = new ViewAwareViewModel();
            var fixture = new LoadingView();

            fixture.ViewModel = vm;
            Assert.Equal(0, vm.IsLoadedCount);
            Assert.Equal(0, fixture.IsLoadedCount);

            fixture.Loaded.OnNext(Unit.Default);
            Assert.Equal(1, vm.IsLoadedCount);
            Assert.Equal(1, fixture.IsLoadedCount);

            fixture.ViewModel = null;
            Assert.Equal(0, vm.IsLoadedCount);

            fixture.Dispose();
        }
示例#2
0
        public void LoadingGetRefCounted()
        {
            var fixture = new ViewAwareViewModel();

            Assert.Equal(0, fixture.IsLoadedCount);

            fixture.View.ViewLoaded();
            Assert.Equal(1, fixture.IsLoadedCount);

            fixture.View.ViewLoaded();
            Assert.Equal(1, fixture.IsLoadedCount);

            fixture.View.ViewUnloaded();
            Assert.Equal(1, fixture.IsLoadedCount);

            // Refcount drops to zero
            fixture.View.ViewUnloaded();
            Assert.Equal(0, fixture.IsLoadedCount);
        }
示例#3
0
        public void CanUnloadAndLoadViewAgain()
        {
            var vm      = new ViewAwareViewModel();
            var fixture = new LoadingView();

            fixture.ViewModel = vm;
            Assert.Equal(0, vm.IsLoadedCount);
            Assert.Equal(0, fixture.IsLoadedCount);

            fixture.Loaded.OnNext(Unit.Default);
            Assert.Equal(1, vm.IsLoadedCount);
            Assert.Equal(1, fixture.IsLoadedCount);

            fixture.Unloaded.OnNext(Unit.Default);
            Assert.Equal(0, vm.IsLoadedCount);
            Assert.Equal(0, fixture.IsLoadedCount);

            fixture.Loaded.OnNext(Unit.Default);
            Assert.Equal(1, vm.IsLoadedCount);
            Assert.Equal(1, fixture.IsLoadedCount);

            fixture.Dispose();
        }