public void Constructor_FilePathNull_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 = null, ProjectOwner = projectOwner, ProjectFactory = projectFactory, ProjectStorage = projectStorage }; // Call TestDelegate call = () => new OpenProjectActivity(openProjectProperties); // Assert const string expectedMessage = "Filepath should be set."; string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage).ParamName; Assert.AreEqual("requiredOpenProjectProperties", paramName); mocks.VerifyAll(); }
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(); }
public void Constructor_ExpectedValues() { // 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 }; // Call var activity = new OpenProjectActivity(openProjectProperties); // Assert Assert.IsInstanceOf <Activity>(activity); Assert.AreEqual("Openen van project", activity.Description); Assert.IsNull(activity.ProgressText); Assert.AreEqual(ActivityState.None, activity.State); mocks.VerifyAll(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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); }
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(); }
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(); }
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(); }