/// <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;
            }
        }
        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]);
        }
Exemple #3
0
        public async Task GetProjectsListAsyncTestSinglePage()
        {
            ListProjectsResponse[] responses =
            {
                new ListProjectsResponse(),
                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.GetProjectsListAsync();

            Assert.AreEqual(1, projects.Count);
            Assert.AreEqual(s_someProject, projects[0]);
        }
        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();
        }
Exemple #5
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>());
     }
 }
Exemple #6
0
        public async Task GetProjectsListAsyncTestException()
        {
            _projectsResourceMock.Request(p => p.List()).Response <ListProjectsResponse>().Throws(s_googleApiException);

            await Assert.ThrowsExceptionAsync <DataSourceException>(() => _objectUnderTest.GetProjectsListAsync());
        }