Example #1
0
        public QueryResultsViewModel(string caption, IQueryResultsView view, IEventAggregator aggregator, ITimeLineService service, 
            IAsyncManager asyncManager, ContextMenuRoot menu)
        {
            this._aggregator = aggregator;
            _service = service;
            this._asyncManager = asyncManager;
            Caption = caption;
            View = view;

            View.DataContext = this;

            this.Tweets = new ObservableCollection<TweetViewModel>();

            this._aggregator.GetEvent<RefreshEvent>().Subscribe(Refresh//,
                ,ThreadOption.UIThread, true,
                _ => !this.Editing
                );

            GlobalCommands.UpCommand.RegisterCommand(new DelegateCommand<object>(MoveUp));
            GlobalCommands.DownCommand.RegisterCommand(new DelegateCommand<object>(MoveDown));

            _contextMenu = menu;

            _editCommand = new DelegateCommand<object>(EditSelectedTweet,
                                                       o =>
                                                       this.SelectedTweet !=
                                                       null);

            _cancelEditCommand = new DelegateCommand<object>(CancelEdit,
                o => this.SelectedTweet != null && this.SelectedTweet.Editable);
        }
        protected override void OnSetup()
        {
            var commands =
                from prop in
                    typeof (GlobalCommands).GetProperties(BindingFlags.Static |
                                                          BindingFlags.Public)
                where
                    typeof(CompositeCommand).IsAssignableFrom(prop.PropertyType)
                select prop.GetValue(null, null) as CompositeCommand;
            foreach (var command in commands)
            {
                command.RegisteredCommands.ForEach(command.UnregisterCommand);
            }

            _service = GetMock<ITimeLineService>();

            this.GetMock<IQueryResultsView>();
            this.GetMock<ILinqApi>();
            _aggregator = GetMock<IEventAggregator>();
            _querySubmittedEvent = new Mock<QuerySubmittedEvent>
                                      {CallBase = true};
            _refreshEvent = CreateEvent<RefreshEvent, object>();

            _aggregator.Setup(a => a.GetEvent<QuerySubmittedEvent>()).Returns(
                this._querySubmittedEvent.Object);

            _menuRoot = new ContextMenuRoot();

            Register(_menuRoot);

            Register(DefaultCaption);

            _vm = Create<QueryResultsViewModel>();
        }