Esempio n. 1
0
        public void BindingController_BindingFinished()
        {
            // Arrange
            ServerViewModel serverVM = CreateServerViewModel();

            serverVM.SetProjects(new[] { new SonarQubeProject("key1", "") });
            ProjectViewModel  projectVM   = serverVM.Projects.First();
            BindingController testSubject = this.PrepareCommandForExecution();

            this.host.VisualStateManager.ManagedState.ConnectedServers.Add(serverVM);
            var progressEvents = new ConfigurableProgressEvents();

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType <ProgressControllerResult>())
            {
                // Arrange
                testSubject.SetBindingInProgress(progressEvents, projectVM.Project);
                testSubject.IsBindingInProgress.Should().BeTrue();

                // Act
                progressEvents.SimulateFinished(result);

                // Assert
                testSubject.IsBindingInProgress.Should().BeFalse();

                if (result == ProgressControllerResult.Succeeded)
                {
                    this.host.TestStateManager.BoundProject.Should().Be(projectVM.Project);
                }
                else
                {
                    this.host.TestStateManager.BoundProject.Should().BeNull();
                }
            }
        }
Esempio n. 2
0
        public void BindingController_BindingFinished()
        {
            // Arrange
            var bindingArgs = new BindCommandArgs("key1", "name1", new ConnectionInformation(new Uri("http://localhost")));

            BindingController testSubject = this.PrepareCommandForExecution();
            var progressEvents            = new ConfigurableProgressEvents();

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType <ProgressControllerResult>())
            {
                // Arrange
                testSubject.SetBindingInProgress(progressEvents, bindingArgs);
                testSubject.IsBindingInProgress.Should().BeTrue();

                // Act
                progressEvents.SimulateFinished(result);

                // Assert
                testSubject.IsBindingInProgress.Should().BeFalse();

                if (result == ProgressControllerResult.Succeeded)
                {
                    this.host.TestStateManager.AssignedProjectKey.Should().Be("key1");
                }
                else
                {
                    this.host.TestStateManager.AssignedProjectKey.Should().BeNull();
                }
            }
        }
        public void BindingController_SetBindingInProgress()
        {
            // Arrange
            ProjectViewModel  projectVM   = CreateProjectViewModel();
            BindingController testSubject = this.PrepareCommandForExecution();
            var progressEvents            = new ConfigurableProgressEvents();

            foreach (var controllerResult in (ProgressControllerResult[])Enum.GetValues(typeof(ProgressControllerResult)))
            {
                this.dteMock.ToolWindows.SolutionExplorer.Window.Active = false;

                // Sanity
                testSubject.BindCommand.CanExecute(projectVM).Should().BeTrue();

                // Act - disable
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);

                // Assert
                testSubject.BindCommand.CanExecute(projectVM).Should().BeFalse("Binding is in progress so should not be enabled");

                // Act - finish
                progressEvents.SimulateFinished(controllerResult);

                // Assert
                testSubject.BindCommand.CanExecute(projectVM).Should().BeTrue("Binding is finished with result: {0}", controllerResult);
                if (controllerResult == ProgressControllerResult.Succeeded)
                {
                    this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeTrue("SolutionExplorer window supposed to be activated");
                }
                else
                {
                    this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse("SolutionExplorer window is not supposed to be activated");
                }
            }
        }
        public void BindingController_BindingFinished_Navigation()
        {
            // Arrange
            ServerViewModel serverVM = CreateServerViewModel();

            serverVM.SetProjects(new[]
            {
                new ProjectInformation {
                    Key = "key1"
                }
            });
            ProjectViewModel  projectVM   = serverVM.Projects.First();
            BindingController testSubject = this.PrepareCommandForExecution();

            this.host.VisualStateManager.ManagedState.ConnectedServers.Add(serverVM);
            var progressEvents = new ConfigurableProgressEvents();
            var teController   = new ConfigurableTeamExplorerController();

            var mefExports = MefTestHelpers.CreateExport <ITeamExplorerController>(teController);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExports);

            serviceProvider.RegisterService(typeof(SComponentModel), mefModel, replaceExisting: true);

            // Case 1: On non-successful binding no navigation will occur
            foreach (ProgressControllerResult nonSuccuess in new[] { ProgressControllerResult.Cancelled, ProgressControllerResult.Failed })
            {
                // Act
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
                progressEvents.SimulateFinished(nonSuccuess);

                // Assert
                teController.ShowConnectionsPageCallsCount.Should().Be(0);
                this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse();
            }

            // Case 2: Has conflicts (should navigate to team explorer page)
            this.conflictsController.HasConflicts = true;

            // Act
            testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            teController.ShowConnectionsPageCallsCount.Should().Be(1);
            this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse();

            // Case 3: Has no conflicts (should navigate to solution explorer)
            this.conflictsController.HasConflicts = false;

            // Act
            testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            teController.ShowConnectionsPageCallsCount.Should().Be(1);
            this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeTrue();
        }
Esempio n. 5
0
        public void ConnectionController_ShowNuGetWarning()
        {
            // Arrange
            ConnectionController testSubject = new ConnectionController(this.host, this.connectionProvider,
                                                                        this.connectionWorkflowMock.Object);

            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;

            this.connectionProvider.ConnectionInformationToReturn = null;
            var progressEvents = new ConfigurableProgressEvents();

            // Case 1: do NOT show
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Case 2: show, but canceled
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Cancelled);

            // Assert
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Case 3: show, but failed
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Failed);

            // Assert
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Test Case 4: show, succeeded
            // Arrange
            this.settings.ShowServerNuGetTrustWarning = true;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            notifications.AssertNotification(NotificationIds.WarnServerTrustId, Strings.ServerNuGetTrustWarningMessage);
        }
Esempio n. 6
0
        public void BindingController_BindingFinished_Navigation()
        {
            // Arrange
            var bindingArgs = new BindCommandArgs("key2", "", new ConnectionInformation(new Uri("http://myUri")));

            BindingController testSubject = this.PrepareCommandForExecution();
            var progressEvents            = new ConfigurableProgressEvents();
            var teController = new ConfigurableTeamExplorerController();

            var mefExports = MefTestHelpers.CreateExport <ITeamExplorerController>(teController);
            var mefModel   = ConfigurableComponentModel.CreateWithExports(mefExports);

            serviceProvider.RegisterService(typeof(SComponentModel), mefModel, replaceExisting: true);

            // Case 1: On non-successful binding no navigation will occur
            foreach (ProgressControllerResult nonSuccuess in new[] { ProgressControllerResult.Cancelled, ProgressControllerResult.Failed })
            {
                // Act
                testSubject.SetBindingInProgress(progressEvents, bindingArgs);
                progressEvents.SimulateFinished(nonSuccuess);

                // Assert
                teController.ShowConnectionsPageCallsCount.Should().Be(0);
                this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse();
            }

            // Case 2: Has conflicts (should navigate to team explorer page)
            this.conflictsController.HasConflicts = true;

            // Act
            testSubject.SetBindingInProgress(progressEvents, bindingArgs);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            teController.ShowConnectionsPageCallsCount.Should().Be(1);
            this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse();

            // Case 3: Has no conflicts (should navigate to solution explorer)
            this.conflictsController.HasConflicts = false;

            // Act
            testSubject.SetBindingInProgress(progressEvents, bindingArgs);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Assert
            teController.ShowConnectionsPageCallsCount.Should().Be(1);
            this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeTrue();
        }
        public void BindingController_SetBindingInProgress_Notifications()
        {
            // Arrange
            ServerViewModel serverVM = CreateServerViewModel();

            serverVM.SetProjects(new[]
            {
                new ProjectInformation {
                    Key = "key1"
                }
            });
            ProjectViewModel  projectVM   = serverVM.Projects.ToArray()[0];
            BindingController testSubject = this.PrepareCommandForExecution();
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);
            var progressEvents = new ConfigurableProgressEvents();

            this.host.ActiveSection.UserNotifications.ShowNotificationError("Need to make sure that this is clear once started", NotificationIds.FailedToBindId, new RelayCommand(() => { }));
            ConfigurableUserNotification userNotifications = (ConfigurableUserNotification)section.UserNotifications;

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType <ProgressControllerResult>())
            {
                // Act - start
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);

                // Assert
                userNotifications.AssertNoNotification(NotificationIds.FailedToBindId);

                // Act - finish
                progressEvents.SimulateFinished(result);

                // Assert
                if (result == ProgressControllerResult.Succeeded)
                {
                    userNotifications.AssertNoNotification(NotificationIds.FailedToBindId);
                }
                else
                {
                    userNotifications.AssertNotification(NotificationIds.FailedToBindId, Strings.FailedToToBindSolution);
                }
            }
        }
Esempio n. 8
0
        public void ConnectionController_SetConnectionInProgress()
        {
            // Arrange
            ConnectionController testSubject = new ConnectionController(this.host, this.connectionProvider,
                                                                        this.connectionWorkflowMock.Object);

            this.projectSystemHelper.SetIsSolutionFullyOpened(true);
            this.connectionProvider.ConnectionInformationToReturn = null;
            var progressEvents = new ConfigurableProgressEvents();
            var connectionInfo = new ConnectionInformation(new Uri("http://refreshConnection"));

            // Sanity
            testSubject.ConnectCommand.CanExecute().Should().BeTrue();
            testSubject.RefreshCommand.CanExecute(connectionInfo).Should().BeTrue();

            foreach (var controllerResult in (ProgressControllerResult[])Enum.GetValues(typeof(ProgressControllerResult)))
            {
                this.outputWindowPane.Reset();

                // Act - disable
                testSubject.SetConnectionInProgress(progressEvents);

                // Assert
                testSubject.ConnectCommand.CanExecute().Should().BeFalse("Connection is in progress so should not be enabled");
                testSubject.RefreshCommand.CanExecute(connectionInfo).Should().BeFalse("Connection is in progress so should not be enabled");
                this.outputWindowPane.AssertOutputStrings(0);

                // Act - log progress
                string message = controllerResult.ToString();
                progressEvents.SimulateStepExecutionChanged(message, double.NaN);

                // Assert prefix
                this.outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.ConnectingToSonarQubePrefixMessageFormat, message));

                // Act - finish
                progressEvents.SimulateFinished(controllerResult);

                // Assert
                testSubject.ConnectCommand.CanExecute().Should().BeTrue("Connection is finished with result: {0}", controllerResult);
                testSubject.RefreshCommand.CanExecute(connectionInfo).Should().BeTrue("Connection is finished with result: {0}", controllerResult);
            }
        }
Esempio n. 9
0
        public void ProgressStepRunner_OnFinished()
        {
            // Arrange
            ConfigurableProgressEvents        progressEvents = new ConfigurableProgressEvents();
            ProgressControllerResult?         result         = null;
            Action <ProgressControllerResult> action         = (r) => result = r;

            foreach (ProgressControllerResult progressResult in Enum.GetValues(typeof(ProgressControllerResult)))
            {
                result = null;
                progressEvents.RunOnFinished(action);

                // Act
                progressEvents.SimulateFinished(progressResult);

                // Assert
                result.Should().Be(progressResult, "Action was not called");
                progressEvents.AssertNoFinishedEventHandlers();
            }
        }
        public void ProgressStepRunner_OnFinished()
        {
            // Setup
            ConfigurableProgressEvents        progressEvents = new ConfigurableProgressEvents();
            ProgressControllerResult?         result         = null;
            Action <ProgressControllerResult> action         = (r) => result = r;

            foreach (ProgressControllerResult progressResult in Enum.GetValues(typeof(ProgressControllerResult)))
            {
                result = null;
                Helpers.RunOnFinished(progressEvents, action);

                // Act
                progressEvents.SimulateFinished(progressResult);

                // Verify
                Assert.AreEqual(progressResult, result, "Action was not called");
                progressEvents.AssertNoFinishedEventHandlers();
            }
        }
        public void ProgressStepRunner_OnFinished()
        {
            // Setup
            ConfigurableProgressEvents progressEvents = new ConfigurableProgressEvents();
            ProgressControllerResult? result = null;
            Action<ProgressControllerResult> action = (r) => result = r;

            foreach (ProgressControllerResult progressResult in Enum.GetValues(typeof(ProgressControllerResult)))
            {
                result = null;
                Helpers.RunOnFinished(progressEvents, action);

                // Act
                progressEvents.SimulateFinished(progressResult);

                // Verify
                Assert.AreEqual(progressResult, result, "Action was not called");
                progressEvents.AssertNoFinishedEventHandlers();
            }
        }
Esempio n. 12
0
        public void BindingController_BindingFinished()
        {
            // Setup
            ServerViewModel serverVM = CreateServerViewModel();

            serverVM.SetProjects(new[]
            {
                new ProjectInformation {
                    Key = "key1"
                }
            });
            ProjectViewModel  projectVM   = serverVM.Projects.First();
            BindingController testSubject = this.PrepareCommandForExecution();

            this.host.VisualStateManager.ManagedState.ConnectedServers.Add(serverVM);
            var progressEvents = new ConfigurableProgressEvents();

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType <ProgressControllerResult>())
            {
                // Setup
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
                Assert.IsTrue(testSubject.IsBindingInProgress);

                // Act
                progressEvents.SimulateFinished(result);


                // Verify
                Assert.IsFalse(testSubject.IsBindingInProgress);

                if (result == ProgressControllerResult.Succeeded)
                {
                    this.host.TestStateManager.AssertBoundProject(projectVM.ProjectInformation);
                }
                else
                {
                    this.host.TestStateManager.AssertNoBoundProject();
                }
            }
        }
Esempio n. 13
0
        public void BindingController_SetBindingInProgress()
        {
            // Arrange
            BindCommandArgs       bindingArgs           = CreateBindingArguments("key1", "name1", "http://localhost");
            ConnectionInformation otherConnection       = new ConnectionInformation(new Uri("http://otherConnection"));
            BindCommandArgs       bindingInProgressArgs = new BindCommandArgs("another.key", "another.name", otherConnection);

            BindingController testSubject = this.PrepareCommandForExecution();
            var progressEvents            = new ConfigurableProgressEvents();

            foreach (var controllerResult in (ProgressControllerResult[])Enum.GetValues(typeof(ProgressControllerResult)))
            {
                this.dteMock.ToolWindows.SolutionExplorer.Window.Active = false;

                // Sanity
                testSubject.BindCommand.CanExecute(bindingArgs).Should().BeTrue();

                // Act - disable
                testSubject.SetBindingInProgress(progressEvents, bindingInProgressArgs);

                // Assert
                testSubject.BindCommand.CanExecute(bindingArgs).Should().BeFalse("Binding is in progress so should not be enabled");

                // Act - finish
                progressEvents.SimulateFinished(controllerResult);

                // Assert
                testSubject.BindCommand.CanExecute(bindingArgs).Should().BeTrue("Binding is finished with result: {0}", controllerResult);
                if (controllerResult == ProgressControllerResult.Succeeded)
                {
                    this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeTrue("SolutionExplorer window supposed to be activated");
                }
                else
                {
                    this.dteMock.ToolWindows.SolutionExplorer.Window.Active.Should().BeFalse("SolutionExplorer window is not supposed to be activated");
                }
            }
        }
Esempio n. 14
0
        public void BindingController_SetBindingInProgress_Notifications()
        {
            // Arrange
            var bindingArgs = new BindCommandArgs("key2", "", new ConnectionInformation(new Uri("http://myUri")));

            BindingController testSubject = this.PrepareCommandForExecution();
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);
            var progressEvents = new ConfigurableProgressEvents();

            this.host.ActiveSection.UserNotifications.ShowNotificationError("Need to make sure that this is clear once started", NotificationIds.FailedToBindId, new RelayCommand(() => { }));
            ConfigurableUserNotification userNotifications = (ConfigurableUserNotification)section.UserNotifications;

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType <ProgressControllerResult>())
            {
                // Act - start
                testSubject.SetBindingInProgress(progressEvents, bindingArgs);

                // Assert
                userNotifications.AssertNoNotification(NotificationIds.FailedToBindId);

                // Act - finish
                progressEvents.SimulateFinished(result);

                // Assert
                if (result == ProgressControllerResult.Succeeded)
                {
                    userNotifications.AssertNoNotification(NotificationIds.FailedToBindId);
                }
                else
                {
                    userNotifications.AssertNotification(NotificationIds.FailedToBindId, Strings.FailedToToBindSolution);
                }
            }
        }
        public void ConnectionController_SetConnectionInProgress()
        {
            // Setup
            ConnectionController testSubject = new ConnectionController(this.host, this.connectionProvider, this.connectionWorkflow);
            this.connectionProvider.ConnectionInformationToReturn = null;
            var progressEvents = new ConfigurableProgressEvents();
            var connectionInfo = new ConnectionInformation(new Uri("http://refreshConnection"));

            // Sanity
            Assert.IsTrue(testSubject.ConnectCommand.CanExecute());
            Assert.IsTrue(testSubject.RefreshCommand.CanExecute(connectionInfo));

            foreach (var controllerResult in (ProgressControllerResult[])Enum.GetValues(typeof(ProgressControllerResult)))
            {
                this.outputWindowPane.Reset();

                // Act - disable
                testSubject.SetConnectionInProgress(progressEvents);

                // Verify 
                Assert.IsFalse(testSubject.ConnectCommand.CanExecute(), "Connection is in progress so should not be enabled");
                Assert.IsFalse(testSubject.RefreshCommand.CanExecute(connectionInfo), "Connection is in progress so should not be enabled");
                this.outputWindowPane.AssertOutputStrings(0);

                // Act - log progress
                string message = controllerResult.ToString();
                progressEvents.SimulateStepExecutionChanged(message, double.NaN);

                // Verify prefix
                this.outputWindowPane.AssertOutputStrings(string.Format(CultureInfo.CurrentCulture, Strings.ConnectingToSonarQubePrefixMessageFormat, message));

                // Act - finish
                progressEvents.SimulateFinished(controllerResult);

                // Verify 
                Assert.IsTrue(testSubject.ConnectCommand.CanExecute(), "Connection is finished with result: {0}", controllerResult);
                Assert.IsTrue(testSubject.RefreshCommand.CanExecute(connectionInfo), "Connection is finished with result: {0}", controllerResult);
            }
        }
        public void ConnectionController_ShowNuGetWarning()
        {
            // Setup
            ConnectionController testSubject = new ConnectionController(this.host, this.connectionProvider, this.connectionWorkflow);
            this.host.SetActiveSection(ConfigurableSectionController.CreateDefault());
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)this.host.ActiveSection.UserNotifications;
            this.connectionProvider.ConnectionInformationToReturn = null;
            var progressEvents = new ConfigurableProgressEvents();
            
            // Case 1: do NOT show
            // Setup
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Verify
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Case 2: show, but cancelled
            // Setup
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Cancelled);

            // Verify
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);


            // Case 3: show, but failed
            // Setup
            this.settings.ShowServerNuGetTrustWarning = false;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Failed);

            // Verify
            notifications.AssertNoNotification(NotificationIds.WarnServerTrustId);

            // Test Case 4: show, succeeded
            // Setup
            this.settings.ShowServerNuGetTrustWarning = true;

            // Act
            testSubject.SetConnectionInProgress(progressEvents);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Verify
            notifications.AssertNotification(NotificationIds.WarnServerTrustId, Strings.ServerNuGetTrustWarningMessage);
        }
        public void BindingController_SetBindingInProgress()
        {
            // Setup
            ProjectViewModel projectVM = CreateProjectViewModel();
            BindingController testSubject = this.PrepareCommandForExecution();
            var progressEvents = new ConfigurableProgressEvents();

            foreach (var controllerResult in (ProgressControllerResult[])Enum.GetValues(typeof(ProgressControllerResult)))
            {
                this.dteMock.ToolWindows.SolutionExplorer.Window.Active = false;

                // Sanity
                Assert.IsTrue(testSubject.BindCommand.CanExecute(projectVM));

                // Act - disable
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);

                // Verify
                Assert.IsFalse(testSubject.BindCommand.CanExecute(projectVM), "Binding is in progress so should not be enabled");

                // Act - finish
                progressEvents.SimulateFinished(controllerResult);

                // Verify
                Assert.IsTrue(testSubject.BindCommand.CanExecute(projectVM), "Binding is finished with result: {0}", controllerResult);
                if (controllerResult == ProgressControllerResult.Succeeded)
                {
                    Assert.IsTrue(this.dteMock.ToolWindows.SolutionExplorer.Window.Active, "SolutionExplorer window supposed to be activated");
                }
                else
                {
                    Assert.IsFalse(this.dteMock.ToolWindows.SolutionExplorer.Window.Active, "SolutionExplorer window is not supposed to be activated");
                }
            }
        }
        public void BindingController_BindingFinished()
        {
            // Setup
            ServerViewModel serverVM = CreateServerViewModel();
            serverVM.SetProjects(new[]
            {
                new ProjectInformation { Key = "key1" }
            });
            ProjectViewModel projectVM = serverVM.Projects.First();
            BindingController testSubject = this.PrepareCommandForExecution();
            this.host.VisualStateManager.ManagedState.ConnectedServers.Add(serverVM);
            var progressEvents = new ConfigurableProgressEvents();

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType<ProgressControllerResult>())
            {
                // Setup
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
                Assert.IsTrue(testSubject.IsBindingInProgress);

                // Act
                progressEvents.SimulateFinished(result);


                // Verify
                Assert.IsFalse(testSubject.IsBindingInProgress);

                if (result == ProgressControllerResult.Succeeded)
                {
                    this.host.TestStateManager.AssertBoundProject(projectVM.ProjectInformation);
                }
                else
                {
                    this.host.TestStateManager.AssertNoBoundProject();
                }
            }
        }
        public void BindingController_BindingFinished_Navigation()
        {
            // Setup
            ServerViewModel serverVM = CreateServerViewModel();
            serverVM.SetProjects(new[]
            {
                new ProjectInformation { Key = "key1" }
            });
            ProjectViewModel projectVM = serverVM.Projects.First();
            BindingController testSubject = this.PrepareCommandForExecution();
            this.host.VisualStateManager.ManagedState.ConnectedServers.Add(serverVM);
            var progressEvents = new ConfigurableProgressEvents();
            var teController = new ConfigurableTeamExplorerController();

            var mefExports = MefTestHelpers.CreateExport<ITeamExplorerController>(teController);
            var mefModel = ConfigurableComponentModel.CreateWithExports(mefExports);
            serviceProvider.RegisterService(typeof(SComponentModel), mefModel, replaceExisting: true);

            // Case 1: On non-successful binding no navigation will occur
            foreach(ProgressControllerResult nonSuccuess in new[] { ProgressControllerResult.Cancelled, ProgressControllerResult.Failed } )
            {
                // Act
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
                progressEvents.SimulateFinished(nonSuccuess);

                // Verify
                teController.AssertExpectedNumCallsShowConnectionsPage(0);
                Assert.IsFalse(this.dteMock.ToolWindows.SolutionExplorer.Window.Active);
            }

            // Case 2: Has conflicts (should navigate to team explorer page)
            this.conflictsController.HasConflicts = true;

            // Act
            testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Verify
            teController.AssertExpectedNumCallsShowConnectionsPage(1);
            Assert.IsFalse(this.dteMock.ToolWindows.SolutionExplorer.Window.Active);

            // Case 3: Has no conflicts (should navigate to solution explorer)
            this.conflictsController.HasConflicts = false;

            // Act
            testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);
            progressEvents.SimulateFinished(ProgressControllerResult.Succeeded);

            // Verify
            teController.AssertExpectedNumCallsShowConnectionsPage(1);
            Assert.IsTrue(this.dteMock.ToolWindows.SolutionExplorer.Window.Active);
        }
        public void BindingController_SetBindingInProgress_Notifications()
        {
            // Setup
            ServerViewModel serverVM = CreateServerViewModel();
            serverVM.SetProjects(new[]
            {
                new ProjectInformation { Key = "key1" }
            });
            ProjectViewModel projectVM = serverVM.Projects.ToArray()[0];
            BindingController testSubject = this.PrepareCommandForExecution();
            var section = ConfigurableSectionController.CreateDefault();
            this.host.SetActiveSection(section);
            var progressEvents = new ConfigurableProgressEvents();
            this.host.ActiveSection.UserNotifications.ShowNotificationError("Need to make sure that this is clear once started", NotificationIds.FailedToBindId, new RelayCommand(() => { }));
            ConfigurableUserNotification userNotifications = (ConfigurableUserNotification)section.UserNotifications;

            foreach (ProgressControllerResult result in Enum.GetValues(typeof(ProgressControllerResult)).OfType<ProgressControllerResult>())
            {
                // Act - start
                testSubject.SetBindingInProgress(progressEvents, projectVM.ProjectInformation);

                // Verify
                userNotifications.AssertNoNotification(NotificationIds.FailedToBindId);

                // Act - finish
                progressEvents.SimulateFinished(result);

                // Verify
                if (result == ProgressControllerResult.Succeeded)
                {
                    userNotifications.AssertNoNotification(NotificationIds.FailedToBindId);
                }
                else
                {
                    userNotifications.AssertNotification(NotificationIds.FailedToBindId, Strings.FailedToToBindSolution);
                }
            }
        }