Beispiel #1
0
        public void UnloadProjectWithoutCurrentProject()
        {
            var service = new Mock <IUserInterfaceService>();
            var facade  = new ProjectHub(service.Object);

            Assert.Throws <CannotUnloadProjectException>(() => facade.UnloadProject());
        }
Beispiel #2
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));
        }
Beispiel #3
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));
        }
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
        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 #6
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));
        }
Beispiel #7
0
 public void UnloadProjectWithoutCurrentProject()
 {
     var service = new Mock<IUserInterfaceService>();
     var facade = new ProjectHub(service.Object);
     Assert.Throws<CannotUnloadProjectException>(() => facade.UnloadProject());
 }
Beispiel #8
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));
        }