Inheritance: IInfoBarManager
コード例 #1
0
        public void InfoBarManager_AttachInfoBar()
        {
            // Setup
            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.AttachInfoBar(windowGuid, "Hello", "world", KnownMonikers.UserWarning);
            frame.AssertShowNoActivateCalled(1);
            bool actionClicked = false;
            bool closed = false;
            infoBarWrapper.ButtonClick += (s, e) => actionClicked = true;
            infoBarWrapper.Closed += (s, e) => closed = true;

            // Verify
            Assert.IsNotNull(infoBarWrapper);
            host.AssertInfoBars(1);
            var infoBarUI = host.MockedElements.Single();
            Assert.AreEqual(1, infoBarUI.Model.TextSpans.Count);
            Assert.AreEqual("Hello", infoBarUI.Model.TextSpans.GetSpan(0).Text);
            Assert.AreEqual(1, infoBarUI.Model.ActionItems.Count);
            Assert.AreEqual("world", infoBarUI.Model.ActionItems.GetItem(0).Text);

            // Sanity
            Assert.IsFalse(actionClicked);
            Assert.IsFalse(closed);

            // Act (check if close event is fired)
            infoBarUI.SimulateClickEvent();

            // Verify
            Assert.IsTrue(actionClicked);
            Assert.IsFalse(closed);

            // Act (check if close event is fired)
            infoBarUI.SimulateClosedEvent();

            // Verify
            Assert.IsTrue(closed);

            // Act (check that events won't fire once closed)
            actionClicked = false;
            closed = false;
            infoBarUI.SimulateClickEvent();
            infoBarWrapper.Close();
            infoBarUI.SimulateClosedEvent();

            // Verify
            Assert.IsFalse(actionClicked);
            Assert.IsFalse(closed);
            frame.AssertShowNoActivateCalled(1); // Should only be called once in all this flow
        }
コード例 #2
0
        public void InfoBarManager_AttachInfoBar_ArgChecks()
        {
            // Setup
            var testSubject = new InfoBarManager(this.serviceProvider);

            // Simple checks
            Exceptions.Expect<ArgumentNullException>(() => testSubject.AttachInfoBar(Guid.Empty, null, "button text", KnownMonikers.EventError));
            Exceptions.Expect<ArgumentNullException>(() => testSubject.AttachInfoBar(Guid.Empty, "", "button text", KnownMonikers.EventError));
            Exceptions.Expect<ArgumentNullException>(() => testSubject.AttachInfoBar(Guid.Empty, "message", null, KnownMonikers.EventError));
            Exceptions.Expect<ArgumentNullException>(() => testSubject.AttachInfoBar(Guid.Empty, "message", " ", KnownMonikers.EventError));

            // Actually checking if the frame exists
            Exceptions.Expect<ArgumentException>(() => testSubject.AttachInfoBar(Guid.Empty, "message", "button text", KnownMonikers.EventError));
        }
コード例 #3
0
        public void InfoBarManager_DetachInfoBar_ArgChecks()
        {
            // Setup
            var testSubject = new InfoBarManager(this.serviceProvider);

            Exceptions.Expect<ArgumentNullException>(() => testSubject.DetachInfoBar(null));
            Exceptions.Expect<ArgumentException>(() => testSubject.DetachInfoBar(new InvalidInfoBar()));
        }
コード例 #4
0
        public void InfoBarManager_DetachInfoBar()
        {
            // Setup
            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.AttachInfoBar(windowGuid, "Hello", "world", default(ImageMoniker));
            bool closed = false;
            infoBarWrapper.Closed += (s, e) => closed = true;

            // Sanity
            host.AssertInfoBars(1);

            // Act
            testSubject.DetachInfoBar(infoBarWrapper);

            // Verify
            Assert.IsTrue(closed, "Expected to auto-close");
            host.AssertInfoBars(0);
        }
コード例 #5
0
        public void InfoBarManager_AttachInfoBar_Failures()
        {
            // Setup
            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 + Verify
            Assert.IsNull(testSubject.AttachInfoBar(windowGuid, "Hello", "world", default(ImageMoniker)));
            frame.AssertShowNoActivateCalled(0);

            // Case 2: Service exists, no host for frame
            this.serviceProvider.RegisterService(typeof(SVsInfoBarUIFactory), new ConfigurableVsInfoBarUIFactory());

            // Act + Verify
            Assert.IsNull(testSubject.AttachInfoBar(windowGuid, "Hello", "world", default(ImageMoniker)));
            frame.AssertShowNoActivateCalled(0);
        }