void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); if (Optional.IsDefined(Permissions)) { writer.WritePropertyName("permissions"); writer.WriteStringValue(Permissions.Value.ToString()); } if (Optional.IsDefined(CommunityGalleryInfo)) { writer.WritePropertyName("communityGalleryInfo"); #if NET6_0_OR_GREATER writer.WriteRawValue(CommunityGalleryInfo); #else JsonSerializer.Serialize(writer, JsonDocument.Parse(CommunityGalleryInfo.ToString()).RootElement); #endif } writer.WriteEndObject(); }
public void Gallery_SharingToCommunity_CRUD_Tests() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); string rgName = ComputeManagementTestUtilities.GenerateName(ResourceGroupPrefix); try { m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup { Location = galleryHomeLocation }); Trace.TraceInformation("Created the resource group: " + rgName); string galleryName = ComputeManagementTestUtilities.GenerateName(GalleryNamePrefix); Gallery galleryIn = GetTestInputCommunityGallery(); m_CrpClient.Galleries.CreateOrUpdate(rgName, galleryName, galleryIn); Trace.TraceInformation(string.Format("Created the community gallery: {0} in resource group: {1} with sharing profile permission: {2}", galleryName, rgName, galleryIn.SharingProfile.Permissions)); Gallery galleryOut = m_CrpClient.Galleries.Get(rgName, galleryName); Trace.TraceInformation("Got the gallery."); Assert.NotNull(galleryOut); ValidateGallery(galleryIn, galleryOut); Assert.NotNull(galleryOut.SharingProfile); Assert.NotNull(galleryOut.SharingProfile.CommunityGalleryInfo); Assert.Equal("Community", galleryOut.SharingProfile.Permissions); Trace.TraceInformation("Enable sharing to the public via post"); SharingUpdate sharingUpdate = new SharingUpdate() { OperationType = SharingUpdateOperationTypes.EnableCommunity }; m_CrpClient.GallerySharingProfile.Update(rgName, galleryName, sharingUpdate); Gallery galleryOutWithSharingProfile = m_CrpClient.Galleries.Get(rgName, galleryName, SelectPermissions.Permissions); Trace.TraceInformation("Got the gallery"); Assert.NotNull(galleryOutWithSharingProfile); CommunityGalleryInfo communityGalleryInfo = JsonConvert.DeserializeObject <CommunityGalleryInfo>(galleryOutWithSharingProfile.SharingProfile.CommunityGalleryInfo.ToString()); Assert.True(communityGalleryInfo.CommunityGalleryEnabled); Trace.TraceInformation("Reset this gallery to private before deleting it."); SharingUpdate resetPrivateUpdate = new SharingUpdate() { OperationType = SharingUpdateOperationTypes.Reset }; m_CrpClient.GallerySharingProfile.Update(rgName, galleryName, resetPrivateUpdate); Trace.TraceInformation("Deleting this gallery."); m_CrpClient.Galleries.Delete(rgName, galleryName); } finally { m_ResourcesClient.ResourceGroups.Delete(rgName); } // resource groups cleanup is taken cared by MockContext.Dispose() method. } }