public void CreateAndUpdateCommitmentPlan()
        {
            const string TagKey   = "tag1";
            const string TagValue = "value1";

            this.RunAMLCommitmentPlanTestScenario((commitmentPlanName, resourceGroupName, resourcesClient, amlPlansClient) =>
            {
                try
                {
                    // Create and validate the AML commitment plan resource
                    CommitmentPlan inputCommitmentPlan  = new CommitmentPlan(CommitmentPlanTests.DefaultLocation, sku: new ResourceSku(1, CommitmentPlanTests.TestSkuName, CommitmentPlanTests.TestSkuTier));
                    CommitmentPlan outputCommitmentPlan = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroupName, commitmentPlanName).Result.Body;
                    CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroupName, commitmentPlanName, outputCommitmentPlan);

                    // Update the commitment plan
                    outputCommitmentPlan.Tags[TagKey] = TagValue;
                    outputCommitmentPlan = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(outputCommitmentPlan, resourceGroupName, commitmentPlanName).Result.Body;

                    // Validate the change
                    Assert.Equal(1, outputCommitmentPlan.Tags.Count);
                    Assert.Equal(TagValue, outputCommitmentPlan.Tags[TagKey]);
                }
                finally
                {
                    // Remove the commitment plan
                    BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName));
                }
            });
        }
Beispiel #2
0
        public void CreateAndPostOnGraphWebService()
        {
            const string NewRegion = "southcentralus";

            this.RunAMLWebServiceTestScenario((webServiceName, resourceGroupName, resourcesClient, amlServicesClient, cpResourceId, storageAccount) =>
            {
                try
                {
                    // Create and validate the AML service resource
                    var serviceDefinition = WebServiceTests.GetServiceDefinitionFromTestData(this.TestServiceDefinitionFile, cpResourceId, storageAccount);
                    var webService        = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, resourceGroupName, webServiceName);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, webService, serviceDefinition);

                    //Validate that the expected not found exception is thrown before create the regional properties
                    var expectedCloudException = Assert.Throws <CloudException>(() => amlServicesClient.WebServices.Get(resourceGroupName, webServiceName, NewRegion));
                    Assert.NotNull(expectedCloudException.Body);
                    Assert.Equal("NotFound", expectedCloudException.Body.Code);

                    // Submit some updates to this resource
                    amlServicesClient.WebServices.CreateRegionalPropertiesWithRequestId(resourceGroupName, webServiceName, NewRegion);

                    // Retrieve the AML web service after POST
                    var retrievedService = amlServicesClient.WebServices.Get(resourceGroupName, webServiceName, NewRegion);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, retrievedService);
                    Assert.NotNull(retrievedService.Properties);
                    var properties = retrievedService.Properties as WebServicePropertiesForGraph;
                    Assert.NotNull(properties);
                    Assert.NotNull(properties.Package);
                    Assert.NotNull(properties.Package.Nodes);
                    Assert.NotNull(properties.Package.Nodes["node1"]);
                    Assert.NotNull(properties.Package.Nodes["node1"].Parameters);
                    Assert.NotNull(properties.Package.Nodes["node1"].Parameters["Account Key"]);

                    WebServiceParameter param = properties.Package.Nodes["node1"].Parameters["Account Key"];

                    string expectedThumbprint = "ONE_THUMBPRINT";
                    Assert.Equal(expectedThumbprint, param.CertificateThumbprint);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Caught unexpected exception: ");
                    Trace.TraceError(ex.Message);

                    throw;
                }
                finally
                {
                    // Remove the web service
                    BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName));
                }
            });
        }
Beispiel #3
0
        public void CreateGetRemoveGraphWebService()
        {
            this.RunAMLWebServiceTestScenario((webServiceName, resourceGroupName, resourcesClient, amlServicesClient, cpResourceId, storageAccount) =>
            {
                bool serviceWasRemoved = false;
                try
                {
                    //Validate expected NO-OP behavior on deleting a non existing service
                    amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName);

                    // Create and validate the AML service resource
                    var serviceDefinition = WebServiceTests.GetServiceDefinitionFromTestData(this.TestServiceDefinitionFile, cpResourceId, storageAccount);
                    var webService        = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, resourceGroupName, webServiceName);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, webService, serviceDefinition);

                    // Retrieve the AML web service after creation
                    var retrievedService = amlServicesClient.WebServices.Get(resourceGroupName, webServiceName);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, retrievedService);

                    // Retrieve the AML web service's keys
                    WebServiceKeys serviceKeys = amlServicesClient.WebServices.ListKeys(resourceGroupName, webServiceName);
                    Assert.NotNull(serviceKeys);
                    Assert.Equal(serviceKeys.Primary, serviceDefinition.Properties.Keys.Primary);
                    Assert.Equal(serviceKeys.Secondary, serviceDefinition.Properties.Keys.Secondary);

                    // Remove the web service
                    amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName);
                    serviceWasRemoved = true;

                    //Validate that the expected not found exception is thrown after deletion when trying to access the service
                    var expectedCloudException = Assert.Throws <CloudException>(() => amlServicesClient.WebServices.Get(resourceGroupName, webServiceName));
                    Assert.NotNull(expectedCloudException.Body);
                    Assert.Equal("NotFound", expectedCloudException.Body.Code);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Caught unexpected exception: ");
                    Trace.TraceError(ex.Message);

                    throw;
                }
                finally
                {
                    // Remove the web service
                    if (!serviceWasRemoved)
                    {
                        BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName));
                    }
                }
            });
        }
Beispiel #4
0
        public void CreateAndUpdateOnGraphWebService()
        {
            this.RunAMLWebServiceTestScenario((webServiceName, resourceGroupName, resourcesClient, amlServicesClient, cpResourceId, storageAccount) =>
            {
                try
                {
                    // Create and validate the AML service resource
                    var serviceDefinition = WebServiceTests.GetServiceDefinitionFromTestData(this.TestServiceDefinitionFile, cpResourceId, storageAccount);
                    var webService        = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, resourceGroupName, webServiceName);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, webService, serviceDefinition);

                    // Submit some updates to this resource
                    var serviceUpdates = new WebService
                    {
                        Properties = new WebServicePropertiesForGraph
                        {
                            Description = "description was updated!",
                            Keys        = new WebServiceKeys("f6ae3d003c63457ab4c5997effb5e4dc"),
                            Diagnostics = new DiagnosticsConfiguration(DiagnosticsLevel.All)
                        }
                    };
                    var updatedWebService = amlServicesClient.WebServices.PatchWithRequestId(serviceUpdates, resourceGroupName, webServiceName);

                    // Validate the updated resource
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, updatedWebService);
                    Assert.Equal(serviceUpdates.Properties.Description, updatedWebService.Properties.Description);
                    Assert.NotNull(updatedWebService.Properties.Diagnostics);
                    Assert.Equal(serviceUpdates.Properties.Diagnostics.Level, updatedWebService.Properties.Diagnostics.Level);
                    Assert.True(updatedWebService.Properties.ModifiedOn.Value.CompareTo(webService.Properties.ModifiedOn.Value) > 0);

                    // Also fetch the service keys and validate the update there
                    WebServiceKeys serviceKeys = amlServicesClient.WebServices.ListKeys(resourceGroupName, webServiceName);
                    Assert.NotNull(serviceKeys);
                    Assert.Equal(serviceKeys.Primary, serviceUpdates.Properties.Keys.Primary);
                    Assert.Equal(serviceKeys.Secondary, serviceDefinition.Properties.Keys.Secondary);
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Caught unexpected exception: ");
                    Trace.TraceError(ex.Message);

                    throw;
                }
                finally
                {
                    // Remove the web service
                    BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName));
                }
            });
        }
        private void RunAMLCommitmentPlanTestScenario(AMLCommitmentPlanTestDelegate actualTest,
                                                      [System.Runtime.CompilerServices.CallerMemberName]
                                                      string methodName = "testframework_failed")
        {
            using (var context = MockContext.Start(this.GetType().FullName, methodName))
            {
                bool   testIsSuccessfull = true;
                string cpRpApiVersion    = string.Empty;
                ResourceManagementClient resourcesClient = null;

                var commitmentPlanName = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix);
                var resourceGroupName  = TestUtilities.GenerateName(CommitmentPlanTests.TestResourceGroupNamePrefix);

                try
                {
                    // Create a resource group for the AML commitment plan
                    resourcesClient = context.GetServiceClient <ResourceManagementClient>();
                    var resourceGroupDefinition = new ResourceGroup
                    {
                        Location = CommitmentPlanTests.DefaultLocation
                    };
                    resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, resourceGroupDefinition);

                    // Create a client for the AML RP and run the actual test
                    var commitmentPlansClient = context.GetServiceClient <AzureMLCommitmentPlansManagementClient>();

                    // Run the actual test
                    actualTest(commitmentPlanName, resourceGroupName, resourcesClient, commitmentPlansClient);
                }
                catch (CloudException cloudEx)
                {
                    Trace.TraceError("Caught unexpected exception: ");
                    Trace.TraceError(BaseScenarioTests.GenerateCloudExceptionReport(cloudEx));
                    testIsSuccessfull = false;
                }
                finally
                {
                    if (resourcesClient != null)
                    {
                        // Delete the created resource group
                        BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroupName));
                    }
                }
                Assert.True(testIsSuccessfull);
            }
        }
        public void CreateGetRemoveCommitmentPlan()
        {
            this.RunAMLCommitmentPlanTestScenario((commitmentPlanName, resourceGroupName, resourcesClient, amlPlansClient) =>
            {
                bool planWasRemoved = false;
                try
                {
                    //Validate expected NO-OP behavior on deleting a nonexistent plan
                    amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName);

                    // Create and validate the AML commitment plan resource
                    CommitmentPlan inputCommitmentPlan  = new CommitmentPlan(CommitmentPlanTests.DefaultLocation, sku: new ResourceSku(1, CommitmentPlanTests.TestSkuName, CommitmentPlanTests.TestSkuTier));
                    CommitmentPlan outputCommitmentPlan = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroupName, commitmentPlanName).Result.Body;
                    CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroupName, commitmentPlanName, outputCommitmentPlan);

                    // Retrieve the AML commitment plan after creation
                    var retrievedPlan = amlPlansClient.CommitmentPlans.Get(resourceGroupName, commitmentPlanName);
                    CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroupName, commitmentPlanName, retrievedPlan);

                    // Remove the commitment plan
                    amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName).Wait();
                    planWasRemoved = true;

                    //Validate that the expected not found exception is thrown after deletion when trying to access the commitment plan
                    var expectedCloudException = Assert.Throws <CloudException>(() => amlPlansClient.CommitmentPlans.Get(resourceGroupName, commitmentPlanName));
                    Assert.NotNull(expectedCloudException.Body);
                    Assert.Equal("ResourceNotFound", expectedCloudException.Body.Code);
                }
                finally
                {
                    // Remove the commitment plan
                    if (!planWasRemoved)
                    {
                        BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroupName, commitmentPlanName));
                    }
                }
            });
        }
        public void CreateAndListCommitmentPlans()
        {
            this.RunAMLCommitmentPlanTestScenario((commitmentPlanName, resourceGroupName, resourcesClient, amlPlansClient) =>
            {
                string plan1Name = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix);
                string plan2Name = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix);
                string plan3Name = TestUtilities.GenerateName(CommitmentPlanTests.TestPlanNamePrefix);

                string resourceGroup1Name = TestUtilities.GenerateName(CommitmentPlanTests.TestResourceGroupNamePrefix);
                string resourceGroup2Name = TestUtilities.GenerateName(CommitmentPlanTests.TestResourceGroupNamePrefix);

                try
                {
                    ResourceSku sku = new ResourceSku(1, CommitmentPlanTests.TestSkuName, CommitmentPlanTests.TestSkuTier);
                    CommitmentPlan inputCommitmentPlan = new CommitmentPlan(CommitmentPlanTests.DefaultLocation, sku: sku);

                    // Create two commitment plans in the first resource group
                    resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroup1Name, new ResourceGroup {
                        Location = CommitmentPlanTests.DefaultLocation
                    });

                    CommitmentPlan outputCommitmentPlan1 = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroup1Name, plan1Name).Result.Body;
                    CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroup1Name, plan1Name, outputCommitmentPlan1);

                    CommitmentPlan outputCommitmentPlan2 = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroup1Name, plan2Name).Result.Body;
                    CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroup1Name, plan2Name, outputCommitmentPlan2);

                    // Create one commitment plan in the second resource group
                    resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroup2Name, new ResourceGroup {
                        Location = CommitmentPlanTests.DefaultLocation
                    });

                    CommitmentPlan outputCommitmentPlan3 = amlPlansClient.CommitmentPlans.CreateOrUpdateWithHttpMessagesAsync(inputCommitmentPlan, resourceGroup2Name, plan3Name).Result.Body;
                    CommitmentPlanTests.ValidateCommitmentPlanResource(amlPlansClient.SubscriptionId, resourceGroup2Name, plan3Name, outputCommitmentPlan3);

                    // Get plans from first resource group and validate
                    var plansInGroup1 = amlPlansClient.CommitmentPlans.ListInResourceGroup(resourceGroup1Name);

                    Assert.NotNull(plansInGroup1);
                    Assert.Equal(2, plansInGroup1.Count());

                    string expectedResourceId1 = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, amlPlansClient.SubscriptionId, resourceGroup1Name, plan1Name);
                    Assert.Contains(plansInGroup1, plan => string.Equals(plan.Id, expectedResourceId1, StringComparison.OrdinalIgnoreCase));

                    string expectedResourceId2 = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, amlPlansClient.SubscriptionId, resourceGroup1Name, plan2Name);
                    Assert.Contains(plansInGroup1, plan => string.Equals(plan.Id, expectedResourceId2, StringComparison.OrdinalIgnoreCase));

                    // Get plans from second resource group and validate
                    var plansInGroup2 = amlPlansClient.CommitmentPlans.ListInResourceGroup(resourceGroup2Name);

                    Assert.NotNull(plansInGroup2);
                    Assert.Single(plansInGroup2);

                    string expectedResourceId3 = string.Format(CultureInfo.InvariantCulture, CommitmentPlanTests.ResourceIdFormat, amlPlansClient.SubscriptionId, resourceGroup2Name, plan3Name);
                    Assert.Contains(plansInGroup2, plan => string.Equals(plan.Id, expectedResourceId3, StringComparison.OrdinalIgnoreCase));
                }
                finally
                {
                    // Delete plans and resource groups
                    BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroup1Name, plan1Name));
                    BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroup1Name, plan2Name));
                    BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroup1Name));

                    BaseScenarioTests.DisposeOfTestResource(() => amlPlansClient.CommitmentPlans.RemoveWithHttpMessagesAsync(resourceGroup2Name, plan3Name));
                    BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroup2Name));
                }
            });
        }
Beispiel #8
0
        private void RunAMLWebServiceTestScenario(AMLWebServiceTestDelegate actualTest,
                                                  [System.Runtime.CompilerServices.CallerMemberName]
                                                  string methodName = "testframework_failed")
        {
            using (var context = MockContext.Start(this.GetType(), methodName))
            {
                bool   testIsSuccessfull = true;
                string cpRpApiVersion    = string.Empty;
                ResourceManagementClient resourcesClient         = null;
                StorageManagementClient  storageManagementClient = null;

                var amlServiceName     = TestUtilities.GenerateName(WebServiceTests.TestServiceNamePrefix);
                var resourceGroupName  = TestUtilities.GenerateName(WebServiceTests.TestResourceGroupNamePrefix);
                var commitmentPlanName = TestUtilities.GenerateName(WebServiceTests.TestCommitmentPlanNamePrefix);
                var cpDeploymentName   = "depl" + commitmentPlanName;
                var storageAccountName = TestUtilities.GenerateName(WebServiceTests.TestStorageAccountPrefix);

                try
                {
                    // Create a resource group for the AML service
                    resourcesClient = context.GetServiceClient <ResourceManagementClient>();
                    var resourceGroupDefinition = new ResourceGroup
                    {
                        Location = WebServiceTests.DefaultLocation
                    };
                    resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, resourceGroupDefinition);

                    // Create a support storage account for the service in this resource group
                    storageManagementClient = context.GetServiceClient <StorageManagementClient>();
                    var accountParameters = new StorageAccountCreateParameters
                    {
                        AccountType = AccountType.StandardLRS,
                        Location    = WebServiceTests.DefaultLocation
                    };
                    storageManagementClient.StorageAccounts.Create(resourceGroupName, storageAccountName, accountParameters);
                    StorageAccountKeys accountKeys = storageManagementClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName);
                    var storageAccountInfo         = new StorageAccount(storageAccountName, accountKeys.Key1);

                    // Create an AML commitment plan resource to associate with the services
                    cpRpApiVersion = ResourceProvidersHelper.GetRPApiVersion(resourcesClient, WebServiceTests.MLResourceProviderNamespace, WebServiceTests.CPResourceType);
                    var cpDeploymentItems = WebServiceTests.CreateCommitmentPlanResource(resourceGroupName, commitmentPlanName, cpDeploymentName, resourcesClient, cpRpApiVersion);
                    var cpResource        = cpDeploymentItems.Item2;

                    // Create a client for the AML RP and run the actual test
                    var webServicesClient = context.GetServiceClient <AzureMLWebServicesManagementClient>();

                    // Run the actual test
                    actualTest(amlServiceName, resourceGroupName, resourcesClient, webServicesClient, cpResource.Id, storageAccountInfo);
                }
                catch (CloudException cloudEx)
                {
                    Trace.TraceError("Caught unexpected exception: ");
                    Trace.TraceError(BaseScenarioTests.GenerateCloudExceptionReport(cloudEx));
                    testIsSuccessfull = false;
                }
                finally
                {
                    if (resourcesClient != null)
                    {
                        // Delete the deployment with the commitment plan
                        if (cpRpApiVersion != string.Empty)
                        {
                            BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.Resources.Delete(resourceGroupName, WebServiceTests.MLResourceProviderNamespace, string.Empty, WebServiceTests.CPResourceType, commitmentPlanName, cpRpApiVersion));
                            BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.Deployments.Delete(resourceGroupName, cpDeploymentName));
                        }

                        // Delete the created storage account
                        BaseScenarioTests.DisposeOfTestResource(() => storageManagementClient.StorageAccounts.Delete(resourceGroupName, storageAccountName));

                        // Delete the created resource group
                        BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(resourceGroupName));
                    }
                }
                Assert.True(testIsSuccessfull);
            }
        }
Beispiel #9
0
        public void CreateAndListWebServices()
        {
            this.RunAMLWebServiceTestScenario((webServiceName, resourceGroupName, resourcesClient, amlServicesClient, cpResourceId, storageAccount) =>
            {
                string service2Name        = TestUtilities.GenerateName(WebServiceTests.TestServiceNamePrefix);
                string service3Name        = TestUtilities.GenerateName(WebServiceTests.TestServiceNamePrefix);
                var otherResourceGroupName = TestUtilities.GenerateName(WebServiceTests.TestResourceGroupNamePrefix);
                var otherServiceName       = TestUtilities.GenerateName(WebServiceTests.TestServiceNamePrefix);

                try
                {
                    // Create a few webservices in the same resource group
                    var serviceDefinition = WebServiceTests.GetServiceDefinitionFromTestData(this.TestServiceDefinitionFile, cpResourceId, storageAccount);
                    var webService1       = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, resourceGroupName, webServiceName);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, webServiceName, webService1, serviceDefinition);
                    var webService2 = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, resourceGroupName, service2Name);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, service2Name, webService2, serviceDefinition);
                    var webService3 = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, resourceGroupName, service3Name);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, resourceGroupName, service3Name, webService3, serviceDefinition);

                    // Create a new web service in a different resource group
                    resourcesClient.ResourceGroups.CreateOrUpdate(otherResourceGroupName, new ResourceGroup {
                        Location = WebServiceTests.DefaultLocation
                    });
                    var otherService = amlServicesClient.WebServices.CreateOrUpdateWithRequestId(serviceDefinition, otherResourceGroupName, otherServiceName);
                    WebServiceTests.ValidateWebServiceResource(amlServicesClient.SubscriptionId, otherResourceGroupName, otherServiceName, otherService, serviceDefinition);

                    // Validate that only the first 3 services are returned on the get call for web services in a subscription & resource group
                    var servicesInGroup = amlServicesClient.WebServices.ListByResourceGroup(resourceGroupName);
                    Assert.NotNull(servicesInGroup);
                    IList <WebService> servicesList = servicesInGroup.ToList();
                    Assert.NotNull(servicesList);
                    Assert.Equal(3, servicesList.Count);
                    string service1ExpectedId = string.Format(CultureInfo.InvariantCulture, WebServiceTests.ResourceIdFormat, amlServicesClient.SubscriptionId, resourceGroupName, webServiceName);
                    string service2ExpectedId = string.Format(CultureInfo.InvariantCulture, WebServiceTests.ResourceIdFormat, amlServicesClient.SubscriptionId, resourceGroupName, service2Name);
                    string service3ExpectedId = string.Format(CultureInfo.InvariantCulture, WebServiceTests.ResourceIdFormat, amlServicesClient.SubscriptionId, resourceGroupName, service3Name);
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, service1ExpectedId, StringComparison.OrdinalIgnoreCase));
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, service2ExpectedId, StringComparison.OrdinalIgnoreCase));
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, service3ExpectedId, StringComparison.OrdinalIgnoreCase));

                    // Validate that all services are called when getting the AML service resource list for the subscription
                    var servicesInSubscription = amlServicesClient.WebServices.ListBySubscriptionIdWithHttpMessagesAsync().Result;
                    Assert.NotNull(servicesInSubscription);
                    servicesList = servicesInSubscription.Body.ToList();
                    Assert.NotNull(servicesList);
                    Assert.True(servicesList.Count >= 4);
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, service1ExpectedId, StringComparison.OrdinalIgnoreCase));
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, service2ExpectedId, StringComparison.OrdinalIgnoreCase));
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, service3ExpectedId, StringComparison.OrdinalIgnoreCase));
                    string otherServiceExpectedId = string.Format(CultureInfo.InvariantCulture, WebServiceTests.ResourceIdFormat, amlServicesClient.SubscriptionId, otherResourceGroupName, otherServiceName);
                    Assert.Contains(servicesList, svc => string.Equals(svc.Id, otherServiceExpectedId, StringComparison.OrdinalIgnoreCase));
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Caught unexpected exception: ");
                    Trace.TraceError(ex.Message);

                    throw;
                }
                finally
                {
                    // Remove the resources created by the test
                    BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName));
                    BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, service2Name));
                    BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, service3Name));
                    BaseScenarioTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(otherResourceGroupName, otherServiceName));
                    BaseScenarioTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(otherResourceGroupName));
                }
            });
        }