public MainWindowViewModel(ApplicationSettings settings,
		                           DataSources dataSources,
		                           QuickFilters quickFilters,
		                           IActionCenter actionCenter,
		                           IAutoUpdater updater,
		                           IDispatcher dispatcher)
        {
            if (dataSources == null) throw new ArgumentNullException("dataSources");
            if (quickFilters == null) throw new ArgumentNullException("quickFilters");
            if (updater == null) throw new ArgumentNullException("updater");
            if (dispatcher == null) throw new ArgumentNullException("dispatcher");

            _dataSourcesViewModel = new DataSourcesViewModel(settings, dataSources);
            _dataSourcesViewModel.PropertyChanged += DataSourcesViewModelOnPropertyChanged;
            _quickFilters = new QuickFiltersViewModel(settings, quickFilters);
            _quickFilters.OnFiltersChanged += OnQuickFiltersChanged;
            _settings = new SettingsViewModel(settings);
            _actionCenter = new ActionCenterViewModel(dispatcher, actionCenter);

            _timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromMilliseconds(100)
                };
            _timer.Tick += TimerOnTick;
            _timer.Start();

            _autoUpdater = new AutoUpdateViewModel(updater, settings.AutoUpdate, dispatcher);

            _dispatcher = dispatcher;
            WindowTitle = Constants.MainWindowTitle;

            _selectNextDataSourceCommand = new DelegateCommand(SelectNextDataSource);
            _selectPreviousDataSourceCommand = new DelegateCommand(SelectPreviousDataSource);
            _addDataSourceCommand = new DelegateCommand(AddDataSource);

            ChangeDataSource(CurrentDataSource);
        }
        public void TestRemove2()
        {
            _settings = new ApplicationSettings("foobar");
            var group = new DataSource {Id = Guid.NewGuid()};
            var source1 = new DataSource("foo") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source2 = new DataSource("bar") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source3 = new DataSource("clondyke") {Id = Guid.NewGuid(), ParentId = group.Id};
            _settings.DataSources.Add(source1);
            _settings.DataSources.Add(source2);
            _settings.DataSources.Add(source3);
            _settings.DataSources.Add(group);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            _model = new DataSourcesViewModel(_settings, _dataSources);
            var merged = (MergedDataSourceViewModel) _model.Observable[0];
            IDataSourceViewModel viewModel1 = merged.Observable.ElementAt(0);
            IDataSourceViewModel viewModel2 = merged.Observable.ElementAt(1);
            IDataSourceViewModel viewModel3 = merged.Observable.ElementAt(2);
            viewModel1.RemoveCommand.Execute(null);

            merged.ChildCount.Should().Be(2);
            merged.Observable.Should().NotContain(viewModel1);
            _model.Observable.Should().Equal(new object[] {merged});
            _dataSources.Should().Equal(new object[] {viewModel2.DataSource, viewModel3.DataSource, merged.DataSource});
            _settings.DataSources.Should().Equal(new object[] {source2, source3, group});
        }
        public void TestRemove1()
        {
            _settings = new ApplicationSettings("foobar");
            var source = new DataSource("foo") {Id = Guid.NewGuid()};
            _settings.DataSources.Add(source);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            _model = new DataSourcesViewModel(_settings, _dataSources);
            IDataSourceViewModel viewModel = _model.Observable[0];
            viewModel.RemoveCommand.Execute(null);

            _model.Observable.Should().BeEmpty();
            _dataSources.Should().BeEmpty();
            _settings.DataSources.Should().BeEmpty();
        }
 public void SetUp()
 {
     _settings = new ApplicationSettings("dawddwa");
     _dataSources = new DataSources(_scheduler, _settings.DataSources);
     _model = new DataSourcesViewModel(_settings, _dataSources);
 }
        public void TestCtor2()
        {
            _settings = new ApplicationSettings("foobar");
            var group = new DataSource {Id = Guid.NewGuid()};
            var source = new DataSource("foo") {Id = Guid.NewGuid(), ParentId = Guid.NewGuid()};
            _settings.DataSources.Add(group);
            _settings.DataSources.Add(source);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            new Action(() => _model = new DataSourcesViewModel(_settings, _dataSources)).ShouldNotThrow();
            _model.Observable.Count.Should().Be(2);
            IDataSourceViewModel viewModel = _model.Observable[0];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<MergedDataSourceViewModel>();
            viewModel.DataSource.Id.Should().Be(group.Id);
            var merged = (MergedDataSourceViewModel) viewModel;
            merged.Observable.Should().BeEmpty();

            viewModel = _model.Observable[1];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<SingleDataSourceViewModel>();
        }
        public void TestCtor1()
        {
            _settings = new ApplicationSettings("foobar");
            var group = new DataSource {Id = Guid.NewGuid()};
            var source1 = new DataSource("foo") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source2 = new DataSource("bar") {Id = Guid.NewGuid(), ParentId = group.Id};
            var source3 = new DataSource("clondyke") {Id = Guid.NewGuid()};
            _settings.DataSources.Add(group);
            _settings.DataSources.Add(source1);
            _settings.DataSources.Add(source2);
            _settings.DataSources.Add(source3);
            _dataSources = new DataSources(_scheduler, _settings.DataSources);
            _model = new DataSourcesViewModel(_settings, _dataSources);
            _model.Observable.Count.Should().Be(2);
            IDataSourceViewModel viewModel = _model.Observable[0];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<MergedDataSourceViewModel>();
            viewModel.DataSource.Id.Should().Be(group.Id);
            var merged = (MergedDataSourceViewModel) viewModel;
            merged.Observable.Count().Should().Be(2);
            merged.Observable.ElementAt(0).DataSource.Id.Should().Be(source1.Id);
            merged.Observable.ElementAt(1).DataSource.Id.Should().Be(source2.Id);

            viewModel = _model.Observable[1];
            viewModel.Should().NotBeNull();
            viewModel.Should().BeOfType<SingleDataSourceViewModel>();
            viewModel.DataSource.Id.Should().Be(source3.Id);
        }