public void VsSessionHost_SetActiveSection() { // Setup VsSessionHost testSubject = this.CreateTestSubject(null); // Case 1: Invalid args Exceptions.Expect <ArgumentNullException>(() => testSubject.SetActiveSection(null)); // Case 2: Valid args var section1 = ConfigurableSectionController.CreateDefault(); var section2 = ConfigurableSectionController.CreateDefault(); bool refresh1Called = false; section1.RefreshCommand = new RelayCommand(() => refresh1Called = true); bool refresh2Called = false; section2.RefreshCommand = new RelayCommand(() => refresh2Called = true); // Act (set section1) testSubject.SetActiveSection(section1); Assert.IsFalse(refresh1Called, "Refresh should only be called when bound project was found"); Assert.IsFalse(refresh2Called, "Refresh should only be called when bound project was found"); // Verify Assert.AreSame(section1, testSubject.ActiveSection); // Act (set section2) testSubject.ClearActiveSection(); testSubject.SetActiveSection(section2); // Verify Assert.AreSame(section2, testSubject.ActiveSection); Assert.IsFalse(refresh1Called, "Refresh should only be called when bound project was found"); Assert.IsFalse(refresh2Called, "Refresh should only be called when bound project was found"); }
public void VsSessionHost_SyncCommandFromActiveSectionDuringActiveSectionChanges() { // Arrange VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); int syncCalled = 0; this.stateManager.SyncCommandFromActiveSectionAction = () => syncCalled++; // Case 1: SetActiveSection this.stateManager.ExpectActiveSection = true; // Act testSubject.SetActiveSection(section); // Assert syncCalled.Should().Be(1, "SyncCommandFromActiveSection wasn't called during section activation"); // Case 2: ClearActiveSection section this.stateManager.ExpectActiveSection = false; // Act testSubject.ClearActiveSection(); // Assert syncCalled.Should().Be(2, "SyncCommandFromActiveSection wasn't called during section deactivation"); }
public void VsSessionHost_IServiceProvider_GetService() { // Setup var testSubject = new VsSessionHost(this.serviceProvider, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), new ConfigurableActiveSolutionTracker()); ConfigurableVsShell shell = new ConfigurableVsShell(); shell.RegisterPropertyGetter((int)__VSSPROPID2.VSSPROPID_InstallRootDir, () => this.TestContext.TestRunDirectory); this.serviceProvider.RegisterService(typeof(SVsShell), shell); // Local services // Act + Verify foreach (Type serviceType in VsSessionHost.SupportedLocalServices) { Assert.IsNotNull(testSubject.GetService(serviceType)); } Assert.AreSame(testSubject.GetService <IFileSystem>(), testSubject.GetService <ISourceControlledFileSystem>()); // VS-services // Sanity Assert.IsNull(testSubject.GetService(typeof(VsSessionHostTests)), "Not expecting any service at this point"); // Setup this.serviceProvider.RegisterService(typeof(VsSessionHostTests), this); // Act + Verify Assert.AreSame(this, testSubject.GetService(typeof(VsSessionHostTests)), "Unexpected service was returned, expected to use the service provider"); }
public void VsSessionHost_IServiceProvider_GetService() { // Arrange var testSubject = new VsSessionHost(this.serviceProvider, this.sonarQubeServiceMock.Object, new ConfigurableActiveSolutionTracker()); ConfigurableVsShell shell = new ConfigurableVsShell(); shell.RegisterPropertyGetter((int)__VSSPROPID2.VSSPROPID_InstallRootDir, () => this.TestContext.TestRunDirectory); this.serviceProvider.RegisterService(typeof(SVsShell), shell); // Local services // Act + Assert foreach (Type serviceType in VsSessionHost.SupportedLocalServices) { testSubject.GetService(serviceType).Should().NotBeNull(); } testSubject.GetService <ISourceControlledFileSystem>().Should().Be(testSubject.GetService <IFileSystem>()); // VS-services // Sanity testSubject.GetService(typeof(VsSessionHostTests)).Should().BeNull("Not expecting any service at this point"); // Arrange this.serviceProvider.RegisterService(typeof(VsSessionHostTests), this); // Act + Assert testSubject.GetService(typeof(VsSessionHostTests)).Should().Be(this, "Unexpected service was returned, expected to use the service provider"); }
public void VsSessionHost_ArgChecks() { var loggerMock = new Mock <ILogger>(); Action action = () => new VsSessionHost(this.serviceProvider, null, new ConfigurableActiveSolutionTracker(), loggerMock.Object); action.Should().ThrowExactly <ArgumentNullException>(); action = () => new VsSessionHost(null, sonarQubeServiceMock.Object, new ConfigurableActiveSolutionTracker(), loggerMock.Object); action.Should().ThrowExactly <ArgumentNullException>(); action = () => new VsSessionHost(this.serviceProvider, sonarQubeServiceMock.Object, null, loggerMock.Object); action.Should().ThrowExactly <ArgumentNullException>(); action = () => new VsSessionHost(this.serviceProvider, sonarQubeServiceMock.Object, new ConfigurableActiveSolutionTracker(), null); action.Should().ThrowExactly <ArgumentNullException>(); action = () => new VsSessionHost(this.serviceProvider, null, null, sonarQubeServiceMock.Object, new ConfigurableActiveSolutionTracker(), loggerMock.Object, null); action.Should().ThrowExactly <ArgumentNullException>(); using (var host = new VsSessionHost(this.serviceProvider, sonarQubeServiceMock.Object, new ConfigurableActiveSolutionTracker(), loggerMock.Object)) { host.Should().NotBeNull("Not expecting this to fail, just to make the static analyzer happy"); } }
public void VsSessionHost_SetActiveSection() { // Arrange VsSessionHost testSubject = this.CreateTestSubject(null); // Case 1: Invalid args Exceptions.Expect <ArgumentNullException>(() => testSubject.SetActiveSection(null)); // Case 2: Valid args var section1 = ConfigurableSectionController.CreateDefault(); var section2 = ConfigurableSectionController.CreateDefault(); bool refresh1Called = false; section1.RefreshCommand = new RelayCommand(() => refresh1Called = true); bool refresh2Called = false; section2.RefreshCommand = new RelayCommand(() => refresh2Called = true); // Act (set section1) testSubject.SetActiveSection(section1); refresh1Called.Should().BeFalse(); refresh2Called.Should().BeFalse(); // Assert testSubject.ActiveSection.Should().Be(section1); // Act (set section2) testSubject.ClearActiveSection(); testSubject.SetActiveSection(section2); // Assert testSubject.ActiveSection.Should().Be(section2); refresh1Called.Should().BeFalse(); refresh2Called.Should().BeFalse(); }
public void VsSessionHost_SetActiveSection_TransferState() { // Setup VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); // Act testSubject.SetActiveSection(section); // Verify Assert.AreSame(stateManager.ManagedState, testSubject.ActiveSection.ViewModel.State); }
public void VsSessionHost_SetActiveSection_TransferState() { // Arrange VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); // Act testSubject.SetActiveSection(section); // Assert testSubject.ActiveSection.ViewModel.State.Should().Be(stateManager.ManagedState); }
public void VsSessionHost_ArgChecks() { Exceptions.Expect<ArgumentNullException>(() => new VsSessionHost(null, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), new ConfigurableActiveSolutionTracker())); Exceptions.Expect<ArgumentNullException>(() => new VsSessionHost(this.serviceProvider, null, new ConfigurableActiveSolutionTracker())); Exceptions.Expect<ArgumentNullException>(() => new VsSessionHost(this.serviceProvider, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), null)); using (var host = new VsSessionHost(this.serviceProvider, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), new ConfigurableActiveSolutionTracker())) { Assert.IsNotNull(host, "Not expecting this to fail, just to make the static analyzer happy"); } }
public void VsSessionHost_ArgChecks() { Exceptions.Expect <ArgumentNullException>(() => new VsSessionHost(null, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), new ConfigurableActiveSolutionTracker())); Exceptions.Expect <ArgumentNullException>(() => new VsSessionHost(this.serviceProvider, null, new ConfigurableActiveSolutionTracker())); Exceptions.Expect <ArgumentNullException>(() => new VsSessionHost(this.serviceProvider, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), null)); using (var host = new VsSessionHost(this.serviceProvider, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), new ConfigurableActiveSolutionTracker())) { Assert.IsNotNull(host, "Not expecting this to fail, just to make the static analyzer happy"); } }
public void VsSessionHost_ClearActiveSection_ClearState() { // Setup VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); testSubject.SetActiveSection(section); // Act testSubject.ClearActiveSection(); // Verify Assert.IsNull(testSubject.ActiveSection); Assert.IsNull(section.ViewModel.State); }
public void VsSessionHost_ClearActiveSection_ClearState() { // Arrange VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); testSubject.SetActiveSection(section); // Act testSubject.ClearActiveSection(); // Assert testSubject.ActiveSection.Should().BeNull(); section.ViewModel.State.Should().BeNull(); }
public void VsSessionHost_SetActiveSection_ChangeHost() { // Arrange VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); // Sanity this.stepRunner.CurrentHost.Should().BeNull(); // Act testSubject.SetActiveSection(section); // Assert this.stepRunner.CurrentHost.Should().Be(section.ProgressHost); }
public void VsSessionHost_SetActiveSection_ChangeHost() { // Setup VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); // Sanity this.stepRunner.AssertNoCurrentHost(); // Act testSubject.SetActiveSection(section); // Verify this.stepRunner.AssertCurrentHost(section.ProgressHost); }
private VsSessionHost CreateTestSubject(ConfigurableActiveSolutionTracker tracker) { this.stateManager = new ConfigurableStateManager(); var host = new VsSessionHost(this.serviceProvider, stateManager, this.stepRunner, this.sonarQubeServiceMock.Object, tracker ?? new ConfigurableActiveSolutionTracker(), Dispatcher.CurrentDispatcher); this.stateManager.Host = host; host.ReplaceInternalServiceForTesting <ISolutionBindingSerializer>(this.solutionBinding); return(host); }
public void VsSessionHost_ActiveSectionChangedEvent() { // Arrange VsSessionHost testSubject = this.CreateTestSubject(null); ISectionController section = ConfigurableSectionController.CreateDefault(); ISectionController otherSection = ConfigurableSectionController.CreateDefault(); int changed = 0; testSubject.ActiveSectionChanged += (o, e) => changed++; // Act (1st set) testSubject.SetActiveSection(section); // Assert changed.Should().Be(1, "ActiveSectionChanged event was expected to fire"); // Act (clear) testSubject.ClearActiveSection(); // Assert changed.Should().Be(2, "ActiveSectionChanged event was expected to fire"); // Act (2nd set) testSubject.SetActiveSection(otherSection); // Assert changed.Should().Be(3, "ActiveSectionChanged event was expected to fire"); // Act (clear) testSubject.ClearActiveSection(); // Assert changed.Should().Be(4, "ActiveSectionChanged event was expected to fire"); // Act (clear again) testSubject.ClearActiveSection(); // Assert changed.Should().Be(4, "ActiveSectionChanged event was not expected to fire, since already cleared"); }
private VsSessionHost CreateTestSubject(ConfigurableActiveSolutionTracker tracker) { this.stateManager = new ConfigurableStateManager(); var host = new VsSessionHost(this.serviceProvider, stateManager, this.stepRunner, this.sonarQubeService, tracker?? new ConfigurableActiveSolutionTracker(), Dispatcher.CurrentDispatcher); this.stateManager.Host = host; host.ReplaceInternalServiceForTesting<ISolutionBindingSerializer>(this.solutionBinding); return host; }
public void VsSessionHost_IServiceProvider_GetService() { // Setup var testSubject = new VsSessionHost(this.serviceProvider, new Integration.Service.SonarQubeServiceWrapper(this.serviceProvider), new ConfigurableActiveSolutionTracker()); ConfigurableVsShell shell = new ConfigurableVsShell(); shell.RegisterPropertyGetter((int)__VSSPROPID2.VSSPROPID_InstallRootDir, () => this.TestContext.TestRunDirectory); this.serviceProvider.RegisterService(typeof(SVsShell), shell); // Local services // Act + Verify foreach (Type serviceType in VsSessionHost.SupportedLocalServices) { Assert.IsNotNull(testSubject.GetService(serviceType)); } Assert.AreSame(testSubject.GetService<IFileSystem>(), testSubject.GetService<ISourceControlledFileSystem>()); // VS-services // Sanity Assert.IsNull(testSubject.GetService(typeof(VsSessionHostTests)), "Not expecting any service at this point"); // Setup this.serviceProvider.RegisterService(typeof(VsSessionHostTests), this); // Act + Verify Assert.AreSame(this, testSubject.GetService(typeof(VsSessionHostTests)), "Unexpected service was returned, expected to use the service provider"); }