public void CanCreateUpdateDeleteLinkedService()
        {
            BasicDelegatingHandler handler = new BasicDelegatingHandler();

            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();

                var client = TestHelper.GetOperationalInsightsManagementClient(handler);
                var subId = client.Credentials.SubscriptionId;
               
                var linkedServiceName = "Automation";
                var accountResourceIdFromat = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Automation/automationAccounts/{2}";
                var accountResourceId = string.Format(accountResourceIdFromat, subId, resourceGroupName, automationAccountName);
                
                // Create a linked service
                var createParameters = new LinkedServiceCreateOrUpdateParameters
                {
                    Name = linkedServiceName,
                    Properties = new LinkedServiceProperties() { ResourceId = accountResourceId }
                };
                var createResponse = client.LinkedServices.CreateOrUpdate(resourceGroupName, workspaceName, createParameters);
                Assert.True(HttpStatusCode.Created == createResponse.StatusCode || HttpStatusCode.OK == createResponse.StatusCode);
                TestHelper.ValidateLinkedService(createParameters, createResponse.LinkedService);

                // Get the linked service
                var getResponse = client.LinkedServices.Get(resourceGroupName, workspaceName, linkedServiceName);
                Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
                TestHelper.ValidateLinkedService(createParameters, getResponse.LinkedService);

                // List the linked services in the workspace
                var listResponse = client.LinkedServices.List(resourceGroupName, workspaceName);
                Assert.True(HttpStatusCode.OK == listResponse.StatusCode);
                Assert.Equal(1, listResponse.LinkedServices.Count);
                Assert.Null(listResponse.NextLink);
                Assert.Single(listResponse.LinkedServices.Where(w => w.Properties.ResourceId.Equals(accountResourceId, StringComparison.OrdinalIgnoreCase)));

                var accountResourceId2 = string.Format(accountResourceIdFromat, subId, resourceGroupName, automationAccountName2);
                var updateParameters = new LinkedServiceCreateOrUpdateParameters
                {
                    Name = linkedServiceName,
                    Properties = new LinkedServiceProperties() { ResourceId = accountResourceId2 }
                };

                // Perform an update on one of the linked service
                var updateResponse = client.LinkedServices.CreateOrUpdate(resourceGroupName, workspaceName, updateParameters);
                Assert.True(HttpStatusCode.OK == updateResponse.StatusCode);
                TestHelper.ValidateLinkedService(updateParameters, updateResponse.LinkedService);

                // Delete a linked service
                var deleteResponse = client.LinkedServices.Delete(resourceGroupName, workspaceName, linkedServiceName);
                Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);

                // Verify the linkedService source is gone
                getResponse = client.LinkedServices.Get(resourceGroupName, workspaceName, linkedServiceName);
                Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
                Assert.Null(getResponse.LinkedService);
            }
        }
 /// <summary>
 /// Create or update a linked service.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.OperationalInsights.ILinkedServiceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The resource group name of the linked service.
 /// </param>
 /// <param name='workspaceName'>
 /// Required. The name of the parent workspace that will contain the
 /// linked service
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters required to create or update a linked
 /// service.
 /// </param>
 /// <returns>
 /// The create or update linked service operation response.
 /// </returns>
 public static LinkedServiceCreateOrUpdateResponse CreateOrUpdate(this ILinkedServiceOperations operations, string resourceGroupName, string workspaceName, LinkedServiceCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ILinkedServiceOperations)s).CreateOrUpdateAsync(resourceGroupName, workspaceName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Create or update a linked service.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.OperationalInsights.ILinkedServiceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The resource group name of the linked service.
 /// </param>
 /// <param name='workspaceName'>
 /// Required. The name of the parent workspace that will contain the
 /// linked service
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters required to create or update a linked
 /// service.
 /// </param>
 /// <returns>
 /// The create or update linked service operation response.
 /// </returns>
 public static Task<LinkedServiceCreateOrUpdateResponse> CreateOrUpdateAsync(this ILinkedServiceOperations operations, string resourceGroupName, string workspaceName, LinkedServiceCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, workspaceName, parameters, CancellationToken.None);
 }
Пример #4
0
        /// <summary>
        /// Validates a linked service matches the expected properties. Throws assertion exceptions if validation fails.
        /// </summary>
        /// <param name="expected">Expected linked service</param>
        /// <param name="actual">Actual linked service</param>
        internal static void ValidateLinkedService(LinkedServiceCreateOrUpdateParameters expected, LinkedService actual)
        {
            Assert.NotNull(actual);
            Assert.NotNull(actual.Id);
            Assert.Equal(LinkedServiceResourceType.ToLower(), actual.Type.ToLower());

            Assert.NotNull(actual.Properties);
            Assert.Equal(expected.Properties.ResourceId.ToLower(), actual.Properties.ResourceId.ToLower());
        }
        public void LinkedServiceCreateFailsWithoutWorkspace()
        {
            BasicDelegatingHandler handler = new BasicDelegatingHandler();
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var client = TestHelper.GetOperationalInsightsManagementClient(handler);
                var subId = client.Credentials.SubscriptionId;

                string linkedServiceName = "Automation";
                string workspaceName = TestUtilities.GenerateName("AzSDKTest");

                var accountResourceIdFromat = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Automation/automationAccounts/{2}";
                var accountResourceId = string.Format(accountResourceIdFromat, subId, resourceGroupName, "testAccount");

                var createParameters = new LinkedServiceCreateOrUpdateParameters
                {
                    Name = linkedServiceName,
                    Properties = new LinkedServiceProperties() { ResourceId = accountResourceId }
                };

                // Create a linked service on a non-existent workspace
                TestHelper.VerifyCloudException(HttpStatusCode.NotFound, () => client.LinkedServices.CreateOrUpdate(resourceGroupName, workspaceName, createParameters));
            }
        }