public void InitWpfServiceProvider()
        {
            // Allow previous windows to die before bringing up a new one.
            Dispatcher.CurrentDispatcher.Invoke(() => { }, DispatcherPriority.ApplicationIdle);

            _packageMock = new Mock <Package> {
                CallBase = true
            };

            Mock <IVsSettingsManager> settingsManagerMock =
                ServiceProviderMock.SetupService <SVsSettingsManager, IVsSettingsManager>();

            // ReSharper disable once RedundantAssignment
            var intValue = 0;
            // ReSharper disable once RedundantAssignment
            var store = Mock.Of <IVsSettingsStore>(
                ss => ss.GetIntOrDefault(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), out intValue) == 0);

            settingsManagerMock.Setup(sm => sm.GetReadOnlySettingsStore(It.IsAny <uint>(), out store)).Returns(0);

            ServiceProviderMock.SetupService <IVsUIShell, IVsUIShell>();

            // Reset the service provider in an internal microsoft class.
            Type         windowHelper            = typeof(Microsoft.Internal.VisualStudio.PlatformUI.WindowHelper);
            PropertyInfo serviceProviderProperty =
                windowHelper.GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Static);

            Debug.Assert(serviceProviderProperty != null);
            serviceProviderProperty.SetMethod.Invoke(null, new object[] { null });

            // Set the global service provider.
            RunPackageInitalize();
        }
        public async Task TestFindToolWindow_ReturnsExistingInstance()
        {
            Mock <IVsUIShell> uiShellMock = ServiceProviderMock.SetupService <SVsUIShell, IVsUIShell>();
            Guid classId         = Guid.Empty;
            Guid activate        = Guid.Empty;
            Guid persistenceSlot = typeof(LogsViewerToolWindow).GUID;
            // ReSharper disable once RedundantAssignment
            IVsWindowFrame frame = VsWindowFrameMocks.GetMockedWindowFrame();

            uiShellMock.Setup(
                shell => shell.CreateToolWindow(
                    It.IsAny <uint>(),
                    It.IsAny <uint>(),
                    It.IsAny <object>(),
                    ref classId,
                    ref persistenceSlot,
                    ref activate,
                    It.IsAny <IServiceProvider>(),
                    It.IsAny <string>(),
                    It.IsAny <int[]>(),
                    out frame))
            .Returns(VSConstants.S_OK);

            await RunPackageInitializeAsync();

            _objectUnderTest.AddService(
                typeof(SVsUIShell),
                (container, token, type) => Task.FromResult <object>(uiShellMock.Object));
            var toolWindow     = _objectUnderTest.FindToolWindow <LogsViewerToolWindow>(true);
            var existingWindow = _objectUnderTest.FindToolWindow <LogsViewerToolWindow>(false);

            Assert.AreEqual(toolWindow, existingWindow);
        }
        public void TestInitialize()
        {
            var taskSchedulerMock = new Mock <IVsTaskSchedulerService>();
            Mock <IVsTaskSchedulerService2> taskScheduler2Mock = taskSchedulerMock.As <IVsTaskSchedulerService2>();

            taskSchedulerMock.Setup(ts => ts.CreateTaskCompletionSource())
            .Returns(() => new FakeIVsTaskCompletionSource());
            taskScheduler2Mock.Setup(ts => ts.GetAsyncTaskContext())
            .Returns(AssemblyInitialize.JoinableApplicationContext);
            taskScheduler2Mock.Setup(ts => ts.GetTaskScheduler(It.IsAny <uint>()))
            .Returns((uint context) => FakeIVsTask.GetSchedulerFromContext((__VSTASKRUNCONTEXT)context));

            DteMock             = new Mock <DTE>().As <DTE2>();
            ServiceProviderMock = DteMock.As <IServiceProvider>();
            ServiceProviderMock.SetupService <SDTE, DTE2>(DteMock);
            ServiceProviderMock.SetupService <DTE, DTE2>(DteMock);
            ComponentModelMock =
                ServiceProviderMock.SetupService <SComponentModel, IComponentModel>(DefaultValueProvider.Mock);
            ServiceProviderMock.SetupService <SVsTaskSchedulerService, IVsTaskSchedulerService2>(taskScheduler2Mock);
            ServiceProviderMock.SetupDefaultServices();

            ServiceProvider oldProvider = ServiceProvider.GlobalProvider;

            ServiceProvider.CreateFromSetSite(ServiceProviderMock.Object);
            Assert.AreNotEqual(oldProvider, ServiceProvider.GlobalProvider);
        }
Example #4
0
 public void TestInitalize()
 {
     DteMock             = new Mock <DTE>();
     ServiceProviderMock = DteMock.As <IServiceProvider>();
     ServiceProviderMock.SetupService <DTE, DTE>(DteMock);
     ComponentModelMock = ServiceProviderMock.SetupService <SComponentModel, IComponentModel>();
     ComponentModelMock.DefaultValueProvider = DefaultValueProvider.Mock;
     ServiceProviderMock.SetupDefaultServices();
 }
Example #5
0
        public async Task TestGetServiceSI_GetsServiceOfTypeIRegisteredByS()
        {
            Mock <IVsSolution> solutionMock = ServiceProviderMock.SetupService <SVsSolution, IVsSolution>();

            await RunPackageInitalizeAsync();

            IVsSolution service = _objectUnderTest.GetService <SVsSolution, IVsSolution>();

            Assert.AreEqual(solutionMock.Object, service);
        }
        public async Task TestGetServiceSI_GetsServiceOfTypeIRegisteredByS()
        {
            Mock <IVsSolution> solutionMock = ServiceProviderMock.SetupService <SVsSolution, IVsSolution>();

            await RunPackageInitializeAsync();

            _objectUnderTest.AddService(
                typeof(SVsSolution),
                (container, token, type) => Task.FromResult <object>(solutionMock.Object));

            IVsSolution service = _objectUnderTest.GetService <SVsSolution, IVsSolution>();

            Assert.AreEqual(solutionMock.Object, service);
        }
        public void TestFindToolWindow_ReturnsInstanceForCreateTrue()
        {
            Mock <IVsUIShell> uiShellMock = ServiceProviderMock.SetupService <SVsUIShell, IVsUIShell>();
            Guid clsid           = Guid.Empty;
            Guid activate        = Guid.Empty;
            Guid persistenceSlot = typeof(LogsViewerToolWindow).GUID;
            // ReSharper disable once RedundantAssignment
            IVsWindowFrame frame = VsWindowFrameMocks.GetMockedWindowFrame();

            uiShellMock.Setup(
                shell => shell.CreateToolWindow(
                    It.IsAny <uint>(), It.IsAny <uint>(), It.IsAny <object>(), ref
                    clsid, ref persistenceSlot, ref activate, It.IsAny <IServiceProvider>(), It.IsAny <string>(),
                    It.IsAny <int[]>(),
                    out frame)).Returns(VSConstants.S_OK);

            RunPackageInitalize();
            var toolWindow = _objectUnderTest.FindToolWindow <LogsViewerToolWindow>(true);

            Assert.IsNotNull(toolWindow);
        }
        public void BeforeEach()
        {
            // Initialize the export provider to get types exported in GoogleCloudExtension.dll.
            var container = new CompositionContainer(
                new AggregateCatalog(
                    new AssemblyCatalog(typeof(GoogleCloudExtensionPackage).Assembly),
                    new TypeCatalog(typeof(DelegatingServiceProvider))));

            ComponentModelMock.Setup(cm => cm.DefaultExportProvider).Returns(container);
            ComponentModelMock.Setup(cm => cm.GetService <GcpMenuBarControlFactory>())
            .Returns(new GcpMenuBarControlFactory(MockHelpers.LazyOf <IGcpMenuBarControl>()));

            _reporterMock = new Mock <IEventsReporter>();
            EventsReporterWrapper.ReporterLazy = _reporterMock.ToLazy();
            _objectUnderTest = new GoogleCloudExtensionPackage();

            _registerUiFactoryMock = ServiceProviderMock.SetupService <SVsUIFactory, IVsRegisterUIFactories>();
            Guid menuBarControlFactoryGuid = typeof(GcpMenuBarControlFactory).GUID;

            _registerUiFactoryMock.Setup(
                f => f.RegisterUIFactory(ref menuBarControlFactoryGuid, It.IsAny <IVsUIFactory>()));
        }