public void InfoBarManager_AttachInfoBarWithButton_ArgChecks() { // Arrange var testSubject = new InfoBarManager(this.serviceProvider); // Simple checks Exceptions.Expect <ArgumentNullException>(() => testSubject.AttachInfoBarWithButton(Guid.Empty, null, "button text", CreateFromVsMoniker(KnownMonikers.EventError))); Exceptions.Expect <ArgumentNullException>(() => testSubject.AttachInfoBarWithButton(Guid.Empty, "", "button text", CreateFromVsMoniker(KnownMonikers.EventError))); Exceptions.Expect <ArgumentNullException>(() => testSubject.AttachInfoBarWithButton(Guid.Empty, "message", null, CreateFromVsMoniker(KnownMonikers.EventError))); Exceptions.Expect <ArgumentNullException>(() => testSubject.AttachInfoBarWithButton(Guid.Empty, "message", " ", CreateFromVsMoniker(KnownMonikers.EventError))); // Actually checking if the frame exists Exceptions.Expect <ArgumentException>(() => testSubject.AttachInfoBarWithButton(Guid.Empty, "message", "button text", CreateFromVsMoniker(KnownMonikers.EventError))); }
public void InfoBarManager_AttachInfoBar_Failures() { // Arrange Guid windowGuid = new Guid(); ConfigurableVsWindowFrame frame = this.shell.RegisterToolWindow(windowGuid); var testSubject = new InfoBarManager(this.serviceProvider); // Case 1: No service this.serviceProvider.AssertOnUnexpectedServiceRequest = false; // Act + Assert testSubject.AttachInfoBarWithButton(windowGuid, "Hello", "world", default).Should().BeNull(); frame.ShowNoActivateCalledCount.Should().Be(0); // Case 2: Service exists, no host for frame this.serviceProvider.RegisterService(typeof(SVsInfoBarUIFactory), new ConfigurableVsInfoBarUIFactory()); // Act + Assert testSubject.AttachInfoBarWithButton(windowGuid, "Hello", "world", default).Should().BeNull(); frame.ShowNoActivateCalledCount.Should().Be(0); }
public void InfoBarManager_DetachInfoBar() { // Arrange Guid windowGuid = new Guid(); ConfigurableVsWindowFrame frame = this.shell.RegisterToolWindow(windowGuid); this.serviceProvider.RegisterService(typeof(SVsInfoBarUIFactory), new ConfigurableVsInfoBarUIFactory()); var testSubject = new InfoBarManager(this.serviceProvider); ConfigurableVsInfoBarHost host = RegisterFrameInfoBarHost(frame); IInfoBar infoBarWrapper = testSubject.AttachInfoBarWithButton(windowGuid, "Hello", "world", default); bool closed = false; infoBarWrapper.Closed += (s, e) => closed = true; // Sanity host.AssertInfoBars(1); // Act testSubject.DetachInfoBar(infoBarWrapper); // Assert closed.Should().BeTrue("Expected to auto-close"); host.AssertInfoBars(0); }
public void InfoBarManager_AttachInfoBar() { // Arrange Guid windowGuid = new Guid(); ConfigurableVsWindowFrame frame = this.shell.RegisterToolWindow(windowGuid); this.serviceProvider.RegisterService(typeof(SVsInfoBarUIFactory), new ConfigurableVsInfoBarUIFactory()); var testSubject = new InfoBarManager(this.serviceProvider); ConfigurableVsInfoBarHost host = RegisterFrameInfoBarHost(frame); // Sanity host.AssertInfoBars(0); // Act IInfoBar infoBarWrapper = testSubject.AttachInfoBarWithButton(windowGuid, "Hello", "world", CreateFromVsMoniker(KnownMonikers.UserWarning)); frame.ShowNoActivateCalledCount.Should().Be(1); bool actionClicked = false; bool closed = false; infoBarWrapper.ButtonClick += (s, e) => actionClicked = true; infoBarWrapper.Closed += (s, e) => closed = true; // Assert infoBarWrapper.Should().NotBeNull(); host.AssertInfoBars(1); var infoBarUI = host.MockedElements.Single(); infoBarUI.Model.TextSpans.Count.Should().Be(1); infoBarUI.Model.TextSpans.GetSpan(0).Text.Should().Be("Hello"); infoBarUI.Model.ActionItems.Count.Should().Be(1); infoBarUI.Model.ActionItems.GetItem(0).Text.Should().Be("world"); // Sanity actionClicked.Should().BeFalse(); closed.Should().BeFalse(); // Act (check if close event is fired) infoBarUI.SimulateClickEvent(); // Assert actionClicked.Should().BeTrue(); closed.Should().BeFalse(); // Act (check if close event is fired) infoBarUI.SimulateClosedEvent(); // Assert closed.Should().BeTrue(); // Act (check that events won't fire once closed) actionClicked = false; closed = false; infoBarUI.SimulateClickEvent(); infoBarWrapper.Close(); infoBarUI.SimulateClosedEvent(); // Assert actionClicked.Should().BeFalse(); closed.Should().BeFalse(); frame.ShowNoActivateCalledCount.Should().Be(1); // Should only be called once in all this flow }