Example #1
0
        public void TestCancelCommand()
        {
            var m = new ProgressModel();
            TestCancel(m, ProgressModel.GeneralCancelCommand, m);

            m = new ProgressModel();
            TestCancel(m, m.CancelCommand, null);
        }
Example #2
0
        public void TestSourceProperty()
        {
            var pm = new ProgressModel { Progress = 50, ScaledMaximum = 2 };

            var bar = new ProgressBar();
            ProgressModel.SetSource(bar, pm);
            Assert.AreEqual(1, bar.Value);
            Assert.AreEqual(2, bar.Maximum);

            pm.Progress = null;

            Assert.AreEqual(true, bar.IsIndeterminate);
        }
Example #3
0
        public void TestScaledMaximum()
        {
            var pm = new ProgressModel();
            pm.Maximum = 10;
            pm.Progress = 5;

            pm.ScaledMaximum = 2;
            Assert.AreEqual(1, pm.ScaledProgress);

            pm.ScaledMaximum = 100;
            Assert.AreEqual(10, pm.ScaledMaximum);
            Assert.AreEqual(5, pm.ScaledProgress);
        }
Example #4
0
        public void OpenSearch(string query)
        {
            var progress = new ProgressModel();
            var results = searcher.DoSearch(query, progress);

            var headerControl = new Controls.ProgressHeader { Caption = query, DataContext = progress, Image = Icons.SearchResults16 };
            headerControl.SetBinding(Controls.ProgressHeader.IsLoadingProperty, new Binding("IsLoading") { Source = results });

            var tab = new TabItem {
                Header = headerControl,
                Content = new Views.SearchView { DataContext = results }
            };

            tabs.Items.Add(tab);
            tab.IsSelected = true;
        }
Example #5
0
 public CancellationCommand(ProgressModel target)
 {
     fixedTarget = target;
 }
Example #6
0
 public static void SetSource(ProgressBar bar, ProgressModel value)
 {
     if (bar == null) throw new ArgumentNullException("bar");
     bar.SetValue(SourceProperty, value);
 }
Example #7
0
        void TestCancel(ProgressModel model, ICommand cancelCommand, object parameter)
        {
            Assert.IsFalse(cancelCommand.CanExecute(parameter));
            int changeCount = 0;
            EventHandler changeHandler = delegate { changeCount++; };
            try {
                cancelCommand.CanExecuteChanged += changeHandler;

                model.AllowCancellation = true;
                Assert.AreEqual(1, changeCount, "Changing AllowCancellation didn't raise CanExecuteChanged");
                Assert.IsTrue(cancelCommand.CanExecute(parameter));

                cancelCommand.Execute(parameter);
                Assert.IsTrue(model.WasCanceled);

                model.AllowCancellation = false;
                Assert.AreEqual(2, changeCount, "Changing AllowCancellation didn't raise CanExecuteChanged");
                Assert.IsFalse(cancelCommand.CanExecute(parameter));

            } finally { cancelCommand.CanExecuteChanged -= changeHandler; }
        }