Example #1
0
        public void LoadNewProject()
        {
            var project = new Mock <IProject>();

            var persistence = new Mock <IPersistenceInformation>();
            var service     = new Mock <IUserInterfaceService>();
            {
                service.Setup(s => s.Contains(It.IsAny <CommandId>()))
                .Returns(true);

                service.Setup(s => s.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()))
                .Callback <CommandId, ICommandContext>(
                    (id, context) =>
                {
                    LoadProjectContext loadContext = context as LoadProjectContext;
                    Assert.AreSame(persistence.Object, loadContext.LoadFrom);
                    loadContext.Result = Task <IProject> .Factory.StartNew(
                        () => project.Object,
                        new CancellationToken(),
                        TaskCreationOptions.None,
                        new CurrentThreadTaskScheduler());
                })
                .Verifiable();
            }

            var facade = new ProjectHub(service.Object);

            facade.LoadProject(persistence.Object);

            Assert.IsTrue(facade.HasActiveProject());
            service.Verify(s => s.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()), Times.Exactly(1));
        }
Example #2
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 Invoke()
        {
            var persistedProject = new Mock<IPersistenceInformation>();

            Func<IPersistenceInformation, IProject> function = persistenceInfo =>
            {
                Assert.AreEqual(persistedProject.Object, persistenceInfo);
                return new Mock<IProject>().Object;
            };
            var command = new LoadProjectCommand(function);

            var context = new LoadProjectContext
                {
                    LoadFrom = persistedProject.Object,
                };
            command.Invoke(context);
            Assert.IsNotNull(context.Result);
        }
Example #4
0
        public void Invoke()
        {
            var persistedProject = new Mock <IPersistenceInformation>();

            Func <IPersistenceInformation, IProject> function = persistenceInfo =>
            {
                Assert.AreEqual(persistedProject.Object, persistenceInfo);
                return(new Mock <IProject>().Object);
            };
            var command = new LoadProjectCommand(function);

            var context = new LoadProjectContext
            {
                LoadFrom = persistedProject.Object,
            };

            command.Invoke(context);
            Assert.IsNotNull(context.Result);
        }
Example #5
0
        public void LoadNewProjectWithLoadingFailure()
        {
            var persistence = new Mock <IPersistenceInformation>();
            var service     = new Mock <IUserInterfaceService>();
            {
                service.Setup(s => s.Contains(It.IsAny <CommandId>()))
                .Returns(true);

                service.Setup(s => s.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()))
                .Callback <CommandId, ICommandContext>(
                    (id, context) =>
                {
                    LoadProjectContext loadContext = context as LoadProjectContext;
                    Assert.AreSame(persistence.Object, loadContext.LoadFrom);
                    loadContext.Result = null;
                })
                .Verifiable();
            }

            var facade = new ProjectHub(service.Object);

            Assert.Throws <FailedToLoadProjectException>(() => facade.LoadProject(persistence.Object));
            service.Verify(s => s.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()), Times.Exactly(1));
        }
Example #6
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();
        }