Exemple #1
0
        public void Constructor_MigrateProjectNull_ThrowArgumentException()
        {
            // Setup
            var mocks          = new MockRepository();
            var projectOwner   = mocks.Stub <IProjectOwner>();
            var projectFactory = mocks.Stub <IProjectFactory>();
            var projectStorage = mocks.Stub <IStoreProject>();

            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = "",
                ProjectOwner   = projectOwner,
                ProjectFactory = projectFactory,
                ProjectStorage = projectStorage
            };

            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = "",
                Migrator          = null
            };

            // Call
            TestDelegate call = () => new OpenProjectActivity(openProjectProperties, migrateProjectProperties);

            // Assert
            const string expectedMessage = "Project migrator should be set.";
            string       paramName       = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage).ParamName;

            Assert.AreEqual("optionalProjectMigrationProperties", paramName);

            mocks.VerifyAll();
        }
        /// <summary>
        /// Check if migration is required and if so the migration settings are initialized.
        /// </summary>
        /// <param name="filePath">The project file to open.</param>
        /// <param name="migrationConstructionProperties">Output: Will be null if this method
        /// returns <see cref="MigrationRequired.No"/> or <see cref="MigrationRequired.Aborted"/>.
        /// Will be a concrete instance if this method returns <see cref="MigrationRequired.Yes"/>.</param>
        /// <returns>Indicates if migration is required or not, or that the operation has
        /// been cancelled.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is
        /// not a valid file path.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="filePath"/>
        /// is <c>null</c>.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when the file at <paramref name="filePath"/>
        /// couldn't be read.</exception>
        /// <exception cref="StorageValidationException">Thrown when the file at <paramref name="filePath"/>
        /// is not a valid project file.</exception>
        private MigrationRequired PrepareProjectMigration(string filePath,
                                                          out OpenProjectActivity.ProjectMigrationConstructionProperties migrationConstructionProperties)
        {
            migrationConstructionProperties = null;
            MigrationRequired migrationNeeded = projectMigrator.ShouldMigrate(filePath);

            if (migrationNeeded == MigrationRequired.Yes)
            {
                string projectFilePathTakingIntoAccountMigration = projectMigrator.DetermineMigrationLocation(filePath);
                if (string.IsNullOrWhiteSpace(projectFilePathTakingIntoAccountMigration))
                {
                    migrationNeeded = MigrationRequired.Aborted;
                }
                else
                {
                    migrationConstructionProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
                    {
                        Migrator          = projectMigrator,
                        MigrationFilePath = projectFilePathTakingIntoAccountMigration
                    };
                }
            }

            return(migrationNeeded);
        }
Exemple #3
0
        public void Run_MigrateThrowsArgumentException_ActivityFailedWithAdditionalLogMessages()
        {
            // Setup
            const string someFilePath          = "<path to some file>";
            const string someMigrationFilePath = "<path to some migrated file>";
            const string exceptionMessage      = "<some exception message>";

            var mocks   = new MockRepository();
            var project = mocks.Stub <IProject>();

            var projectStorage = mocks.StrictMock <IStoreProject>();

            projectStorage.Expect(ps => ps.LoadProject(someMigrationFilePath))
            .Return(project)
            .Repeat.Never();

            var projectFactory = mocks.Stub <IProjectFactory>();
            var projectOwner   = mocks.Stub <IProjectOwner>();

            var projectMigrator = mocks.StrictMock <IMigrateProject>();

            projectMigrator.Expect(m => m.Migrate(someFilePath, someMigrationFilePath))
            .Throw(new ArgumentException(exceptionMessage));
            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = someFilePath,
                ProjectOwner   = projectOwner,
                ProjectFactory = projectFactory,
                ProjectStorage = projectStorage
            };

            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = someMigrationFilePath,
                Migrator          = projectMigrator
            };

            var activity = new OpenProjectActivity(openProjectProperties, migrateProjectProperties);

            // Call
            Action call = () => activity.Run();

            // Assert
            TestHelper.AssertLogMessagesAreGenerated(call, new[]
            {
                "Openen van project is gestart.",
                exceptionMessage
            }, 2);

            Assert.AreEqual(ActivityState.Failed, activity.State);

            mocks.VerifyAll();
        }
Exemple #4
0
        public void Run_WithMigration_ExpectedProgressNotifications()
        {
            // Setup
            var mocks          = new MockRepository();
            var projectFactory = mocks.Stub <IProjectFactory>();
            var projectOwner   = mocks.Stub <IProjectOwner>();
            var storeProject   = mocks.Stub <IStoreProject>();
            var migrateProject = mocks.Stub <IMigrateProject>();

            migrateProject.Stub(pm => pm.Migrate(null, null))
            .IgnoreArguments()
            .Return(true);
            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = "",
                ProjectFactory = projectFactory,
                ProjectOwner   = projectOwner,
                ProjectStorage = storeProject
            };
            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = "",
                Migrator          = migrateProject
            };
            var activity = new OpenProjectActivity(openProjectProperties,
                                                   migrateProjectProperties);

            var progressMessages = new List <string>();

            activity.ProgressChanged += (sender, args) =>
            {
                Assert.AreSame(activity, sender);
                Assert.AreEqual(EventArgs.Empty, args);

                progressMessages.Add(activity.ProgressText);
            };

            // Call
            activity.Run();

            // Assert
            var expectedProgressMessages = new[]
            {
                "Stap 1 van 3 | Migreren van project",
                "Stap 2 van 3 | Inlezen van project"
            };

            CollectionAssert.AreEqual(expectedProgressMessages, progressMessages);
            mocks.VerifyAll();
        }
Exemple #5
0
        public void Run_SuccessfulMigrateAndLoadProject_ActivityExecutedWithoutAdditionalLogMessages()
        {
            // Setup
            const string someFilePath          = "<path to some file>";
            const string someMigrationFilePath = "<path to some migrated file>";

            var mocks   = new MockRepository();
            var project = mocks.Stub <IProject>();

            var projectStorage = mocks.Stub <IStoreProject>();

            projectStorage.Expect(ps => ps.LoadProject(someMigrationFilePath))
            .Return(project);

            var projectFactory = mocks.Stub <IProjectFactory>();
            var projectOwner   = mocks.Stub <IProjectOwner>();

            var projectMigrator = mocks.Stub <IMigrateProject>();

            projectMigrator.Expect(m => m.Migrate(someFilePath, someMigrationFilePath))
            .Return(true);
            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = someFilePath,
                ProjectOwner   = projectOwner,
                ProjectFactory = projectFactory,
                ProjectStorage = projectStorage
            };

            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = someMigrationFilePath,
                Migrator          = projectMigrator
            };

            var activity = new OpenProjectActivity(openProjectProperties, migrateProjectProperties);

            // Call
            Action call = () => activity.Run();

            // Assert
            TestHelper.AssertLogMessageIsGenerated(call, "Openen van project is gestart.", 1);

            Assert.AreEqual(ActivityState.Executed, activity.State);

            mocks.VerifyAll();
        }
Exemple #6
0
        public void Finish_ProjectMigrationFailed_ProjectSetToNull()
        {
            // Setup
            var mocks          = new MockRepository();
            var projectFactory = mocks.Stub <IProjectFactory>();
            var projectOwner   = mocks.Stub <IProjectOwner>();

            projectOwner.Expect(po => po.SetProject(null, null));
            var storeProject   = mocks.Stub <IStoreProject>();
            var migrateProject = mocks.Stub <IMigrateProject>();

            migrateProject.Stub(pm => pm.Migrate(null, null))
            .IgnoreArguments()
            .Throw(new ArgumentException());
            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = "",
                ProjectFactory = projectFactory,
                ProjectOwner   = projectOwner,
                ProjectStorage = storeProject
            };
            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = "",
                Migrator          = migrateProject
            };

            var activity = new OpenProjectActivity(openProjectProperties,
                                                   migrateProjectProperties);

            activity.Run();

            // Precondition
            Assert.AreEqual(ActivityState.Failed, activity.State);

            activity.ProgressChanged += (sender, args) =>
            {
                Assert.AreSame(activity, sender);
                Assert.AreEqual(EventArgs.Empty, args);
            };

            // Call
            activity.Finish();

            // Assert
            mocks.VerifyAll();
        }
        /// <summary>
        /// Starts an activity that can migrate the project if required, then opens the project.
        /// </summary>
        /// <param name="filePath">The project file to open.</param>
        /// <param name="migrationProperties">The construction properties related to migrating
        /// a project. Can be <c>null</c>.</param>
        /// <returns>Returns <c>true</c> if the operation completed successfully; Returns
        /// <c>false</c> otherwise (for example when the operation failed or was cancelled).</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is
        /// not a valid file path.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="filePath"/>
        /// is <c>null</c>.</exception>
        private bool MigrateAndOpenProject(string filePath, OpenProjectActivity.ProjectMigrationConstructionProperties migrationProperties)
        {
            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = filePath,
                ProjectOwner   = projectOwner,
                ProjectFactory = projectFactory,
                ProjectStorage = projectPersister
            };
            var activity = new OpenProjectActivity(openProjectProperties, migrationProperties);

            ActivityProgressDialogRunner.Run(mainWindowController.MainWindow, activity);

            return(activity.State == ActivityState.Finished);
        }
Exemple #8
0
        public void GivenActivityMigrationProject_WhenCancellingAndMigrationThrowsException_DoNotLoadProject()
        {
            // Setup
            var mocks          = new MockRepository();
            var projectFactory = mocks.StrictMock <IProjectFactory>();
            var storeProject   = mocks.StrictMock <IStoreProject>();
            var projectOwner   = mocks.StrictMock <IProjectOwner>();
            var migrateProject = mocks.Stub <IMigrateProject>();

            migrateProject.Stub(mp => mp.Migrate(null, null))
            .IgnoreArguments()
            .Throw(new ArgumentException());
            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = "",
                ProjectFactory = projectFactory,
                ProjectStorage = storeProject,
                ProjectOwner   = projectOwner
            };
            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = "",
                Migrator          = migrateProject
            };
            var activity = new OpenProjectActivity(openProjectProperties,
                                                   migrateProjectProperties);

            // When
            activity.ProgressChanged += (sender, args) => activity.Cancel();
            activity.Run();
            activity.Finish();

            // Assert
            Assert.AreEqual(ActivityState.Canceled, activity.State);
            mocks.VerifyAll();
        }
Exemple #9
0
        public void Finish_ProjectMigratedAndOpened_ExpectedProgressText()
        {
            // Setup
            var mocks          = new MockRepository();
            var project        = mocks.Stub <IProject>();
            var projectFactory = mocks.Stub <IProjectFactory>();
            var projectOwner   = mocks.Stub <IProjectOwner>();
            var storeProject   = mocks.Stub <IStoreProject>();

            storeProject.Stub(sp => sp.LoadProject(null))
            .IgnoreArguments()
            .Return(project);
            var migrateProject = mocks.Stub <IMigrateProject>();

            migrateProject.Stub(pm => pm.Migrate(null, null))
            .IgnoreArguments()
            .Return(true);
            mocks.ReplayAll();

            var openProjectProperties = new OpenProjectActivity.OpenProjectConstructionProperties
            {
                FilePath       = "",
                ProjectFactory = projectFactory,
                ProjectOwner   = projectOwner,
                ProjectStorage = storeProject
            };
            var migrateProjectProperties = new OpenProjectActivity.ProjectMigrationConstructionProperties
            {
                MigrationFilePath = "",
                Migrator          = migrateProject
            };

            var activity = new OpenProjectActivity(openProjectProperties,
                                                   migrateProjectProperties);

            activity.Run();

            // Precondition
            Assert.AreEqual(ActivityState.Executed, activity.State);

            var progressMessages = new List <string>();

            activity.ProgressChanged += (sender, args) =>
            {
                Assert.AreSame(activity, sender);
                Assert.AreEqual(EventArgs.Empty, args);

                progressMessages.Add(activity.ProgressText);
            };

            // Call
            activity.Finish();

            // Assert
            var expectedProgressMessages = new[]
            {
                "Stap 3 van 3 | Initialiseren van geopend project"
            };

            CollectionAssert.AreEqual(expectedProgressMessages, progressMessages);

            mocks.VerifyAll();
        }