public void BindEventHandlerConstructor()
        {
            const string source      = "Source";
            var          bindCommand = new BindCommand(source);

            Assert.Equal(source, bindCommand.Source);
        }
        public void BindEventHandlerConstructor()
        {
            const string source      = "Source";
            var          bindCommand = new BindCommand(source);

            Assert.AreEqual(source, bindCommand.Source, "BindCommand parameterized constructor fail");
        }
Ejemplo n.º 3
0
        internal WindowViewModel(IProgressBarManager progressBarManager, IFilesListManager filesListManager)
        {
            _model = new WindowModel(progressBarManager, filesListManager);
            _model.PropertyChanged += (s, e) => OnPropertyChanged(e.PropertyName);
            _model.SetEmptyState();

            SetZipState = new BindCommand(param =>
            {
                string fileName = FilesHelper.PickZipDialog();
                if (!string.IsNullOrEmpty(fileName))
                {
                    _model.SetZipState(fileName);
                }
            });

            SetFolderState = new BindCommand(param =>
            {
                string folderPath = FilesHelper.PickFolderDialog();
                if (!string.IsNullOrEmpty(folderPath))
                {
                    _model.SetFolderState(folderPath);
                }
            });

            SetEmptyState = new BindCommand(param =>
            {
                _model.SetEmptyState();
            });

            ProcessDragAndDrop = new BindCommand(param =>
            {
                string[] files = (string[])param;

                if (files == null || files.Length != 1)
                {
                    WindowHelper.ShowError("Drag-and-Drop support only one record.");
                }

                string path = files[0];

                if (FilesHelper.IsFolder(path))
                {
                    _model.SetFolderState(path);
                }
                else if (FilesHelper.IsZipFile(path))
                {
                    _model.SetZipState(path);
                }
                else
                {
                    WindowHelper.ShowError("File format isn't supported.");
                }
            });
        }
        internal FilteringViewModel()
        {
            _model.PropertyChanged += (s, e) => OnPropertyChanged(e.PropertyName);

            AddFilter = new BindCommand(param =>
            {
                try
                {
                    _model.AddExpression(param == null ? CurrentFilteringExpression : (string)param);
                    _model.CurrentFilteringExpression = string.Empty;
                }
                catch (ArgumentException e)
                {
                    WindowHelper.ShowError(e.Message);
                }
            });

            EditFilter = new BindCommand(param =>
            {
                try
                {
                    _model.EditExpression(SelectedIndex);
                }
                catch (ArgumentException e)
                {
                    WindowHelper.ShowError(e.Message);
                }
            });

            RemoveFilter = new BindCommand(param =>
            {
                try
                {
                    _model.RemoveExpression(SelectedIndex);
                }
                catch (ArgumentException e)
                {
                    WindowHelper.ShowError(e.Message);
                }
            });

            ShowInfo = new BindCommand(param =>
            {
                string helpMessage = _model.GetHelpMessage();
                WindowHelper.ShowInfo(helpMessage);
            });
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            ScanCommand.Initialize(this);
            BindCommand.Initialize(this);
            ShowStoredResultsCommand.Initialize(this);
            RetrieveResultsCommand.Initialize(this);
            IncrementalScanCommand.Initialize(this);

            Connect connect = new Connect();

            connect.OnConnection(GetDTE());


            CommonActions ca = CommonActionsInstance.getInstance();

            ca.ApplicationObject = GetDTE();
        }
        public void BindCommandMethodExCanPropertyAction()
        {
            var stubServiceProvider = MockServiceProvider.Instance;

            var bindCommand = new BindCommand();
            var viewModel   = new _TestBindCommand();

            bindCommand.Source                          = viewModel;
            bindCommand.ExecuteMethodName               = "ExecuteMethod";
            bindCommand.CanExecuteMethodName            = "CanExecuteMethod";
            bindCommand.PropertyActionCanExecuteChanged = "PropertyActionCanExecuteChanged";


            var bindResolve        = bindCommand.ProvideValue(stubServiceProvider);
            var fakeTargetICommand = (ICommand)bindResolve;

            if (fakeTargetICommand != null)
            {
                fakeTargetICommand.Execute(null);
            }
            Assert.AreEqual(viewModel.ExecuteCalled, true, "Execute - bind was not resolved");

            if (fakeTargetICommand != null)
            {
                fakeTargetICommand.CanExecute(null);
            }
            Assert.AreEqual(viewModel.CanExecuteCalled, true, "CanExecute - bind was not resolved");

            if (fakeTargetICommand != null)
            {
                fakeTargetICommand.CanExecuteChanged += EventHandlerCanExecuteChanged;
            }

            _count = 0;

            // Execute notification
            viewModel.PropertyActionCanExecuteChanged();
            Assert.AreEqual(_count, 1, "CanExecuteChanged - bind was not resolved");
        }
        public void BindCommandPropertyExCanEventToInvoke()
        {
            var stubServiceProvider = MockServiceProvider.Instance;

            var bindCommand = new BindCommand();
            var viewModel   = new _TestBindCommand();

            bindCommand.Source = viewModel;
            bindCommand.ExecutePropertyName            = "ExecutePropertyName";
            bindCommand.CanExecutePropertyName         = "CanExecutePropertyName";
            bindCommand.EventToInvokeCanExecuteChanged = "EventToInvokeCanExecuteChanged";


            var bindResolve        = bindCommand.ProvideValue(stubServiceProvider);
            var fakeTargetICommand = (ICommand)bindResolve;

            if (fakeTargetICommand != null)
            {
                fakeTargetICommand.Execute(null);
            }
            Assert.Equal(viewModel.ExecuteCalled, true);

            if (fakeTargetICommand != null)
            {
                fakeTargetICommand.CanExecute(null);
            }
            Assert.Equal(viewModel.CanExecuteCalled, true);

            if (fakeTargetICommand != null)
            {
                fakeTargetICommand.CanExecuteChanged += EventHandlerCanExecuteChanged;
            }

            _count = 0;

            // Execute notification
            viewModel.ExecuteEventNotifyCanExecuteChanged();
            Assert.Equal(_count, 1);
        }
        public void ProvideValueFromSourceExceptions()
        {
            var stubServiceProvider = MockServiceProvider.Instance;

            var bindCommand = new BindCommand();
            var viewModel   = new _TestBindCommand();

            bindCommand.Source = viewModel;

            bindCommand.ExecuteMethodName               = "_ExecuteMethod";
            bindCommand.CanExecuteMethodName            = "CanExecuteMethod";
            bindCommand.EventToInvokeCanExecuteChanged  = "EventNotifyCanExecuteChanged";
            bindCommand.PropertyActionCanExecuteChanged = "DelegateNotifyCanExecuteChanged";
            UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider),
                                          "ProvideValueExceptions - expected exception - ArgumentException");

            bindCommand.ExecuteMethodName               = "ExecuteMethod";
            bindCommand.CanExecuteMethodName            = "_CanExecuteMethod";
            bindCommand.EventToInvokeCanExecuteChanged  = "EventNotifyCanExecuteChanged";
            bindCommand.PropertyActionCanExecuteChanged = "DelegateNotifyCanExecuteChanged";
            UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider),
                                          "ProvideValueExceptions - expected exception - ArgumentException");

            bindCommand.ExecuteMethodName               = "ExecuteMethod";
            bindCommand.CanExecuteMethodName            = "CanExecuteMethod";
            bindCommand.EventToInvokeCanExecuteChanged  = "_EventNotifyCanExecuteChanged";
            bindCommand.PropertyActionCanExecuteChanged = "DelegateNotifyCanExecuteChanged";
            UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider),
                                          "ProvideValueExceptions - expected exception - ArgumentException");

            bindCommand.ExecuteMethodName               = "ExecuteMethod";
            bindCommand.CanExecuteMethodName            = "CanExecuteMethod";
            bindCommand.EventToInvokeCanExecuteChanged  = "EventNotifyCanExecuteChanged";
            bindCommand.PropertyActionCanExecuteChanged = "_DelegateNotifyCanExecuteChanged";
            UnitTestInternal.AssertThrows(typeof(ArgumentException), () => bindCommand.ProvideValue(stubServiceProvider),
                                          "ProvideValueExceptions - expected exception - ArgumentException");
        }