Beispiel #1
0
        public void ShouldHandleMultipleAsyncBusy()
        {
            const int shortDelay = 1000;
            const int longDelay  = 2000;
            var       vm         = new TestViewModel();

            vm.IsBusy.Should().BeFalse();
            vm.IsNotBusy.Should().BeTrue();
            Task.Run(async() =>
            {
                using (vm.Busy())
                {
                    vm.IsBusy.Should().BeTrue();
                    await Task.Delay(shortDelay);
                }

                vm.IsBusy.Should().BeTrue(because: "because the second method runs longer.");
            });
            Task.Run(async() =>
            {
                using (vm.Busy())
                {
                    vm.IsBusy.Should().BeTrue();
                    vm.IsNotBusy.Should().BeFalse();
                    await Task.Delay(longDelay);
                }
                vm.IsBusy.Should().BeFalse();
            });
            vm.IsBusy.Should().BeFalse();
            vm.IsNotBusy.Should().BeTrue();
        }
Beispiel #2
0
        public void ShouldManageMultipleBusy()
        {
            const int expectedChangeCount  = 2; // one for IsBusy and one for IsNotBusy
            var       propertyChangedCount = 0;
            var       vm = new TestViewModel();

            vm.PropertyChanged += (sender, args) => propertyChangedCount++;

            vm.IsBusy.Should().BeFalse();
            vm.IsNotBusy.Should().BeTrue();

            using (vm.SuppressChangeNotifications())
                using (vm.Busy())
                {
                    vm.IsBusy.Should().BeTrue();
                    vm.IsNotBusy.Should().BeFalse();
                    using (vm.Busy())
                    {
                        vm.IsBusy.Should().BeTrue();
                        vm.IsNotBusy.Should().BeFalse();
                    }
                    vm.IsBusy.Should().BeTrue();
                    vm.IsNotBusy.Should().BeFalse();
                }

            vm.IsBusy.Should().BeFalse();
            vm.IsNotBusy.Should().BeTrue();
            propertyChangedCount.Should().Be(expectedChangeCount);
        }
Beispiel #3
0
        public void ShouldManageMultipleBusyWithDirectSetAndOnlyRaiseTwoPropertyChanges()
        {
            var       propertyChangedCount = 0;
            const int expectedRaiseCount   = 2; // one for busy and one for not busy

            var vm = new TestViewModel();

            vm.PropertyChanged += (sender, args) => propertyChangedCount++;

            using (vm.SuppressChangeNotifications())
            {
                vm.IsBusy.Should().BeFalse();
                vm.IsNotBusy.Should().BeTrue();
                vm.IsBusy = true;
                vm.IsBusy.Should().BeTrue();
                vm.IsNotBusy.Should().BeFalse();
                using (vm.Busy())
                {
                    vm.IsBusy.Should().BeTrue();
                    vm.IsNotBusy.Should().BeFalse();
                    using (vm.Busy())
                    {
                        vm.IsBusy.Should().BeTrue();
                        vm.IsNotBusy.Should().BeFalse();
                        using (vm.Busy())
                        {
                            vm.IsBusy.Should().BeTrue();
                            vm.IsNotBusy.Should().BeFalse();
                            using (vm.Busy())
                            {
                                vm.IsBusy = false;
                                vm.IsBusy.Should().BeTrue();
                                vm.IsNotBusy.Should().BeFalse();
                                using (vm.Busy())
                                {
                                    vm.IsBusy.Should().BeTrue();
                                    vm.IsNotBusy.Should().BeFalse();
                                }
                            }
                        }
                    }

                    vm.IsBusy.Should().BeTrue();
                    vm.IsNotBusy.Should().BeFalse();
                }

                vm.IsBusy.Should().BeFalse();
                vm.IsNotBusy.Should().BeTrue();
                vm.IsBusy = true;
                vm.IsBusy.Should().BeTrue();
                vm.IsNotBusy.Should().BeFalse();
                vm.IsBusy = false;
                vm.IsBusy.Should().BeFalse();
                vm.IsNotBusy.Should().BeTrue();
            }

            propertyChangedCount.Should().Be(expectedRaiseCount);
        }