public void OnDatasetCreated()
        {
            var context = new Mock<IContextAware>();
            {
                context.Setup(c => c.IsSynchronized)
                    .Returns(true);
            }

            var project = new Mock<IProject>();
            var facade = new ProjectFacade(project.Object);

            var model = new ProjectDescriptionModel(context.Object, facade);

            var propertyChangedWasRaised = 0;
            var properties = new List<string>();
            model.PropertyChanged += (s, e) =>
            {
                propertyChangedWasRaised++;
                properties.Add(e.PropertyName);
            };

            project.Raise(p => p.OnDatasetCreated += null, EventArgs.Empty);

            Assert.AreEqual(1, propertyChangedWasRaised);
            Assert.That(
                properties,
                Is.EquivalentTo(
                    new List<string>
                    {
                        "NumberOfDatasets",
                    }));
        }
Пример #2
0
        public void CanUndoWithHistoryWithoutRollBack()
        {
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.CanRollBack)
                    .Returns(false);
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new UndoCommand(projectLink.Object, timerFunc);
            Assert.IsFalse(command.CanExecute(null));
        }
        public void Initialize()
        {
            var context = new Mock<IContextAware>();

            var view = new Mock<IProjectDescriptionView>();
            {
                view.SetupSet(v => v.Model = It.IsAny<ProjectDescriptionModel>())
                    .Verifiable();
            }

            var parameter = new ProjectDescriptionParameter(context.Object);

            var project = new Mock<IProject>();
            var facade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(facade);
            }

            var container = new Mock<IDependencyInjectionProxy>();
            {
                container.Setup(c => c.Resolve<IContextAware>())
                    .Returns(context.Object);
                container.Setup(c => c.Resolve<ILinkToProjects>())
                    .Returns(projectLink.Object);
            }

            var presenter = new ProjectDescriptionPresenter(container.Object);
            ((IPresenter)presenter).Initialize(view.Object, parameter);

            Assert.AreSame(view.Object, presenter.View);
            Assert.AreSame(parameter, presenter.Parameter);
            view.VerifySet(v => v.Model = It.IsAny<ProjectDescriptionModel>(), Times.Once());
        }
        public void ActivateDataset()
        {
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.Mark())
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            var proxy = new Mock<IProxyDataset>();
            {
                proxy.Setup(p => p.IsActivated)
                    .Returns(false);
                proxy.Setup(p => p.CanActivate)
                    .Returns(true);
                proxy.Setup(
                    p => p.Activate(
                        It.IsAny<DistributionLocations>(),
                        It.IsAny<Func<IEnumerable<DistributionSuggestion>, SelectedProposal>>(),
                        It.IsAny<CancellationToken>()))
                    .Returns<DistributionLocations, Func<IEnumerable<DistributionSuggestion>, SelectedProposal>, CancellationToken>(
                        (d, f, c) => Task.Factory.StartNew(
                            () =>
                            {
                            },
                            c,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()))
                    .Verifiable();
            }

            var dataset = new DatasetFacade(proxy.Object);

            Func<IEnumerable<DistributionSuggestion>, SelectedProposal> selectionFunc = suggestions => null;
            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new ActivateDatasetCommand(projectLink.Object, dataset, selectionFunc, timerFunc);
            command.Execute(null);

            proxy.Verify(
                p => p.Activate(
                    It.IsAny<DistributionLocations>(),
                    It.IsAny<Func<IEnumerable<DistributionSuggestion>, SelectedProposal>>(),
                    It.IsAny<CancellationToken>()),
                Times.Once());
            history.Verify(h => h.Mark(), Times.Once());
        }
Пример #5
0
        public void OnDatasetDeleted()
        {
            var project = new Mock<IProject>();
            var facade = new ProjectFacade(project.Object);

            bool eventRaised = false;
            facade.OnDatasetDeleted += (s, e) => { eventRaised = true; };

            project.Raise(p => p.OnDatasetDeleted += null, EventArgs.Empty);
            Assert.IsTrue(eventRaised);
        }
Пример #6
0
        public void OnNameUpdate()
        {
            var project = new Mock<IProject>();
            var facade = new ProjectFacade(project.Object);

            bool eventRaised = false;
            facade.OnNameChanged += (s, e) => { eventRaised = true; };

            project.Raise(p => p.OnNameChanged += null, new ValueChangedEventArgs<string>("newName"));
            Assert.IsTrue(eventRaised);
        }
Пример #7
0
        public void Name()
        {
            var project = new Mock<IProject>();
            {
                project.SetupProperty(p => p.Name);
            }

            var facade = new ProjectFacade(project.Object);

            var name = "name";
            facade.Name = name;
            Assert.AreEqual(name, facade.Name);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectDescriptionModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="facade">The project that holds all the data.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="facade"/> is <see langword="null" />.
        /// </exception>
        public ProjectDescriptionModel(IContextAware context, ProjectFacade facade)
            : base(context)
        {
            {
                Enforce.Argument(() => facade);
            }

            m_Project = facade;
            m_Project.OnNameChanged += (s, e) => Notify(() => Name);
            m_Project.OnSummaryChanged += (s, e) => Notify(() => Summary);
            m_Project.OnDatasetCreated += (s, e) => Notify(() => NumberOfDatasets);
            m_Project.OnDatasetDeleted += (s, e) => Notify(() => NumberOfDatasets);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptBackEndProjectFacade"/> class.
        /// </summary>
        /// <param name="current">The object that describes the current project.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="current"/> is <see langword="null" />.
        /// </exception>
        public ScriptBackEndProjectFacade(ProjectFacade current)
        {
            {
                Enforce.Argument(() => current);
            }

            m_Current = current;
            m_Current.OnClosed += (s, e) => RaiseOnProjectClosed();
            m_Current.OnDatasetCreated += (s, e) => RaiseOnDatasetCreated();
            m_Current.OnDatasetDeleted += (s, e) => RaiseOnDatasetDeleted();
            m_Current.OnNameChanged += (s, e) => RaiseOnProjectNameUpdated();
            m_Current.OnSummaryChanged += (s, e) => RaiseOnProjectSummaryUpdated();
        }
        public void Initialize()
        {
            var context = new Mock<IContextAware>();
            var progress = new Mock<ITrackSteppingProgress>();
            var aggregator = new Mock<IEventAggregator>();
            Func<string, IDisposable> func = s => new MockDisposable();

            var proxyDataset = CreateDataset(0, new List<Mock<IProxyDataset>>());
            var project = new Mock<IProject>();
            {
                project.Setup(p => p.BaseDataset())
                    .Returns(proxyDataset.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            var view = new Mock<IDatasetGraphView>();
            {
                view.SetupSet(v => v.Model = It.IsAny<DatasetGraphModel>())
                    .Verifiable();
            }

            var parameter = new DatasetGraphParameter(context.Object);

            var container = new Mock<IDependencyInjectionProxy>();
            {
                container.Setup(c => c.Resolve<IContextAware>())
                    .Returns(context.Object);
                container.Setup(c => c.Resolve<ILinkToProjects>())
                    .Returns(projectLink.Object);
                container.Setup(c => c.Resolve<ITrackSteppingProgress>())
                    .Returns(progress.Object);
                container.Setup(c => c.Resolve<IEventAggregator>())
                    .Returns(aggregator.Object);
                container.Setup(c => c.Resolve<Func<string, IDisposable>>())
                    .Returns(func);
            }

            var presenter = new DatasetGraphPresenter(container.Object);
            ((IPresenter)presenter).Initialize(view.Object, parameter);

            Assert.AreSame(view.Object, presenter.View);
            Assert.AreSame(parameter, presenter.Parameter);
            view.VerifySet(v => v.Model = It.IsAny<DatasetGraphModel>(), Times.Once());
        }
        public void DeactivateDataset()
        {
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.Mark())
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            using (var source = new CancellationTokenSource())
            {
                var proxy = new Mock<IProxyDataset>();
                {
                    proxy.Setup(p => p.IsActivated)
                        .Returns(true);
                    proxy.Setup(p => p.Deactivate())
                        .Returns(() => Task.Factory.StartNew(
                            () =>
                            {
                            },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()))
                        .Verifiable();
                }

                var dataset = new DatasetFacade(proxy.Object);

                Func<string, IDisposable> timerFunc = s => new MockDisposable();

                var command = new DeactivateDatasetCommand(projectLink.Object, dataset, timerFunc);
                command.Execute(null);

                proxy.Verify(p => p.Deactivate(), Times.Once());
                history.Verify(h => h.Mark(), Times.Once());
            }
        }
Пример #12
0
        public void Create()
        {
            var context = new Mock<IContextAware>();
            var progressTracker = new Mock<ITrackSteppingProgress>();

            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.Mark())
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            var name = "a";
            var summary = "b";
            var proxy = new Mock<IProxyDataset>();
            {
                proxy.Setup(p => p.Name)
                    .Returns(name);
                proxy.Setup(p => p.Summary)
                    .Returns(summary);
                proxy.Setup(p => p.IsEditMode)
                    .Returns(false);
                proxy.Setup(p => p.IsActivated)
                    .Returns(true);
            }

            var dataset = new DatasetFacade(proxy.Object);
            var model = new DatasetDetailModel(context.Object, progressTracker.Object, projectLink.Object, dataset);

            Assert.IsTrue(model.DisplayName.Contains(name));
            Assert.AreEqual(name, model.Name);
            Assert.AreEqual(summary, model.Summary);

            Assert.IsTrue(model.IsLocked);
            Assert.IsTrue(model.IsActivated);
        }
        public void AddNewChild()
        {
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.Mark())
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            var childProxy = new Mock<IProxyDataset>();
            var proxy = new Mock<IProxyDataset>();
            {
                proxy.Setup(p => p.IsValid)
                    .Returns(true);
                proxy.Setup(p => p.CanBecomeParent)
                    .Returns(true);
                proxy.Setup(p => p.StoredAt)
                    .Returns(new NullPersistenceInformation());
                proxy.Setup(p => p.CreateNewChild(It.IsAny<DatasetCreationInformation>()))
                    .Returns(childProxy.Object)
                    .Verifiable();
            }

            var dataset = new DatasetFacade(proxy.Object);
            Func<string, IDisposable> func = s => new MockDisposable();

            var command = new AddChildDatasetCommand(projectLink.Object, dataset, func);
            Assert.IsTrue(command.CanExecute(null));

            command.Execute(null);
            proxy.Verify(p => p.CreateNewChild(It.IsAny<DatasetCreationInformation>()), Times.Once());
            history.Verify(h => h.Mark(), Times.Once());
        }
Пример #14
0
        public void CanSaveProjectWithoutChanges()
        {
            var project = new Mock<IProject>();

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.HasActiveProject())
                    .Returns(true);
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new SaveProjectCommand(projectLink.Object, timerFunc);
            Assert.IsFalse(command.CanExecute(null));
        }
        public void Name()
        {
            var context = new Mock<IContextAware>();
            {
                context.Setup(c => c.IsSynchronized)
                    .Returns(true);
            }

            var mockChangeSet = new Mock<IChangeSet>();
            {
                mockChangeSet.Setup(m => m.StoreChanges())
                    .Verifiable();
            }

            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.RecordHistory())
                    .Returns(mockChangeSet.Object);
            }

            var project = new Mock<IProject>();
            {
                project.SetupProperty(p => p.Name, "a")
                    .Verify();
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var facade = new ProjectFacade(project.Object);

            var model = new ProjectDescriptionModel(context.Object, facade);

            var text = "b";
            model.Name = text;

            project.VerifySet(p => p.Name = text, Times.Once());
            mockChangeSet.Verify(h => h.StoreChanges(), Times.Once());
        }
Пример #16
0
        public void CanUndoWithMarkers()
        {
            var currentMark = new TimeMarker(10);
            var markers = new List<TimeMarker>
                {
                    currentMark,
                    new TimeMarker(1),
                };
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.CanRollBack)
                    .Returns(true);
                history.Setup(h => h.MarkersInThePast())
                    .Returns(markers);
                history.Setup(h => h.Current)
                    .Returns(currentMark);
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
                projectLink.Setup(p => p.HasActiveProject())
                    .Returns(true);
            }

            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new UndoCommand(projectLink.Object, timerFunc);
            Assert.IsTrue(command.CanExecute(null));
        }
Пример #17
0
        /// <summary>
        /// Creates a new project.
        /// </summary>
        public void NewProject()
        {
            if (!CanCreateNewProject())
            {
                throw new CannotCreateNewProjectException();
            }

            var context = new CreateProjectContext();

            Debug.Assert(m_Service.Contains(CreateProjectCommand.CommandId), "A command has gone missing.");
            m_Service.Invoke(CreateProjectCommand.CommandId, context);

            var project = context.Result;

            if (project == null)
            {
                throw new FailedToCreateProjectException();
            }

            m_Facade = new ProjectFacade(project.Result);

            RaiseOnNewProjectLoaded();
        }
Пример #18
0
        /// <summary>
        /// Loads a new project from the given resource stream.
        /// </summary>
        /// <param name="persistenceInformation">The object that describes how the project was persisted.</param>
        public void LoadProject(IPersistenceInformation persistenceInformation)
        {
            if (!CanLoadProject())
            {
                throw new CannotLoadProjectException();
            }

            var context = new LoadProjectContext
                {
                    LoadFrom = persistenceInformation
                };

            Debug.Assert(m_Service.Contains(LoadProjectCommand.CommandId), "A command has gone missing.");
            m_Service.Invoke(LoadProjectCommand.CommandId, context);

            var project = context.Result;
            if (project == null)
            {
                throw new FailedToLoadProjectException();
            }

            m_Facade = new ProjectFacade(project.Result);

            RaiseOnNewProjectLoaded();
        }
        public void DeleteDataset()
        {
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.Mark())
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            var proxy = new Mock<IProxyDataset>();
            {
                proxy.Setup(p => p.IsValid)
                    .Returns(true);
                proxy.Setup(p => p.CanBeDeleted)
                    .Returns(true);
                proxy.Setup(p => p.Delete())
                    .Verifiable();
            }

            var dataset = new DatasetFacade(proxy.Object);
            Func<string, IDisposable> func = s => new MockDisposable();

            var command = new DeleteDatasetCommand(projectLink.Object, dataset, func);
            Assert.IsTrue(command.CanExecute(null));

            command.Execute(null);
            proxy.Verify(p => p.Delete(), Times.Once());
            history.Verify(h => h.Mark(), Times.Once());
        }
Пример #20
0
        public void Root()
        {
            var project = new Mock<IProject>();
            {
                project.Setup(p => p.BaseDataset())
                    .Returns(new Mock<IProxyDataset>().Object);
            }

            var facade = new ProjectFacade(project.Object);
            var root = facade.Root();
            Assert.IsNotNull(root);
        }
Пример #21
0
        public void ReloadProject()
        {
            // Create a 'binary' tree of datasets. This should create the following tree:
            //                            X
            //                          /   \
            //                         /     \
            //                        /       \
            //                       /         \
            //                      /           \
            //                     X             X
            //                   /   \         /   \
            //                  /     \       /     \
            //                 /       \     /       \
            //                X         X   X         X
            //              /   \     /   \
            //             X     X   X     X
            var nodes = new List<Mock<IProxyDataset>>();
            var datasets = new Queue<Tuple<Mock<IProxyDataset>, List<Mock<IProxyDataset>>>>();
            var rootChildren = new List<Mock<IProxyDataset>>();
            var root = CreateDataset(0, rootChildren);
            datasets.Enqueue(new Tuple<Mock<IProxyDataset>, List<Mock<IProxyDataset>>>(root, rootChildren));
            nodes.Add(root);

            int count = 0;
            while (count < 10)
            {
                var tuple = datasets.Dequeue();

                count++;
                var leftChildCollection = new List<Mock<IProxyDataset>>();
                var leftChild = CreateDataset(count, leftChildCollection);

                tuple.Item2.Add(leftChild);
                datasets.Enqueue(new Tuple<Mock<IProxyDataset>, List<Mock<IProxyDataset>>>(leftChild, leftChildCollection));
                nodes.Add(leftChild);

                count++;
                var rightChildCollection = new List<Mock<IProxyDataset>>();
                var rightChild = CreateDataset(count, rightChildCollection);

                tuple.Item2.Add(rightChild);
                datasets.Enqueue(new Tuple<Mock<IProxyDataset>, List<Mock<IProxyDataset>>>(rightChild, rightChildCollection));
                nodes.Add(rightChild);
            }

            var context = new Mock<IContextAware>();
            {
                context.Setup(c => c.IsSynchronized)
                    .Returns(true);
            }

            var tracker = new Mock<ITrackSteppingProgress>();
            var project = new Mock<IProject>();
            {
                project.Setup(p => p.BaseDataset())
                    .Returns(root.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            Func<DatasetFacade, DatasetModel> toModel = d => new DatasetModel(context.Object, tracker.Object, projectLink.Object, d);
            var model = new DatasetGraphModel(context.Object, projectFacade, toModel);

            var graph = model.Graph;
            Assert.AreEqual(nodes.Count, graph.VertexCount);

            var rootVertex = graph.Vertices.FirstOrDefault(d => string.Equals(d.Model.Name, 0.ToString(CultureInfo.InvariantCulture)));
            Assert.IsNotNull(rootVertex);

            var vertices = new Queue<DatasetViewVertex>();
            var linearisedVertices = new List<DatasetViewVertex>();
            vertices.Enqueue(rootVertex);
            linearisedVertices.Add(rootVertex);

            while (vertices.Count > 0)
            {
                var vertex = vertices.Dequeue();
                var outEdges = graph.OutEdges(vertex);

                foreach (var edge in outEdges)
                {
                    vertices.Enqueue(edge.Target);
                    linearisedVertices.Add(edge.Target);
                }
            }

            Assert.That(
                linearisedVertices.Select(l => l.Model.Name),
                Is.EquivalentTo(nodes.Select(n => n.Object.Name)));
        }
Пример #22
0
        public void AddDataset()
        {
            // Create a 'binary' tree of datasets. This should create the following tree:
            //                            X
            //                          /   \
            //                         /     \
            //                        /       \
            //                       /         \
            //                      /           \
            //                     X             X
            var nodes = new List<Tuple<Mock<IProxyDataset>, List<Mock<IProxyDataset>>>>();

            for (int i = 0; i < 3; i++)
            {
                var childCollection = new List<Mock<IProxyDataset>>();
                var child = CreateDataset(i, childCollection);

                nodes.Add(new Tuple<Mock<IProxyDataset>, List<Mock<IProxyDataset>>>(child, childCollection));
            }

            var context = new Mock<IContextAware>();
            {
                context.Setup(c => c.IsSynchronized)
                    .Returns(true);
            }

            var tracker = new Mock<ITrackSteppingProgress>();
            var project = new Mock<IProject>();
            {
                project.Setup(p => p.BaseDataset())
                    .Returns(nodes[0].Item1.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            Func<DatasetFacade, DatasetModel> toModel = d => new DatasetModel(context.Object, tracker.Object, projectLink.Object, d);
            var model = new DatasetGraphModel(context.Object, projectFacade, toModel);

            var graph = model.Graph;
            var rootVertex = graph.Vertices.FirstOrDefault(d => string.Equals(d.Model.Name, 0.ToString(CultureInfo.InvariantCulture)));

            var parent = nodes[0];

            // First node
            parent.Item2.Add(nodes[1].Item1);
            project.Raise(p => p.OnDatasetCreated += null, EventArgs.Empty);

            var vertex = graph.Vertices.FirstOrDefault(d => string.Equals(d.Model.Name, 1.ToString(CultureInfo.InvariantCulture)));
            Assert.IsNotNull(vertex);

            var edges = graph.InEdges(vertex);
            Assert.AreEqual(1, edges.Count());
            Assert.AreSame(rootVertex, edges.First().Source);

            // Second node
            parent.Item2.Add(nodes[2].Item1);
            project.Raise(p => p.OnDatasetCreated += null, EventArgs.Empty);

            vertex = graph.Vertices.FirstOrDefault(d => string.Equals(d.Model.Name, 2.ToString(CultureInfo.InvariantCulture)));
            Assert.IsNotNull(vertex);

            edges = graph.InEdges(vertex);
            Assert.AreEqual(1, edges.Count());
            Assert.AreSame(rootVertex, edges.First().Source);
        }
Пример #23
0
        public void UpdateSummary()
        {
            var context = new Mock<IContextAware>();
            var progressTracker = new Mock<ITrackSteppingProgress>();
            var mockChangeSet = new Mock<IChangeSet>();
            {
                mockChangeSet.Setup(m => m.StoreChanges())
                    .Verifiable();
            }

            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.RecordHistory())
                    .Returns(mockChangeSet.Object);
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            var proxy = new Mock<IProxyDataset>();
            {
                proxy.Setup(p => p.Summary)
                    .Verifiable();
            }

            var dataset = new DatasetFacade(proxy.Object);
            var model = new DatasetModel(context.Object, progressTracker.Object, projectLink.Object, dataset);

            var summary = "a";
            model.Summary = summary;
            proxy.VerifySet(p => p.Summary = It.Is<string>(s => s.Equals(summary)), Times.Once());
            mockChangeSet.Verify(h => h.StoreChanges(), Times.Once());
        }
Пример #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetGraphModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="facade">The project that holds the graph of datasets.</param>
        /// <param name="datasetModelBuilder">The function that builds <see cref="DatasetModel"/> objects.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="facade"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="datasetModelBuilder"/> is <see langword="null" />.
        /// </exception>
        public DatasetGraphModel(
            IContextAware context,
            ProjectFacade facade,
            Func<DatasetFacade, DatasetModel> datasetModelBuilder)
            : base(context)
        {
            {
                Enforce.Argument(() => facade);
            }

            m_Project = facade;
            m_Project.OnDatasetCreated += (s, e) => AddDatasetToGraph();
            m_Project.OnDatasetDeleted += (s, e) => RemoveDatasetFromGraph();

            m_DatasetModelBuilder = datasetModelBuilder;

            LayoutType = "Tree";
            LayoutParameters = new SimpleTreeLayoutParameters
                {
                    LayerGap = 250,
                    VertexGap = 250,
                    Direction = LayoutDirection.TopToBottom,
                };

            ReloadProject();
        }
Пример #25
0
        /// <summary>
        /// Creates a new project.
        /// </summary>
        public void NewProject()
        {
            if (!CanCreateNewProject())
            {
                throw new CannotCreateNewProjectException();
            }

            var context = new CreateProjectContext();

            Debug.Assert(m_Service.Contains(CreateProjectCommand.CommandId), "A command has gone missing.");
            m_Service.Invoke(CreateProjectCommand.CommandId, context);

            var project = context.Result;
            if (project == null)
            {
                throw new FailedToCreateProjectException();
            }

            m_Facade = new ProjectFacade(project.Result);

            RaiseOnNewProjectLoaded();
        }
Пример #26
0
        public void LoadProject()
        {
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.Mark(It.IsAny<string>()))
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
                project.Setup(p => p.Save(It.IsAny<IPersistenceInformation>()))
                    .Verifiable();
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.HasActiveProject())
                    .Returns(true);
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
            }

            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new SaveProjectCommand(projectLink.Object, timerFunc);

            var persistence = new Mock<IPersistenceInformation>();
            command.Execute(persistence.Object);

            project.Verify(p => p.Save(It.IsAny<IPersistenceInformation>()), Times.Once());
            history.Verify(h => h.Mark(It.IsAny<string>()), Times.Once());
        }
Пример #27
0
        /// <summary>
        /// Unloads the current project.
        /// </summary>
        public void UnloadProject()
        {
            if (!CanUnloadProject())
            {
                throw new CannotUnloadProjectException();
            }

            var context = new UnloadProjectContext();

            Debug.Assert(m_Service.Contains(UnloadProjectCommand.CommandId), "A command has gone missing.");
            m_Service.Invoke(UnloadProjectCommand.CommandId, context);

            m_Facade = null;
            RaiseOnProjectUnloaded();
        }
Пример #28
0
        public void Undo()
        {
            var currentMark = new TimeMarker(10);
            var markers = new List<TimeMarker>
                {
                    currentMark,
                    new TimeMarker(1),
                };
            var history = new Mock<ITimeline>();
            {
                history.Setup(h => h.CanRollBack)
                    .Returns(true);
                history.Setup(h => h.MarkersInThePast())
                    .Returns(markers);
                history.Setup(h => h.Current)
                    .Returns(currentMark);
                history.Setup(h => h.RollBackTo(It.IsAny<TimeMarker>(), It.IsAny<TimelineTraveller>()))
                    .Verifiable();
            }

            var project = new Mock<IProject>();
            {
                project.Setup(p => p.History)
                    .Returns(history.Object);
            }

            var projectFacade = new ProjectFacade(project.Object);
            var projectLink = new Mock<ILinkToProjects>();
            {
                projectLink.Setup(p => p.ActiveProject())
                    .Returns(projectFacade);
                projectLink.Setup(p => p.HasActiveProject())
                    .Returns(true);
            }

            Func<string, IDisposable> timerFunc = s => new MockDisposable();

            var command = new UndoCommand(projectLink.Object, timerFunc);
            command.Execute(null);

            history.Verify(h => h.RollBackTo(It.IsAny<TimeMarker>(), It.IsAny<TimelineTraveller>()), Times.Once());
        }
Пример #29
0
        public void SaveProject()
        {
            var persistence = new Mock<IPersistenceInformation>();
            var project = new Mock<IProject>();
            {
                project.Setup(p => p.Save(It.IsAny<IPersistenceInformation>()))
                    .Callback<IPersistenceInformation>(info => Assert.AreSame(persistence.Object, info));
            }

            var facade = new ProjectFacade(project.Object);
            facade.SaveProject(persistence.Object);
        }
Пример #30
0
        public void Summary()
        {
            var project = new Mock<IProject>();
            {
                project.SetupProperty(p => p.Summary);
            }

            var facade = new ProjectFacade(project.Object);

            var summary = "text";
            facade.Summary = summary;
            Assert.AreEqual(summary, facade.Summary);
        }
        public void OnSummaryChange()
        {
            var context = new Mock<IContextAware>();
            {
                context.Setup(c => c.IsSynchronized)
                    .Returns(true);
            }

            var project = new Mock<IProject>();
            var facade = new ProjectFacade(project.Object);

            var model = new ProjectDescriptionModel(context.Object, facade);

            var propertyChangedWasRaised = 0;
            var properties = new List<string>();
            model.PropertyChanged += (s, e) =>
            {
                propertyChangedWasRaised++;
                properties.Add(e.PropertyName);
            };

            var text = "a";
            project.Raise(p => p.OnSummaryChanged += null, new ValueChangedEventArgs<string>(text));

            Assert.AreEqual(1, propertyChangedWasRaised);
            Assert.That(
                properties,
                Is.EquivalentTo(
                    new List<string>
                    {
                        "Summary",
                    }));
        }