/// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Operations                    = new Operations(this);
     AvailabilitySets              = new AvailabilitySetsOperations(this);
     ProximityPlacementGroups      = new ProximityPlacementGroupsOperations(this);
     VirtualMachineExtensionImages = new VirtualMachineExtensionImagesOperations(this);
     VirtualMachineExtensions      = new VirtualMachineExtensionsOperations(this);
     VirtualMachineImages          = new VirtualMachineImagesOperations(this);
     Usage                                 = new UsageOperations(this);
     VirtualMachines                       = new VirtualMachinesOperations(this);
     VirtualMachineSizes                   = new VirtualMachineSizesOperations(this);
     Images                                = new ImagesOperations(this);
     VirtualMachineScaleSets               = new VirtualMachineScaleSetsOperations(this);
     VirtualMachineScaleSetExtensions      = new VirtualMachineScaleSetExtensionsOperations(this);
     VirtualMachineScaleSetRollingUpgrades = new VirtualMachineScaleSetRollingUpgradesOperations(this);
     VirtualMachineScaleSetVMs             = new VirtualMachineScaleSetVMsOperations(this);
     LogAnalytics                          = new LogAnalyticsOperations(this);
     VirtualMachineRunCommands             = new VirtualMachineRunCommandsOperations(this);
     ResourceSkus                          = new ResourceSkusOperations(this);
     Disks                                 = new DisksOperations(this);
     Snapshots                             = new SnapshotsOperations(this);
     Galleries                             = new GalleriesOperations(this);
     GalleryImages                         = new GalleryImagesOperations(this);
     GalleryImageVersions                  = new GalleryImageVersionsOperations(this);
     ContainerServices                     = new ContainerServicesOperations(this);
     BaseUri                               = new System.Uri("https://management.azure.com");
     AcceptLanguage                        = "en-US";
     LongRunningOperationRetryTimeout      = 30;
     GenerateClientRequestId               = true;
     SerializationSettings                 = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
        public async Task GalleryImage_CRUD_Tests()
        {
            EnsureClientsInitialized(LocationEastUs2);
            string rgName = Recording.GenerateAssetName(ResourceGroupPrefix);

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(LocationEastUs2));

            Trace.TraceInformation("Created the resource group: " + rgName);
            string  galleryName = Recording.GenerateAssetName(GalleryNamePrefix);
            Gallery gallery     = GetTestInputGallery();

            await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName, galleryName, gallery));

            Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName, rgName));

            string       galleryImageName  = Recording.GenerateAssetName(GalleryImageNamePrefix);
            GalleryImage inputGalleryImage = GetTestInputGalleryImage();

            await WaitForCompletionAsync(await GalleryImagesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, inputGalleryImage));

            Trace.TraceInformation(string.Format("Created the gallery image: {0} in gallery: {1}", galleryImageName,
                                                 galleryName));

            GalleryImage galleryImageFromGet = await GalleryImagesOperations.GetAsync(rgName, galleryName, galleryImageName);

            Assert.NotNull(galleryImageFromGet);
            ValidateGalleryImage(inputGalleryImage, galleryImageFromGet);

            inputGalleryImage.Description = "Updated description.";
            await WaitForCompletionAsync(await GalleryImagesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, inputGalleryImage));

            Trace.TraceInformation(string.Format("Updated the gallery image: {0} in gallery: {1}", galleryImageName,
                                                 galleryName));
            galleryImageFromGet = await GalleryImagesOperations.GetAsync(rgName, galleryName, galleryImageName);

            Assert.NotNull(galleryImageFromGet);
            ValidateGalleryImage(inputGalleryImage, galleryImageFromGet);

            List <GalleryImage> listGalleryImagesResult = await(GalleryImagesOperations.ListByGalleryAsync(rgName, galleryName)).ToEnumerableAsync();

            Assert.IsTrue(listGalleryImagesResult.Count() == 1);
            //Assert.Single(listGalleryImagesResult);
            //Assert.Null(listGalleryImagesResult.NextPageLink);

            await WaitForCompletionAsync(await GalleryImagesOperations.StartDeleteAsync(rgName, galleryName, galleryImageName));

            listGalleryImagesResult = await(GalleryImagesOperations.ListByGalleryAsync(rgName, galleryName)).ToEnumerableAsync();
            Assert.IsEmpty(listGalleryImagesResult);
            Trace.TraceInformation(string.Format("Deleted the gallery image: {0} in gallery: {1}", galleryImageName,
                                                 galleryName));
            WaitSeconds(30);
            await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName, galleryName));
        }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     ProviderOperations = new ProviderOperations(this);
     GlobalUsers        = new GlobalUsersOperations(this);
     LabAccounts        = new LabAccountsOperations(this);
     Operations         = new Operations(this);
     GalleryImages      = new GalleryImagesOperations(this);
     Labs = new LabsOperations(this);
     EnvironmentSettings = new EnvironmentSettingsOperations(this);
     Environments        = new EnvironmentsOperations(this);
     Users          = new UsersOperations(this);
     BaseUri        = new System.Uri("https://management.azure.com");
     ApiVersion     = "2018-10-15";
     AcceptLanguage = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
        public async Task GalleryImageVersion_CRUD_Tests()
        {
            EnsureClientsInitialized(LocationEastUs2);
            string         rgName    = Recording.GenerateAssetName(ResourceGroupPrefix);
            VirtualMachine vm        = null;
            string         imageName = Recording.GenerateAssetName("psTestSourceImage");

            vm = await CreateCRPImage(rgName, imageName);

            Assert.False(string.IsNullOrEmpty(sourceImageId));
            Trace.TraceInformation(string.Format("Created the source image id: {0}", sourceImageId));

            string  galleryName = Recording.GenerateAssetName(GalleryNamePrefix);
            Gallery gallery     = GetTestInputGallery();

            await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName, galleryName, gallery));

            Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName,
                                                 rgName));
            string       galleryImageName  = Recording.GenerateAssetName(GalleryImageNamePrefix);
            GalleryImage inputGalleryImage = GetTestInputGalleryImage();

            await WaitForCompletionAsync((await GalleryImagesOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName, inputGalleryImage)));

            Trace.TraceInformation(string.Format("Created the gallery image: {0} in gallery: {1}", galleryImageName,
                                                 galleryName));

            string galleryImageVersionName        = "1.0.0";
            GalleryImageVersion inputImageVersion = GetTestInputGalleryImageVersion(sourceImageId);

            await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName,
                                                                                                       galleryImageVersionName, inputImageVersion));

            Trace.TraceInformation(string.Format("Created the gallery image version: {0} in gallery image: {1}",
                                                 galleryImageVersionName, galleryImageName));

            GalleryImageVersion imageVersionFromGet = await GalleryImageVersionsOperations.GetAsync(rgName,
                                                                                                    galleryName, galleryImageName, galleryImageVersionName);

            Assert.NotNull(imageVersionFromGet);
            ValidateGalleryImageVersion(inputImageVersion, imageVersionFromGet);
            imageVersionFromGet = await GalleryImageVersionsOperations.GetAsync(rgName, galleryName, galleryImageName,
                                                                                galleryImageVersionName, ReplicationStatusTypes.ReplicationStatus);

            Assert.AreEqual(StorageAccountType.StandardLRS, imageVersionFromGet.PublishingProfile.StorageAccountType);
            Assert.AreEqual(StorageAccountType.StandardLRS,
                            imageVersionFromGet.PublishingProfile.TargetRegions.First().StorageAccountType);
            Assert.NotNull(imageVersionFromGet.ReplicationStatus);
            Assert.NotNull(imageVersionFromGet.ReplicationStatus.Summary);

            inputImageVersion.PublishingProfile.EndOfLifeDate = Recording.UtcNow.AddDays(100);
            await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryImageName,
                                                                                                       galleryImageVersionName, inputImageVersion));

            Trace.TraceInformation(string.Format("Updated the gallery image version: {0} in gallery image: {1}",
                                                 galleryImageVersionName, galleryImageName));
            imageVersionFromGet = await GalleryImageVersionsOperations.GetAsync(rgName, galleryName,
                                                                                galleryImageName, galleryImageVersionName);

            Assert.NotNull(imageVersionFromGet);
            ValidateGalleryImageVersion(inputImageVersion, imageVersionFromGet);

            Trace.TraceInformation("Listing the gallery image versions");
            List <GalleryImageVersion> listGalleryImageVersionsResult = await(GalleryImageVersionsOperations.
                                                                              ListByGalleryImageAsync(rgName, galleryName, galleryImageName)).ToEnumerableAsync();

            Assert.IsTrue(listGalleryImageVersionsResult.Count() == 1);
            //Assert.Single(listGalleryImageVersionsResult);
            //Assert.Null(listGalleryImageVersionsResult.NextPageLink);

            await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartDeleteAsync(rgName, galleryName, galleryImageName, galleryImageVersionName));

            listGalleryImageVersionsResult = await(GalleryImageVersionsOperations.
                                                   ListByGalleryImageAsync(rgName, galleryName, galleryImageName)).ToEnumerableAsync();
            //Assert.Null(listGalleryImageVersionsResult.NextPageLink);
            Trace.TraceInformation(string.Format("Deleted the gallery image version: {0} in gallery image: {1}",
                                                 galleryImageVersionName, galleryImageName));

            this.WaitMinutes(5);
            await WaitForCompletionAsync(await ImagesOperations.StartDeleteAsync(rgName, imageName));

            Trace.TraceInformation("Deleted the CRP image.");
            await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, vm.Name));

            Trace.TraceInformation("Deleted the virtual machine.");
            await WaitForCompletionAsync(await GalleryImagesOperations.StartDeleteAsync(rgName, galleryName, galleryImageName));

            Trace.TraceInformation("Deleted the gallery image.");
            WaitSeconds(100);
            await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName, galleryName));

            WaitSeconds(100);
            Trace.TraceInformation("Deleted the gallery.");
        }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Operations                    = new Operations(this);
     AvailabilitySets              = new AvailabilitySetsOperations(this);
     ProximityPlacementGroups      = new ProximityPlacementGroupsOperations(this);
     DedicatedHostGroups           = new DedicatedHostGroupsOperations(this);
     DedicatedHosts                = new DedicatedHostsOperations(this);
     SshPublicKeys                 = new SshPublicKeysOperations(this);
     VirtualMachineExtensionImages = new VirtualMachineExtensionImagesOperations(this);
     VirtualMachineExtensions      = new VirtualMachineExtensionsOperations(this);
     VirtualMachineImages          = new VirtualMachineImagesOperations(this);
     VirtualMachineImagesEdgeZone  = new VirtualMachineImagesEdgeZoneOperations(this);
     Usage                                 = new UsageOperations(this);
     VirtualMachines                       = new VirtualMachinesOperations(this);
     VirtualMachineScaleSets               = new VirtualMachineScaleSetsOperations(this);
     VirtualMachineSizes                   = new VirtualMachineSizesOperations(this);
     Images                                = new ImagesOperations(this);
     RestorePointCollections               = new RestorePointCollectionsOperations(this);
     RestorePoints                         = new RestorePointsOperations(this);
     CapacityReservationGroups             = new CapacityReservationGroupsOperations(this);
     CapacityReservations                  = new CapacityReservationsOperations(this);
     VirtualMachineScaleSetExtensions      = new VirtualMachineScaleSetExtensionsOperations(this);
     VirtualMachineScaleSetRollingUpgrades = new VirtualMachineScaleSetRollingUpgradesOperations(this);
     VirtualMachineScaleSetVMExtensions    = new VirtualMachineScaleSetVMExtensionsOperations(this);
     VirtualMachineScaleSetVMs             = new VirtualMachineScaleSetVMsOperations(this);
     LogAnalytics                          = new LogAnalyticsOperations(this);
     VirtualMachineRunCommands             = new VirtualMachineRunCommandsOperations(this);
     VirtualMachineScaleSetVMRunCommands   = new VirtualMachineScaleSetVMRunCommandsOperations(this);
     ResourceSkus                          = new ResourceSkusOperations(this);
     Disks                                 = new DisksOperations(this);
     Snapshots                             = new SnapshotsOperations(this);
     DiskEncryptionSets                    = new DiskEncryptionSetsOperations(this);
     DiskAccesses                          = new DiskAccessesOperations(this);
     DiskRestorePoint                      = new DiskRestorePointOperations(this);
     Galleries                             = new GalleriesOperations(this);
     GalleryImages                         = new GalleryImagesOperations(this);
     GalleryImageVersions                  = new GalleryImageVersionsOperations(this);
     GalleryApplications                   = new GalleryApplicationsOperations(this);
     GalleryApplicationVersions            = new GalleryApplicationVersionsOperations(this);
     GallerySharingProfile                 = new GallerySharingProfileOperations(this);
     SharedGalleries                       = new SharedGalleriesOperations(this);
     SharedGalleryImages                   = new SharedGalleryImagesOperations(this);
     SharedGalleryImageVersions            = new SharedGalleryImageVersionsOperations(this);
     CommunityGalleries                    = new CommunityGalleriesOperations(this);
     CommunityGalleryImages                = new CommunityGalleryImagesOperations(this);
     CommunityGalleryImageVersions         = new CommunityGalleryImageVersionsOperations(this);
     CloudServiceRoleInstances             = new CloudServiceRoleInstancesOperations(this);
     CloudServiceRoles                     = new CloudServiceRolesOperations(this);
     CloudServices                         = new CloudServicesOperations(this);
     CloudServicesUpdateDomain             = new CloudServicesUpdateDomainOperations(this);
     CloudServiceOperatingSystems          = new CloudServiceOperatingSystemsOperations(this);
     DiagnosticOperations                  = new DiagnosticOperations(this);
     DiskInspection                        = new DiskInspectionOperations(this);
     Diagnostics                           = new DiagnosticsOperations(this);
     DiskInspectionStorageConfiguration    = new DiskInspectionStorageConfigurationOperations(this);
     BaseUri                               = new System.Uri("https://management.azure.com");
     AcceptLanguage                        = "en-US";
     LongRunningOperationRetryTimeout      = 30;
     GenerateClientRequestId               = true;
     SerializationSettings                 = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }