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

            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) =>
                {
                    CreateProjectContext createContext = context as CreateProjectContext;
                    createContext.Result = Task <IProject> .Factory.StartNew(
                        () => project.Object,
                        new CancellationToken(),
                        TaskCreationOptions.None,
                        new CurrentThreadTaskScheduler());
                })
                .Verifiable();
            }

            var facade = new ProjectHub(service.Object);

            facade.NewProject();

            Assert.IsTrue(facade.HasActiveProject());
            service.Verify(s => s.Invoke(It.IsAny <CommandId>(), It.IsAny <CreateProjectContext>()), Times.Exactly(1));
        }
        public void Invoke()
        {
            Func<IProject> function = () =>
            {
                return new Mock<IProject>().Object;
            };
            var command = new CreateProjectCommand(function);

            var context = new CreateProjectContext();
            command.Invoke(context);
            Assert.IsNotNull(context.Result);
        }
Beispiel #3
0
        public void Invoke()
        {
            Func <IProject> function = () =>
            {
                return(new Mock <IProject>().Object);
            };
            var command = new CreateProjectCommand(function);

            var context = new CreateProjectContext();

            command.Invoke(context);
            Assert.IsNotNull(context.Result);
        }
Beispiel #4
0
        public void CreateNewProjectWithLoadingFailure()
        {
            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) =>
                {
                    CreateProjectContext createContext = context as CreateProjectContext;
                    createContext.Result = null;
                })
                .Verifiable();
            }

            var facade = new ProjectHub(service.Object);

            Assert.Throws <FailedToCreateProjectException>(() => facade.NewProject());
            service.Verify(s => s.Invoke(It.IsAny <CommandId>(), It.IsAny <CreateProjectContext>()), Times.Exactly(1));
        }
Beispiel #5
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();
        }
Beispiel #6
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();
        }