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 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 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(); }