Esempio n. 1
0
        public void SharedGalleryImage_GetAndList_Tests()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                EnsureClientsInitialized(context);

                SharedGalleryImage sharedGalleryImageOut = m_CrpClient.SharedGalleryImages.Get(galleryAccessLocation, GalleryUniqueName, GalleryImageName);
                Trace.TraceInformation("Got the shared gallery image {0} which is shared to current subscription.", GalleryImageName);
                Assert.NotNull(sharedGalleryImageOut);

                ValidateSharedGalleryImage(sharedGalleryImageOut);


                IPage <SharedGalleryImage> sharedGalleryImagesList = m_CrpClient.SharedGalleryImages.List(galleryAccessLocation, GalleryUniqueName, "tenant");
                Trace.TraceInformation("Got the shared gallery images which are shared to tenant of current subscription.");

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

                foreach (SharedGalleryImage galleryImage in sharedGalleryImagesList)
                {
                    if (galleryImage.Name == GalleryImageName)
                    {
                        ValidateSharedGalleryImage(galleryImage);
                        break;
                    }
                }

                sharedGalleryImagesList = m_CrpClient.SharedGalleryImages.List(galleryAccessLocation, GalleryUniqueName);

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

                ValidateSharedGalleryImage(sharedGalleryImagesList.First());

                sharedGalleryImagesList = m_CrpClient.SharedGalleryImages.List(galleryAccessLocation, GalleryUniqueName, sharedTo: SharedToValues.Tenant);

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

                ValidateSharedGalleryImage(sharedGalleryImagesList.First());
            }
        }
        public void SharedGalleryGet()
        {
            if (this.IsParameterBound(c => c.Name))
            {
                SharedGalleryImage result = SharedGalleryImagesClient.Get(this.Location, this.GalleryUniqueName, this.Name);
                var psObject = new PSSharedGalleryImage();
                ComputeAutomationAutoMapperProfile.Mapper.Map <SharedGalleryImage, PSSharedGalleryImage>(result, psObject);
                WriteObject(psObject);
            }
            else
            {
                Rest.Azure.IPage <SharedGalleryImage> result = new Page <SharedGalleryImage>();

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

                var resultList   = result.ToList();
                var nextPageLink = result.NextPageLink;
                while (!string.IsNullOrEmpty(nextPageLink))
                {
                    var pageResult = SharedGalleryImagesClient.ListNext(nextPageLink);
                    foreach (var pageItem in pageResult)
                    {
                        resultList.Add(pageItem);
                    }
                    nextPageLink = pageResult.NextPageLink;
                }
                var psObject = new List <PSSharedGalleryImageList>();
                foreach (var r in resultList)
                {
                    psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <SharedGalleryImage, PSSharedGalleryImageList>(r));
                }
                WriteObject(psObject);
            }
        }
Esempio n. 3
0
        private void ValidateSharedGalleryImage(SharedGalleryImage sharedGalleryImage)
        {
            string expectedId = "/SharedGalleries/" + GalleryUniqueName + "/Images/" + GalleryImageName;

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