Example #1
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));
                }
            });
        }
Example #2
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));
                    }
                }
            });
        }
Example #3
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));
                }
            });
        }
Example #4
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.ListInResourceGroup(resourceGroupName);
                    Assert.NotNull(servicesInGroup);
                    IList <WebService> servicesList = servicesInGroup.Value;
                    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.True(servicesList.Any(svc => string.Equals(svc.Id, service1ExpectedId, StringComparison.OrdinalIgnoreCase)));
                    Assert.True(servicesList.Any(svc => string.Equals(svc.Id, service2ExpectedId, StringComparison.OrdinalIgnoreCase)));
                    Assert.True(servicesList.Any(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.List();
                    Assert.NotNull(servicesInSubscription);
                    servicesList = servicesInSubscription.Value;
                    Assert.NotNull(servicesList);
                    Assert.True(servicesList.Count >= 4);
                    Assert.True(servicesList.Any(svc => string.Equals(svc.Id, service1ExpectedId, StringComparison.OrdinalIgnoreCase)));
                    Assert.True(servicesList.Any(svc => string.Equals(svc.Id, service2ExpectedId, StringComparison.OrdinalIgnoreCase)));
                    Assert.True(servicesList.Any(svc => string.Equals(svc.Id, service3ExpectedId, StringComparison.OrdinalIgnoreCase)));
                    string otherServiceExpectedId = string.Format(CultureInfo.InvariantCulture, WebServiceTests.ResourceIdFormat, amlServicesClient.SubscriptionId, otherResourceGroupName, otherServiceName);
                    Assert.True(servicesList.Any(svc => string.Equals(svc.Id, otherServiceExpectedId, StringComparison.OrdinalIgnoreCase)));
                }
                finally
                {
                    // Remove the resources created by the test
                    WebServiceTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, webServiceName));
                    WebServiceTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, service2Name));
                    WebServiceTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(resourceGroupName, service3Name));
                    WebServiceTests.DisposeOfTestResource(() => amlServicesClient.WebServices.RemoveWithRequestId(otherResourceGroupName, otherServiceName));
                    WebServiceTests.DisposeOfTestResource(() => resourcesClient.ResourceGroups.Delete(otherResourceGroupName));
                }
            });
        }