コード例 #1
0
 /// <summary>
 /// Create a resource.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group. The name is case
 /// insensitive.
 /// </param>
 /// <param name='identity'>
 /// Required. Resource identity.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create or update resource parameters.
 /// </param>
 /// <returns>
 /// Resource information.
 /// </returns>
 public static Task<ResourceCreateOrUpdateResult> CreateOrUpdateAsync(this IResourceOperations operations, string resourceGroupName, ResourceIdentity identity, BasicResource parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, identity, parameters, CancellationToken.None);
 }
コード例 #2
0
        public void SetResourceWithReplaceRewritesResource()
        {
            var originalProperties = new Dictionary<string, object>
                {
                    {"name", "site1"},
                    {"siteMode", "Standard"},
                    {"computeMode", "Dedicated"},
                    {"list", new [] {1,2,3}},
                    {"misc", new Dictionary<string, object>
                        {
                            {"key1", "value1"},
                            {"key2", "value2"}
                        }}};

            var originalPropertiesSerialized = JsonConvert.SerializeObject(originalProperties, new JsonSerializerSettings
            {
                TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
                TypeNameHandling = TypeNameHandling.None
            });

            var patchProperties = new Dictionary<string, object>
                {
                    {"siteMode", "Dedicated"},
                    {"newMode", "NewValue"},
                    {"list", new [] {4,5,6}},
                    {"misc", new Dictionary<string, object>
                        {
                            {"key3", "value3"}
                        }}};

            UpdatePSResourceParameters parameters = new UpdatePSResourceParameters()
            {
                Name = resourceIdentity.ResourceName,
                ParentResource = resourceIdentity.ParentResourcePath,
                PropertyObject = new Hashtable(patchProperties),
                ResourceGroupName = resourceGroupName,
                ResourceType = resourceIdentity.ResourceProviderNamespace + "/" + resourceIdentity.ResourceType
            };

            BasicResource actual = new BasicResource();

            resourceOperationsMock.Setup(f => f.GetAsync(resourceGroupName, It.IsAny<ResourceIdentity>(), It.IsAny<CancellationToken>()))
                .Returns(() => Task.Factory.StartNew(() => new ResourceGetResult
                {
                    StatusCode = HttpStatusCode.OK,
                    Resource = new Resource
                    {
                        Name = parameters.Name,
                        Location = "West US",
                        Properties = originalPropertiesSerialized,
                        ProvisioningState = ProvisioningState.Running,
                    }
                }));

            resourceOperationsMock.Setup(f => f.CreateOrUpdateAsync(resourceGroupName, It.IsAny<ResourceIdentity>(), It.IsAny<BasicResource>(), It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new ResourceCreateOrUpdateResult
                {
                    RequestId = "123",
                    StatusCode = HttpStatusCode.OK,
                    Resource = new Resource
                    {
                        Location = "West US",
                        Properties = originalPropertiesSerialized,
                        ProvisioningState = ProvisioningState.Running
                    }
                }))
                .Callback((string groupName, ResourceIdentity id, BasicResource p, CancellationToken token) => actual = p);

            resourcesClient.UpdatePSResource(parameters);

            JToken actualJson = JToken.Parse(actual.Properties);

            Assert.Null(actualJson["name"]);
            Assert.Equal("Dedicated", actualJson["siteMode"].ToObject<string>());
            Assert.Null(actualJson["computeMode"]);
            Assert.Equal("NewValue", actualJson["newMode"].ToObject<string>());
            Assert.Equal("[4,5,6]", actualJson["list"].ToString(Formatting.None));
            Assert.Null(actualJson["misc"]["key1"]);
            Assert.Null(actualJson["misc"]["key2"]);
            Assert.Equal("value3", actualJson["misc"]["key3"].ToObject<string>());
        }
コード例 #3
0
 /// <summary>
 /// Create a resource.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group. The name is case
 /// insensitive.
 /// </param>
 /// <param name='identity'>
 /// Required. Resource identity.
 /// </param>
 /// <param name='parameters'>
 /// Required. Create or update resource parameters.
 /// </param>
 /// <returns>
 /// Resource information.
 /// </returns>
 public static ResourceCreateOrUpdateResult CreateOrUpdate(this IResourceOperations operations, string resourceGroupName, ResourceIdentity identity, BasicResource parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IResourceOperations)s).CreateOrUpdateAsync(resourceGroupName, identity, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }