Пример #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 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();
        }
Пример #3
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();
        }
Пример #4
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();
        }
Пример #5
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();
        }
Пример #6
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();
        }