Ejemplo n.º 1
0
        public void TestAddChild1()
        {
            var model = new MergedDataSourceViewModel(_dataSources.AddGroup(), _actionCenter.Object);
            SingleDataSource source = _dataSources.AddDataSource("foo");
            var sourceViewModel     = new SingleDataSourceViewModel(source, _actionCenter.Object);

            model.AddChild(sourceViewModel);
            model.Observable.Should().Equal(sourceViewModel);
            sourceViewModel.Parent.Should().BeSameAs(model);
        }
Ejemplo n.º 2
0
        private void Drag(IDataSourceViewModel source, IDataSourceViewModel dest)
        {
            var merged = dest as MergedDataSourceViewModel;

            if (merged != null)
            {
                // Drag from ungrouped onto an existing group
                // => add to existing group
                AddFileToGroup(source, merged);
                SelectedItem = merged;
            }
            else
            {
                // Drag from ungrouped onto a dest within a group
                // => find group of dest and addd to it
                merged = dest.Parent as MergedDataSourceViewModel;
                if (merged != null)
                {
                    AddFileToGroup(source, merged);
                    SelectedItem = merged;
                }
                else
                {
                    // Drag from ungrouped onto another ungrouped source
                    // => remove dest as well and create new group
                    int destIndex = _observable.IndexOf(dest);
                    if (destIndex != -1)
                    {
                        _observable.Remove(dest);

                        MergedDataSource mergedDataSource = _dataSources.AddGroup();
                        merged         = new MergedDataSourceViewModel(mergedDataSource, _actionCenter, _settings);
                        merged.Remove += OnRemove;
                        merged.AddChild(source);
                        merged.AddChild(dest);
                        _observable.Insert(destIndex, merged);
                        _allDataSourceViewModels.Add(merged);
                        SelectedItem = merged;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void TestAddChild2()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            SingleDataSource source = _dataSources.AddDataSource("foo");
            var sourceViewModel     = new SingleDataSourceViewModel(source, _actionCenter.Object);

            model.AddChild(sourceViewModel);
            sourceViewModel.CharacterCode.Should().Be("A", "because the merged data source is responsible for providing unique character codes");
        }
Ejemplo n.º 4
0
        public void TestAddChild3()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var sources = new List <SingleDataSourceViewModel>();

            for (int i = 0; i < LogLineSourceId.MaxSources; ++i)
            {
                var source          = _dataSources.AddDataSource(i.ToString());
                var sourceViewModel = new SingleDataSourceViewModel(source, _actionCenter.Object);
                sources.Add(sourceViewModel);

                model.AddChild(sourceViewModel).Should().BeTrue("because the child should've been added");
                model.Observable.Should().Equal(sources, "because all previously added children should be there");
            }

            var tooMuch = new SingleDataSourceViewModel(_dataSources.AddDataSource("dadw"), _actionCenter.Object);

            model.AddChild(tooMuch).Should().BeFalse("because no more children can be added");
            model.Observable.Should().Equal(sources, "because only those sources which could be added should be present");
        }
Ejemplo n.º 5
0
        public void TestRemoveChild1()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var child1 = new SingleDataSourceViewModel(_dataSources.AddDataSource("foo"), _actionCenter.Object);

            model.AddChild(child1);

            var child2 = new SingleDataSourceViewModel(_dataSources.AddDataSource("bar"), _actionCenter.Object);

            model.AddChild(child2);
            model.Observable.Should().Equal(new object[]
            {
                child1, child2
            });

            child1.CharacterCode.Should().Be("A");
            child2.CharacterCode.Should().Be("B");

            model.RemoveChild(child1);
            model.Observable.Should().Equal(new object[] { child2 });
            child2.CharacterCode.Should().Be("A");
        }
Ejemplo n.º 6
0
        public void TestInsertChild2()
        {
            var dataSource = _dataSources.AddGroup();
            var model      = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            var child1 = new SingleDataSourceViewModel(_dataSources.AddDataSource("foo"), _actionCenter.Object);

            model.AddChild(child1);
            child1.CharacterCode.Should().Be("A");

            var child2 = new SingleDataSourceViewModel(_dataSources.AddDataSource("bar"), _actionCenter.Object);

            model.Insert(0, child2);
            model.Observable.Should().Equal(new object[]
            {
                child2, child1
            });

            const string reason = "because the merged data source is responsible for providing unique character codes";

            child2.CharacterCode.Should().Be("A", reason);
            child1.CharacterCode.Should().Be("B", reason);
        }
Ejemplo n.º 7
0
 private static void AddFileToGroup(IDataSourceViewModel source, MergedDataSourceViewModel viewModel)
 {
     viewModel.AddChild(source);
 }