Example #1
0
        public void TestOnBrowseStackdriverLogCommand()
        {
            string filter             = null;
            var    logsToolWindowMock = new Mock <LogsViewerToolWindow> {
                CallBase = true
            };

            logsToolWindowMock.Setup(w => w.ViewModel.FilterLog(It.IsAny <string>())).Callback((string s) => filter = s);
            logsToolWindowMock.Object.Frame = VsWindowFrameMocks.GetMockedWindowFrame();
            PackageMock.Setup(
                p => p.FindToolWindow <LogsViewerToolWindow>(false, It.IsAny <int>()))
            .Returns(() => null);
            PackageMock.Setup(p => p.FindToolWindow <LogsViewerToolWindow>(true, It.IsAny <int>()))
            .Returns(logsToolWindowMock.Object);
            var objectUnderTest = new VersionViewModel(
                new GaeSourceRootViewModel(),
                Mock.Of <Service>(s => s.Id == "ServiceId" && s.Split.Allocations == new Dictionary <string, double?>()),
                new Version {
                Id = "VersionId"
            }, true);

            MenuItem logsMenuItem = objectUnderTest.ContextMenu.ItemsSource.OfType <MenuItem>().Single(
                mi => mi.Header.Equals(Resources.CloudExplorerLaunchLogsViewerMenuHeader));

            logsMenuItem.Command.Execute(null);

            StringAssert.Contains(filter, "resource.type=\"gae_app\"");
            StringAssert.Contains(filter, "resource.labels.module_id=\"ServiceId\"");
            StringAssert.Contains(filter, "resource.labels.version_id=\"VersionId\"");
        }
        public void TestOnBrowseStackdriverLogCommand()
        {
            var logsToolWindowMock = new Mock <LogsViewerToolWindow> {
                CallBase = true
            };

            logsToolWindowMock.Object.Frame = VsWindowFrameMocks.GetMockedWindowFrame();
            PackageMock.Setup(
                p => p.FindToolWindow <LogsViewerToolWindow>(false, It.IsAny <int>()))
            .Returns(() => null);
            PackageMock.Setup(
                p => p.FindToolWindow <LogsViewerToolWindow>(true, It.IsAny <int>()))
            .Returns(logsToolWindowMock.Object);
            string filter = null;

            logsToolWindowMock.Setup(w => w.ViewModel.FilterLog(It.IsAny <string>())).Callback((string s) => filter = s);
            var objectUnderTest = new GceInstanceViewModel(
                new GceSourceRootViewModel(Mock.Of <IGceDataSource>()), new Instance {
                Id = 1
            });

            MenuItem logsMenuItem = objectUnderTest.ContextMenu.ItemsSource.OfType <MenuItem>().Single(
                mi => mi.Header as string == Resources.CloudExplorerLaunchLogsViewerMenuHeader);

            logsMenuItem.Command.Execute(null);

            StringAssert.Contains(filter, "resource.type=\"gce_instance\"");
            StringAssert.Contains(filter, "resource.labels.instance_id=\"1\"");
        }
Example #3
0
        protected override void BeforeEach()
        {
            _propertyServiceMock = new Mock <IVsProjectPropertyService>();
            PackageMock.Setup(p => p.GetMefService <IVsProjectPropertyService>()).Returns(_propertyServiceMock.Object);

            _parsedProject = new FakeParsedProject {
                Name = VisualStudioProjectName
            };
            _parsedProject.ProjectMock.Setup(p => p.ConfigurationManager.ConfigurationRowNames).Returns(new string[0]);

            _pickProjectPromptMock = new Mock <Func <Project> >();
            _changedProperties     = new List <string>();

            var mockedApiManager = Mock.Of <IApiManager>(
                x => x.AreServicesEnabledAsync(It.IsAny <IList <string> >()) == Task.FromResult(true) &&
                x.EnableServicesAsync(It.IsAny <IEnumerable <string> >()) == Task.FromResult(true));

            _getClusterListTaskSource = new TaskCompletionSource <IList <Cluster> >();
            var mockedDataSource = Mock.Of <IGkeDataSource>(ds => ds.GetClusterListAsync() == _getClusterListTaskSource.Task);

            _objectUnderTest = new GkeStepViewModel(
                mockedDataSource,
                mockedApiManager,
                _pickProjectPromptMock.Object,
                Mock.Of <IPublishDialog>(pd => pd.Project == _parsedProject));
            _objectUnderTest.PropertyChanged += (sender, args) => _changedProperties.Add(args.PropertyName);
            _objectUnderTest.PublishCommand.CanExecuteChanged += (sender, args) => _canPublishChangedCount++;
            _startProcessMock = new Mock <Func <string, Process> >();
            _objectUnderTest._startProcessOverride = _startProcessMock.Object;
        }
Example #4
0
 protected override void BeforeEach()
 {
     _analyticsOptions = new AnalyticsOptions();
     PackageMock.Setup(p => p.AnalyticsSettings).Returns(_analyticsOptions);
     _promptAnalyticsMock = new Mock <Func <bool> >();
     EventsReporterWrapper.PromptAnalyticsOptIn = _promptAnalyticsMock.Object;
 }
        public void BeforeEach()
        {
            _propertyServiceMock = new Mock <IVsProjectPropertyService>();
            PackageMock.Setup(p => p.GetMefService <IVsProjectPropertyService>()).Returns(_propertyServiceMock.Object);

            var mockedApiManager = Mock.Of <IApiManager>(m =>
                                                         m.AreServicesEnabledAsync(It.IsAny <IList <string> >()) == Task.FromResult(true) &&
                                                         m.EnableServicesAsync(It.IsAny <IEnumerable <string> >()) == Task.FromResult(true));

            PackageMock.Setup(p => p.GetMefService <IApiManager>()).Returns(mockedApiManager);

            _getInstanceListTaskSource = new TaskCompletionSource <IList <Instance> >();
            var mockedDataSource =
                Mock.Of <IGceDataSource>(ds => ds.GetInstanceListAsync() == _getInstanceListTaskSource.Task);

            _windowsCredentialStoreMock  = new Mock <IWindowsCredentialsStore>();
            _manageCredentialsPromptMock = new Mock <Action <Instance> >();

            _mockedProject   = Mock.Of <DteProject>(p => p.ConfigurationManager.ConfigurationRowNames == new string[0]);
            _objectUnderTest = new GceStepViewModel(
                mockedDataSource,
                _windowsCredentialStoreMock.Object,
                _manageCredentialsPromptMock.Object,
                Mock.Of <IPublishDialog>(
                    pd => pd.Project.Name == VisualStudioProjectName && pd.Project.Project == _mockedProject));

            _changedProperties = new List <string>();
            _objectUnderTest.PropertyChanged += (sender, args) => _changedProperties.Add(args.PropertyName);
        }
        public void TestGetRemoteDebuggerPort_Success(string version, int expectedPort)
        {
            PackageMock.Setup(p => p.VsVersion).Returns(version);

            int result = VsVersionUtils.GetRemoteDebuggerPort();

            Assert.AreEqual(expectedPort, result);
        }
        public void TestDefault_DefersToPackage()
        {
            var expectedFactory = Mock.Of <IDataSourceFactory>();

            PackageMock.Setup(p => p.DataSourceFactory).Returns(expectedFactory);

            Assert.AreEqual(expectedFactory, DataSourceFactory.Default);
        }
        public void TestGetToolsPathProvider_GetsVs15Provider()
        {
            PackageMock.Setup(p => p.VsVersion).Returns(VsVersionUtils.VisualStudio2017Version);

            IToolsPathProvider result = VsVersionUtils.GetToolsPathProvider();

            Assert.IsInstanceOfType(result, typeof(GoogleCloudExtension.VsVersion.VS15.ToolsPathProvider));
        }
 public void BeforeEach()
 {
     _getProfileTaskSource  = new TaskCompletionSource <Person>();
     _dataSourceFactoryMock = new Mock <IDataSourceFactory>();
     _dataSourceFactoryMock.Setup(dsf => dsf.CreatePlusDataSource(It.IsAny <GoogleCredential>()).GetProfileAsync())
     .Returns(_getProfileTaskSource.Task);
     PackageMock.Setup(p => p.DataSourceFactory).Returns(_dataSourceFactoryMock.Object);
 }
        protected override void BeforeEach()
        {
            _propertyServiceMock = new Mock <IVsProjectPropertyService>();
            PackageMock.Setup(p => p.GetMefService <IVsProjectPropertyService>()).Returns(_propertyServiceMock.Object);

            _mockedProject       = Mock.Of <Project>();
            _mockedParsedProject = Mock.Of <IParsedDteProject>(p => p.Project == _mockedProject);
        }
Example #11
0
 protected override void BeforeEach()
 {
     _processServiceMock = new Mock <IProcessService>();
     SetupRunCommandResult(true);
     PackageMock.Setup(p => p.ProcessService).Returns(_processServiceMock.Object);
     _objectUnderTest    = new GCloudContext();
     _mockedOutputAction = Mock.Of <Action <string> >();
 }
Example #12
0
        public async Task TestShowToolWindowNoWindowFrame()
        {
            PackageMock.Setup(p => p.FindToolWindow <ToolWindowPane>(true, 0))
            .Returns(new ToolWindowPane {
                Frame = null
            });

            await ToolWindowCommandUtils.ShowToolWindowAsync <ToolWindowPane>();
        }
        protected override void BeforeEach()
        {
            _dteMock = new Mock <DTE>();

            _dteMock.Setup(dte => dte.FullName).Returns(DefaultDevenvPath);

            PackageMock.Setup(p => p.GetService <SDTE, DTE>()).Returns(_dteMock.Object);
            _objectUnderTest = new ToolsPathProvider();
        }
Example #14
0
        public void TestNoLoadWhenMinimized()
        {
            _listLogEntriesSource.SetException(new DataSourceException(""));
            PackageMock.Setup(p => p.IsWindowActive()).Returns(false);

            _objectUnderTest.OnAutoReloadCommand.Execute(null);

            Assert.IsFalse(_objectUnderTest.AsyncAction.IsError);
        }
Example #15
0
 public void BeforeEach()
 {
     _processServiceMock  = new Mock <IProcessService>();
     _versionResultSource = new TaskCompletionSource <CloudSdkVersions>();
     SetupGetJsonOutput("version", _versionResultSource.Task);
     PackageMock.Setup(p => p.ProcessService).Returns(_processServiceMock.Object);
     _objectUnderTest    = new GCloudContext();
     _mockedOutputAction = Mock.Of <Func <string, Task> >();
 }
Example #16
0
        public void TestShowToolWindowNoWindowFrame()
        {
            PackageMock.Setup(p => p.FindToolWindow <ToolWindowPane>(true, 0))
            .Returns(() => new ToolWindowPane {
                Frame = null
            });

            ToolWindowCommandUtils.ShowToolWindow <ToolWindowPane>();
        }
        public void TestInitialConditionsVs2015MissingNetCoreSdk()
        {
            PackageMock.Setup(p => p.VsVersion).Returns(VsVersionUtils.VisualStudio2015Version);

            var objectUnderTest = new AspNetCoreTemplateChooserViewModel(_closeWindowMock.Object);

            Assert.IsTrue(objectUnderTest.NetCoreMissingError);
            Assert.IsFalse(objectUnderTest.OkCommand.CanExecuteCommand);
        }
 public void BeforeEach()
 {
     _targetSdkVersions = new List <string>();
     // ReSharper disable once PossibleUnintendedReferenceComparison
     VsVersionUtils.s_toolsPathProviderOverride =
         Mock.Of <IToolsPathProvider>(tpp => tpp.GetNetCoreSdkVersions() == _targetSdkVersions);
     _closeWindowMock = new Mock <Action>();
     PackageMock.Setup(p => p.VsVersion).Returns(VsVersionUtils.VisualStudio2017Version);
 }
Example #19
0
        public void BeforeEach()
        {
            _browserServiceMock = new Mock <IBrowserService>();

            PackageMock.Setup(p => p.GetMefServiceLazy <IBrowserService>())
            .Returns(_browserServiceMock.ToLazy());

            _objectUnderTest = new AnalyticsOptInWindowViewModel();
        }
        public void BeforeEach()
        {
            _dteMock = new Mock <DTE2>();

            _dteMock.Setup(dte => dte.FullName).Returns(DefaultDevenvPath);

            PackageMock.Setup(p => p.Dte).Returns(_dteMock.Object);
            _objectUnderTest = new ToolsPathProvider();
        }
        public void TestAutoReloadCommandWithWindowMinimized()
        {
            CreateErrorScenario();
            PackageMock.Setup(p => p.IsWindowActive()).Returns(false);

            _objectUnderTest.OnAutoReloadCommand.Execute(null);

            Assert.IsFalse(_objectUnderTest.ShowError);
        }
        public void TestGetAvailableAspNetCoreVersions_ForVS2017NetCore20()
        {
            PackageMock.Setup(p => p.VsVersion).Returns(VsVersionUtils.VisualStudio2017Version);
            _toolsPathProviderMock.Setup(p => p.GetNetCoreSdkVersions()).Returns(new[] { "2.0.35" });

            IList <AspNetVersion> results = AspNetVersion.GetAvailableAspNetCoreVersions(FrameworkType.NetCore);

            CollectionAssert.AreEqual(new[] { AspNetVersion.AspNetCore20 }, results.ToList());
        }
Example #23
0
        protected override void BeforeEach()
        {
            _environmentMock = new Mock <IEnvironment>();

            _environmentMock.Setup(e => e.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86))
            .Returns(DefaultX86ProgramFilesPath);

            PackageMock.Setup(p => p.GetMefServiceLazy <IEnvironment>()).Returns(_environmentMock.ToLazy());
            _objectUnderTest = new ToolsPathProvider();
        }
        public void TestGetToolsPathProvider_ThrowsNotSupportedException()
        {
            const string expectedUnknownVersion = "ExpectedUnknownVersion";

            PackageMock.Setup(p => p.VsVersion).Returns(expectedUnknownVersion);

            var e = Assert.ThrowsException <NotSupportedException>(VsVersionUtils.GetToolsPathProvider);

            StringAssert.Contains(e.Message, expectedUnknownVersion);
        }
 public void BeforeEach()
 {
     _testObject        = null;
     _projectTaskSource = new TaskCompletionSource <IList <Project> >();
     PackageMock.Setup(p => p.DataSourceFactory.ResourceManagerDataSource.ProjectsListTask)
     .Returns(() => _projectTaskSource.Task);
     _properiesChanged            = new List <string>();
     _testObject                  = new PickProjectIdViewModel(DefaultHelpText, false);
     _testObject.PropertyChanged += (sender, args) => _properiesChanged.Add(args.PropertyName);
 }
        public void TestAutoReloadWhenMinimized()
        {
            _objectUnderTest.ShowError = false;
            _getPageOfGroupStatusSource.SetException(new DataSourceException());
            PackageMock.Setup(p => p.IsWindowActive()).Returns(false);

            _objectUnderTest.OnAutoReloadCommand.Execute(null);

            // No API call should be made as the control is off screen
            Assert.IsFalse(_objectUnderTest.ShowError);
        }
Example #27
0
        public void TestShowToolWindowShowError()
        {
            var mockedFrame = Mock.Of <IVsWindowFrame>(f => f.Show() == VSConstants.E_UNEXPECTED);

            PackageMock.Setup(p => p.FindToolWindow <ToolWindowPane>(true, 0))
            .Returns(() => new ToolWindowPane {
                Frame = mockedFrame
            });

            ToolWindowCommandUtils.ShowToolWindow <ToolWindowPane>();
        }
        public void BeforeEach()
        {
            _deployment = new GkeDeployment {
                Metadata = new GkeMetadata {
                    Name = DeploymentName
                }
            };

            _getClusterListTaskSource = new TaskCompletionSource <IList <Cluster> >();
            _getDeploymentsSource     = new TaskCompletionSource <IList <GkeDeployment> >();
            _validateGcloudSource     = new TaskCompletionSource <GCloudValidationResult>();

            _propertyServiceMock = new Mock <IVsProjectPropertyService>();
            _browserServiceMock  = new Mock <IBrowserService>();
            _kubectlContextMock  = new Mock <IKubectlContext>();
            _kubectlContextMock.Setup(kube => kube.GetDeploymentsAsync()).Returns(_getDeploymentsSource.Task);
            _gkeDeploymentServiceMock = new Mock <IGkeDeploymentService>();
            _gkeDeploymentServiceMock
            .Setup(
                s => s.DeployProjectToGkeAsync(
                    It.IsAny <IParsedProject>(),
                    It.IsAny <GkeDeploymentService.Options>()))
            .Returns(Task.CompletedTask);


            PackageMock.Setup(p => p.GetMefService <IGCloudWrapper>().ValidateGCloudAsync(It.IsAny <GCloudComponent>()))
            .Returns(() => _validateGcloudSource.Task);
            PackageMock.Setup(p => p.GetMefService <IVsProjectPropertyService>()).Returns(_propertyServiceMock.Object);
            PackageMock.Setup(p => p.GetMefService <IBrowserService>()).Returns(_browserServiceMock.Object);
            PackageMock.Setup(p => p.GetMefService <IApiManager>()).Returns(Mock.Of <IApiManager>(
                                                                                x => x.AreServicesEnabledAsync(It.IsAny <IList <string> >()) == Task.FromResult(true) &&
                                                                                x.EnableServicesAsync(It.IsAny <IEnumerable <string> >()) == Task.FromResult(true)));
            PackageMock.Setup(p => p.GetMefServiceLazy <IDataSourceFactory>())
            .Returns(
                MockHelpers.LazyOf <IDataSourceFactory>(
                    dsf => dsf.CreateGkeDataSource().GetClusterListAsync() == _getClusterListTaskSource.Task));
            PackageMock.Setup(
                p => p.GetMefService <IKubectlContextProvider>()
                .GetKubectlContextForClusterAsync(It.IsAny <Cluster>()))
            .Returns(_kubectlContextMock.ToTask);
            PackageMock.Setup(p => p.GetMefServiceLazy <IGkeDeploymentService>())
            .Returns(_gkeDeploymentServiceMock.ToLazy);

            _parsedProject = new FakeParsedProject {
                Name = VisualStudioProjectName
            };
            _parsedProject.ProjectMock.Setup(p => p.ConfigurationManager.ConfigurationRowNames).Returns(new string[0]);

            _objectUnderTest = new GkeStepViewModel(Mock.Of <IPublishDialog>(pd => pd.Project == _parsedProject));

            _changedProperties = new List <string>();
            _objectUnderTest.PropertyChanged += (sender, args) => _changedProperties.Add(args.PropertyName);
            _objectUnderTest.PublishCommandAsync.CanExecuteChanged += (sender, args) => _canPublishChangedCount++;
        }
Example #29
0
        public void TestConstructor_NavigatesToPreviousChoice()
        {
            PackageMock.Setup(
                p => p.GetMefService <IVsProjectPropertyService>()
                .GetUserProperty(It.IsAny <Project>(), ChoiceStepViewModel.GoogleCloudPublishChoicePropertyName))
            .Returns(ChoiceType.Gke.ToString);

            var objectUnderTest = new PublishDialogWindowViewModel(_mockedParsedProject, _mockedCloseWindowAction);

            Assert.IsInstanceOfType(objectUnderTest.Content, typeof(GkeStepContent));
        }
        public void TestEnsureAnalyticsOptIn_ShowsPromptWhenDialogNotShown()
        {
            _generalOptions.DialogShown = false;
            _generalOptions.OptIn       = false;
            PackageMock.Setup(p => p.UserPromptService.PromptUser(It.IsAny <AnalyticsOptInWindowContent>()))
            .Returns(true);

            EventsReporterWrapper.EnsureAnalyticsOptIn();

            Assert.IsTrue(_generalOptions.OptIn);
            Assert.IsTrue(_generalOptions.DialogShown);
        }