/// <summary>
        /// Return a list of projects. Returns empty list if no item is found.
        /// </summary>
        private async Task <IList <Project> > GetProjectsAsync()
        {
            ResourceManagerDataSource resourceManager = DataSourceFactory.Default.CreateResourceManagerDataSource();

            if (resourceManager == null)
            {
                return(new List <Project>());
            }

            IsReady = false;
            try
            {
                var projects = await resourceManager.GetProjectsListAsync();

                if (!projects.Any())
                {
                    UserPromptUtils.Default.OkPrompt(
                        message: Resources.CsrNoProjectMessage,
                        title: Resources.CsrConnectSectionTitle);
                }
                return(projects);
            }
            finally
            {
                IsReady = true;
            }
        }
Beispiel #2
0
        public async Task RefreshProjects_RestartsProjectsListTask()
        {
            var responses = new[]
            {
                new ListProjectsResponse
                {
                    Projects = new List <Project> {
                        s_someProject, s_disabledProject
                    },
                    NextPageToken = null
                },
                new ListProjectsResponse
                {
                    Projects = new List <Project> {
                        s_aProject
                    },
                    NextPageToken = null
                }
            };
            CloudResourceManagerService service = GetMockedService(
                (CloudResourceManagerService s) => s.Projects,
                p => p.List(),
                responses);
            var dataSource = new ResourceManagerDataSource(null, init => service, null);

            dataSource.RefreshProjects();
            IList <Project> projects = await dataSource.ProjectsListTask;

            Assert.AreEqual(1, projects.Count);
            Assert.AreEqual(s_aProject, projects[0]);
        }
        public async Task GetProjectsListAsyncTestMultiPage()
        {
            var responses = new[]
            {
                new ListProjectsResponse
                {
                    Projects = new List <Project> {
                        s_someProject, s_disabledProject
                    },
                    NextPageToken = "2"
                },
                new ListProjectsResponse
                {
                    Projects = new List <Project> {
                        s_aProject
                    },
                    NextPageToken = null
                }
            };
            CloudResourceManagerService service = GetMockedService(
                (CloudResourceManagerService s) => s.Projects, p => p.List(), responses);
            var dataSource = new ResourceManagerDataSource(null, init => service, null);

            IList <Project> projects = await dataSource.GetProjectsListAsync();

            Assert.AreEqual(3, projects.Count);
            Assert.AreEqual(s_someProject, projects[0]);
            Assert.AreEqual(s_disabledProject, projects[1]);
            Assert.AreEqual(s_aProject, projects[2]);
        }
Beispiel #4
0
        public async Task ProjectsListTask()
        {
            ListProjectsResponse[] responses =
            {
                new ListProjectsResponse
                {
                    Projects = new List <Project>{
                        s_someProject, s_disabledProject
                    },
                    NextPageToken = null
                },
                new ListProjectsResponse
                {
                    Projects = new List <Project>{
                        s_aProject
                    },
                    NextPageToken = null
                }
            };
            _projectsResourceMock.Request(p => p.List()).ResponseReturns(responses);
            _objectUnderTest = new ResourceManagerDataSource(null, init => _serviceMock.Object, null);

            IList <Project> projects = await _objectUnderTest.ProjectsListTask;

            Assert.AreEqual(1, projects.Count);
            Assert.AreEqual(s_someProject, projects[0]);
        }
        public void TestCreateResourceManagerDataSource_ReturnsNullForNoCredentials()
        {
            CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential).Returns(() => null);

            ResourceManagerDataSource result = _objectUnderTest.CreateResourceManagerDataSource();

            Assert.IsNull(result);
        }
        public async Task GetProjectsListAsyncTestException()
        {
            // Empty response list triggers GoogleApiException.
            var responses = new ListProjectsResponse[0];
            CloudResourceManagerService service = GetMockedService(
                (CloudResourceManagerService s) => s.Projects, p => p.List(), responses);
            var dataSource = new ResourceManagerDataSource(null, init => service, null);

            await dataSource.GetProjectsListAsync();
        }
        public async Task GetProjectTestException()
        {
            // Empty response list triggers GoogleApiException.
            var responses = new Project[0];
            CloudResourceManagerService service = GetMockedService(
                (CloudResourceManagerService s) => s.Projects, p => p.Get(It.IsAny <string>()), responses);
            var dataSource = new ResourceManagerDataSource(null, init => service, null);

            await dataSource.GetProjectAsync(SomeProjectId);
        }
Beispiel #8
0
 private async Task <IEnumerable <Project> > LoadCurrentAccountProjectsAsync()
 {
     try
     {
         var dataSource = new ResourceManagerDataSource(
             CurrentGoogleCredential,
             GoogleCloudExtensionPackage.VersionedApplicationName);
         return(await dataSource.GetProjectsListAsync());
     }
     catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
     {
         return(Enumerable.Empty <Project>());
     }
 }
Beispiel #9
0
        protected override void BeforeEach()
        {
            _gPlusDataSourceMock             = new Mock <IGPlusDataSource>();
            _mockedResourceManagerDataSource = null;
            _mockedGPlusDataSource           = null;

            DataSourceFactoryMock.Setup(f => f.CreateResourceManagerDataSource())
            .Returns(() => _mockedResourceManagerDataSource);
            DataSourceFactoryMock.Setup(f => f.CreatePlusDataSource()).Returns(() => _mockedGPlusDataSource);

            _mockedSelectionUtils             = Mock.Of <ISelectionUtils>();
            _objectUnderTest                  = new CloudExplorerViewModel(_mockedSelectionUtils);
            _propertiesChanged                = new SynchronizedCollection <string>();
            _objectUnderTest.PropertyChanged += (sender, args) => _propertiesChanged.Add(args.PropertyName);
        }
        public async Task GetProjectTestSuccess()
        {
            var responses = new[]
            {
                s_someProject
            };
            CloudResourceManagerService service = GetMockedService(
                (CloudResourceManagerService s) => s.Projects, p => p.Get(It.IsAny <string>()), responses);
            var dataSource = new ResourceManagerDataSource(null, init => service, null);

            Project project = await dataSource.GetProjectAsync(SomeProjectId);

            Assert.AreEqual(s_someProject, project);
            Mock <ProjectsResource> projectsResource = Mock.Get(service.Projects);

            projectsResource.Verify(r => r.Get(SomeProjectId), Times.Once);
            projectsResource.Verify(r => r.Get(It.IsNotIn(SomeProjectId)), Times.Never);
        }
        public void TestCreateResourceManagerDataSource_Returns()
        {
            var userAccount = new UserAccount
            {
                AccountName  = "TestAccountName",
                ClientId     = "TestClientId",
                ClientSecret = "TestClientSecret",
                RefreshToken = "TestRefreshToken"
            };

            CredentialStoreMock.SetupGet(cs => cs.CurrentGoogleCredential)
            .Returns(userAccount.GetGoogleCredential());

            ResourceManagerDataSource result = _objectUnderTest.CreateResourceManagerDataSource();

            var googleCredential = (GoogleCredential)result.Service.HttpClientInitializer;
            var userCredential   = (UserCredential)googleCredential.UnderlyingCredential;
            var flow             = (GoogleAuthorizationCodeFlow)userCredential.Flow;

            Assert.AreEqual(userAccount.ClientSecret, flow.ClientSecrets.ClientSecret);
            Assert.AreEqual(userAccount.ClientId, flow.ClientSecrets.ClientId);
            Assert.AreEqual(userAccount.RefreshToken, userCredential.Token.RefreshToken);
            Assert.AreEqual(GoogleCloudExtensionPackage.Instance.VersionedApplicationName, result.Service.ApplicationName);
        }
Beispiel #12
0
 public void BeforeEach()
 {
     _serviceMock          = new Mock <CloudResourceManagerService>();
     _projectsResourceMock = _serviceMock.Resource(s => s.Projects);
     _objectUnderTest      = new ResourceManagerDataSource(null, init => _serviceMock.Object, null);
 }