Пример #1
0
        public void GivenActivityOpeningProject_WhenCancellingWhileLoadProjectThrowsStorageException_DoNotSetProject()
        {
            // Setup
            var mocks          = new MockRepository();
            var projectFactory = mocks.StrictMock <IProjectFactory>();
            var projectOwner   = mocks.StrictMock <IProjectOwner>();
            var storeProject   = mocks.Stub <IStoreProject>();

            storeProject.Stub(s => s.LoadProject(null))
            .IgnoreArguments()
            .Throw(new StorageException());
            mocks.ReplayAll();

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

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

            // Assert
            Assert.AreEqual(ActivityState.Canceled, activity.State);
            mocks.VerifyAll();
        }
Пример #2
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();
        }
Пример #3
0
        public void GivenSuccessfullyExecutedOpenProjectActivity_WhenFinishingOpenProjectActivity_ThenProjectOwnerAndNewProjectUpdatedWithLogMessage()
        {
            // Given
            const string someFilePath = @"c:\\folder\someFilePath.rtd";

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

            project.Expect(p => p.NotifyObservers());

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

            projectStorage.Stub(ps => ps.LoadProject(someFilePath))
            .Return(project);

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

            projectOwner.Expect(po => po.SetProject(project, someFilePath));
            mocks.ReplayAll();

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

            var activity = new OpenProjectActivity(openProjectProperties);

            activity.Run();

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

            // When
            Action call = () =>
            {
                activity.LogState();
                activity.Finish();
            };

            // Then
            const string expectedMessage = "Openen van project is gelukt.";

            TestHelper.AssertLogMessageIsGenerated(call, expectedMessage, 1);

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

            Assert.AreEqual(Path.GetFileNameWithoutExtension(someFilePath), project.Name);

            mocks.VerifyAll();
        }
Пример #4
0
        public void Finish_OnlyProjectOpened_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);
            mocks.ReplayAll();

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

            var activity = new OpenProjectActivity(openProjectProperties);

            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 2 van 2 | Initialiseren van geopend project"
            };

            CollectionAssert.AreEqual(expectedProgressMessages, progressMessages);

            mocks.VerifyAll();
        }
Пример #5
0
        public void LogState_ActivityCancelled_ProjectOwnerNotUpdatedWithLogMessage()
        {
            // Setup
            const string someFilePath = @"c:\\folder\someFilePath.rtd";

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

            project.Expect(p => p.NotifyObservers())
            .Repeat.Never();

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

            projectStorage.Stub(ps => ps.LoadProject(someFilePath))
            .Return(project);

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

            projectOwner.Expect(po => po.SetProject(project, someFilePath))
            .Repeat.Never();
            mocks.ReplayAll();

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

            var activity = new OpenProjectActivity(openProjectProperties);

            activity.Run();
            activity.Cancel();

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

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

            // Assert
            Tuple <string, LogLevelConstant> expectedMessage = Tuple.Create("Openen van project is geannuleerd.",
                                                                            LogLevelConstant.Warn);

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedMessage, 1);

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

            mocks.VerifyAll();
        }
Пример #6
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();
        }
Пример #7
0
        public void GivenOpenProjectActivityFailedDueToException_WhenFinishingOpenProjectActivity_ThenProjectOwnerHasNullProjectWithLogMessage(Exception exceptionToThrow)
        {
            // Given
            const string someFilePath = @"c:\\folder\someFilePath.rtd";

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

            projectStorage.Stub(ps => ps.LoadProject(someFilePath))
            .Throw(exceptionToThrow);

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

            projectOwner.Expect(po => po.SetProject(null, null));
            mocks.ReplayAll();

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

            var activity = new OpenProjectActivity(openProjectProperties);

            activity.Run();

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

            // When
            Action call = () =>
            {
                activity.LogState();
                activity.Finish();
            };

            // Then
            var expectedMessage = Tuple.Create("Openen van project is mislukt.",
                                               LogLevelConstant.Error);

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedMessage, 1);

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

            mocks.VerifyAll();
        }
Пример #8
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();
        }
Пример #9
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();
        }
Пример #10
0
        public void Run_StoreProjectLoadProjectThrowsStorageException_ActivityFailedWithAdditionalLogMessages()
        {
            // Setup
            const string someFilePath = "<path to some file>";

            const string message        = "<some exception message>";
            var          innerException = new Exception("A");

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

            projectStorage.Expect(ps => ps.LoadProject(someFilePath))
            .Throw(new StorageException(message, innerException));

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

            mocks.ReplayAll();

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

            var activity = new OpenProjectActivity(openProjectProperties);

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

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

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

            mocks.VerifyAll();
        }
Пример #11
0
        public void GivenActivityMigratingAndOpeningProject_WhenCancellingDuringMigration_DoNotLoadProject(bool migrationSuccessful)
        {
            // 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()
            .Return(migrationSuccessful);
            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();
        }
Пример #12
0
        public void Run_StoreProjectLoadProjectReturnsNull_ActivityFailedWithoutAdditionalLogMessages()
        {
            // Setup
            const string someFilePath = "<path to some file>";

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

            projectStorage.Expect(ps => ps.LoadProject(someFilePath))
            .Return(null);

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

            mocks.ReplayAll();

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

            var activity = new OpenProjectActivity(openProjectProperties);

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

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

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

            mocks.VerifyAll();
        }