public void SharedGallery_GetAndList_Tests()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                EnsureClientsInitialized(context);

                SharedGallery sharedGalleryOut = m_CrpClient.SharedGalleries.Get(galleryAccessLocation, GalleryUniqueName);
                Trace.TraceInformation("Got the shared gallery {0} which is shared to current subscription.", GalleryUniqueName);
                Assert.NotNull(sharedGalleryOut);
                ValidateSharedGallery(sharedGalleryOut);


                IPage <SharedGallery> sharedGalleriesList = m_CrpClient.SharedGalleries.List(galleryAccessLocation, "tenant");
                Trace.TraceInformation("Got the shared galleries which are shared to tenant of current subscription.");

                int count = sharedGalleriesList.Count();
                Assert.Equal(1, count);

                foreach (SharedGallery gallery in sharedGalleriesList)
                {
                    if (gallery.Name == GalleryUniqueName)
                    {
                        ValidateSharedGallery(gallery);
                        break;
                    }
                }

                sharedGalleriesList = m_CrpClient.SharedGalleries.List(galleryAccessLocation);

                count = sharedGalleriesList.Count();
                Assert.Equal(1, count);
                Trace.TraceInformation("Got the shared gallery {0} which is shared to current subscription.", GalleryUniqueName);

                ValidateSharedGallery(sharedGalleriesList.First());

                sharedGalleriesList = m_CrpClient.SharedGalleries.List(galleryAccessLocation, sharedTo: SharedToValues.Tenant);

                count = sharedGalleriesList.Count();
                Assert.Equal(1, count);
                Trace.TraceInformation("Got the shared gallery {0} which is shared to current tenant.", GalleryUniqueName);

                ValidateSharedGallery(sharedGalleriesList.First());
            }
        }
        public void SharedGalleryGet()
        {
            if (this.IsParameterBound(c => c.GalleryUniqueName))
            {
                SharedGallery result   = SharedGalleriesClient.Get(this.Location, this.GalleryUniqueName);
                var           psObject = new PSSharedGallery();
                ComputeAutomationAutoMapperProfile.Mapper.Map <SharedGallery, PSSharedGallery>(result, psObject);
                WriteObject(psObject);
            }
            else
            {
                Rest.Azure.IPage <SharedGallery> result = new Page <SharedGallery>();

                if (this.IsParameterBound(c => c.Scope) && this.Scope != "subscription")
                {
                    result = SharedGalleriesClient.List(this.Location, this.Scope);
                }
                else
                {
                    result = SharedGalleriesClient.List(this.Location);
                }

                var resultList   = result.ToList();
                var nextPageLink = result.NextPageLink;
                while (!string.IsNullOrEmpty(nextPageLink))
                {
                    var pageResult = SharedGalleriesClient.ListNext(nextPageLink);
                    foreach (var pageItem in pageResult)
                    {
                        resultList.Add(pageItem);
                    }
                    nextPageLink = pageResult.NextPageLink;
                }
                var psObject = new List <PSSharedGalleryList>();
                foreach (var r in resultList)
                {
                    psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <SharedGallery, PSSharedGalleryList>(r));
                }
                WriteObject(psObject);
            }
        }
Example #3
0
        private void ValidateSharedGallery(SharedGallery sharedGallery)
        {
            string expectedId = "/SharedGalleries/" + GalleryUniqueName;

            Assert.Equal(expectedId, sharedGallery.UniqueId);
        }