示例#1
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                ContainerName     = resourceIdentifier.ResourceName;
                DatabaseName      = ResourceIdentifierExtensions.GetSqlDatabaseName(resourceIdentifier);
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            SqlUserDefinedFunctionCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters
            {
                Resource = new SqlUserDefinedFunctionResource
                {
                    Id   = Name,
                    Body = Body
                },
                Options = new Dictionary <string, string>()
                {
                }
            };

            if (ShouldProcess(Name, "Creating or Updating CosmosDB Sql User Defined Function"))
            {
                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlUserDefinedFunctionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, ContainerName, Name, sqlStoredProcedureCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSSqlUserDefinedFunctionGetResults(sqlUserDefinedFunctionGetResults));
            }

            return;
        }
示例#2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                ContainerName     = resourceIdentifier.ResourceName;
                DatabaseName      = ResourceIdentifierExtensions.GetSqlDatabaseName(resourceIdentifier);
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = CosmosDBManagementClient.SqlResources.GetSqlUserDefinedFunctionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, ContainerName, Name).GetAwaiter().GetResult().Body;
                WriteObject(new PSSqlUserDefinedFunctionGetResults(sqlUserDefinedFunctionGetResults));
            }
            else
            {
                IEnumerable <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = CosmosDBManagementClient.SqlResources.ListSqlUserDefinedFunctionsWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, ContainerName).GetAwaiter().GetResult().Body;

                foreach (SqlUserDefinedFunctionGetResults sqlUserDefinedFunction in sqlUserDefinedFunctions)
                {
                    WriteObject(new PSSqlUserDefinedFunctionGetResults(sqlUserDefinedFunction));
                }
            }

            return;
        }
示例#3
0
 public PSSqlUserDefinedFunctionGetResults(SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults)
 {
     Name     = sqlUserDefinedFunctionGetResults.Name;
     Id       = sqlUserDefinedFunctionGetResults.Id;
     Location = sqlUserDefinedFunctionGetResults.Location;
     Tags     = sqlUserDefinedFunctionGetResults.Tags;
     Resource = new PSSqlUserDefinedFunctionGetPropertiesResource(sqlUserDefinedFunctionGetResults.Resource);
 }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSet))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ParentObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                ContainerName     = resourceIdentifier.ResourceName;
                DatabaseName      = ResourceIdentifierExtensions.GetSqlDatabaseName(resourceIdentifier);
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
            }
            else if (ParameterSetName.Equals(ObjectParameterSet))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                ContainerName     = ResourceIdentifierExtensions.GetSqlContainerName(resourceIdentifier);
                DatabaseName      = ResourceIdentifierExtensions.GetSqlDatabaseName(resourceIdentifier);
                AccountName       = ResourceIdentifierExtensions.GetDatabaseAccountName(resourceIdentifier);
                Name = resourceIdentifier.ResourceName;
            }

            SqlUserDefinedFunctionGetResults readSqlUserDefinedFunctionGetResults = null;

            try
            {
                readSqlUserDefinedFunctionGetResults = CosmosDBManagementClient.SqlResources.GetSqlUserDefinedFunction(ResourceGroupName, AccountName, DatabaseName, ContainerName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    throw new ResourceNotFoundException(message: string.Format(ExceptionMessage.NotFound, Name), innerException: e);
                }
            }

            if (string.IsNullOrEmpty(Body))
            {
                Body = readSqlUserDefinedFunctionGetResults.Resource.Body;
            }

            SqlUserDefinedFunctionCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters
            {
                Resource = new SqlUserDefinedFunctionResource
                {
                    Id   = Name,
                    Body = Body
                },
                Options = new CreateUpdateOptions() //passing empty object as options cannot be null
            };

            if (ShouldProcess(Name, "Updating an existing CosmosDB Sql User Defined Function"))
            {
                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = CosmosDBManagementClient.SqlResources.CreateUpdateSqlUserDefinedFunctionWithHttpMessagesAsync(ResourceGroupName, AccountName, DatabaseName, ContainerName, Name, sqlStoredProcedureCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSSqlUserDefinedFunctionGetResults(sqlUserDefinedFunctionGetResults));
            }

            return;
        }
示例#5
0
 private void VerifySqlUserDefinedFunctions(SqlUserDefinedFunctionGetResults expectedValue, SqlUserDefinedFunctionGetResults actualValue)
 {
     Assert.AreEqual(expectedValue.Id, actualValue.Id);
     Assert.AreEqual(expectedValue.Name, actualValue.Name);
     Assert.AreEqual(expectedValue.Resource.Id, actualValue.Resource.Id);
     Assert.AreEqual(expectedValue.Resource.Rid, actualValue.Resource.Rid);
     Assert.AreEqual(expectedValue.Resource.Ts, actualValue.Resource.Ts);
     Assert.AreEqual(expectedValue.Resource.Etag, actualValue.Resource.Etag);
     Assert.AreEqual(expectedValue.Resource.Body, actualValue.Resource.Body);
 }
 public PSSqlUserDefinedFunctionGetResults(SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults)
 {
     Name = sqlUserDefinedFunctionGetResults.Name;
     Id   = sqlUserDefinedFunctionGetResults.Id;
     SqlUserDefinedFunctionGetResultsId = sqlUserDefinedFunctionGetResults.SqlUserDefinedFunctionGetResultsId;
     Body  = sqlUserDefinedFunctionGetResults.Body;
     _rid  = sqlUserDefinedFunctionGetResults._rid;
     _ts   = sqlUserDefinedFunctionGetResults._ts;
     _etag = sqlUserDefinedFunctionGetResults._etag;
 }
示例#7
0
        public async Task SqlUserDefinedFunctionListTest()
        {
            List <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = await CosmosDBManagementClient.SqlResources.ListSqlUserDefinedFunctionsAsync(
                resourceGroupName, databaseAccountName, databaseName, containerName).ToEnumerableAsync();

            Assert.NotNull(sqlUserDefinedFunctions);
            Assert.AreEqual(1, sqlUserDefinedFunctions.Count);
            SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = await CosmosDBManagementClient.SqlResources.GetSqlUserDefinedFunctionAsync(
                resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName);

            VerifySqlUserDefinedFunctions(sqlUserDefinedFunctionGetResults, sqlUserDefinedFunctions[0]);
        }
示例#8
0
        public async Task SqlUserDefinedFunctionCreateAndUpdateTest()
        {
            SqlUserDefinedFunctionCreateUpdateParameters sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters(
                resource: new SqlUserDefinedFunctionResource(userDefinedFunctionName)
            {
                Body = "function () { var updatetext = getContext(); " +
                       "var response = context.getResponse();" +
                       "response.setBody('First Hello World');" +
                       "}"
            },
                options: new CreateUpdateOptions()
                );
            SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults1 = await WaitForCompletionAsync(
                await CosmosDBManagementClient.SqlResources.StartCreateUpdateSqlUserDefinedFunctionAsync(
                    resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters));

            Assert.NotNull(sqlUserDefinedFunctionGetResults1);
            SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults2 = await CosmosDBManagementClient.SqlResources.GetSqlUserDefinedFunctionAsync(
                resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName);

            Assert.NotNull(sqlUserDefinedFunctionGetResults2);
            VerifySqlUserDefinedFunctions(sqlUserDefinedFunctionGetResults1, sqlUserDefinedFunctionGetResults2);

            sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters(
                resource: new SqlUserDefinedFunctionResource(userDefinedFunctionName)
            {
                Body = "function () { var updatetext = getContext(); " +
                       "var response = context.getResponse();" +
                       "response.setBody('Second Hello World');" +
                       "}"
            },
                options: new CreateUpdateOptions()
                );
            SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults3 = await WaitForCompletionAsync(
                await CosmosDBManagementClient.SqlResources.StartCreateUpdateSqlUserDefinedFunctionAsync(
                    resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters));

            Assert.NotNull(sqlUserDefinedFunctionGetResults3);
            SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults4 = await CosmosDBManagementClient.SqlResources.GetSqlUserDefinedFunctionAsync(
                resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName);

            Assert.NotNull(sqlUserDefinedFunctionGetResults4);
            VerifySqlUserDefinedFunctions(sqlUserDefinedFunctionGetResults3, sqlUserDefinedFunctionGetResults4);
        }
        public void SqlCRUDTests()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create client
                CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler1);

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    {
                        Location  = location,
                        Kind      = DatabaseAccountKind.GlobalDocumentDB,
                        Locations = new List <Location>()
                        {
                            { new Location(locationName: location) }
                        }
                    };

                    databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                    Assert.Equal(databaseAccount.Name, databaseAccountName);
                }

                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters = new SqlDatabaseCreateUpdateParameters
                {
                    Resource = new SqlDatabaseResource {
                        Id = databaseName
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlDatabaseGetResults sqlDatabaseGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, sqlDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults);
                Assert.Equal(databaseName, sqlDatabaseGetResults.Name);

                SqlDatabaseGetResults sqlDatabaseGetResults2 = cosmosDBManagementClient.SqlResources.GetSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults2);
                Assert.Equal(databaseName, sqlDatabaseGetResults2.Name);

                VerifyEqualSqlDatabases(sqlDatabaseGetResults, sqlDatabaseGetResults2);

                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters2 = new SqlDatabaseCreateUpdateParameters
                {
                    Location = location,
                    Tags     = tags,
                    Resource = new SqlDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput
                    }
                };

                SqlDatabaseGetResults sqlDatabaseGetResults3 = cosmosDBManagementClient.SqlResources.CreateUpdateSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, sqlDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults3);
                Assert.Equal(databaseName2, sqlDatabaseGetResults3.Name);

                IEnumerable <SqlDatabaseGetResults> sqlDatabases = cosmosDBManagementClient.SqlResources.ListSqlDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.SqlResources.GetSqlDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal(sqlThroughputType, throughputSettingsGetResults.Type);

                SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters
                {
                    Resource = new SqlContainerResource {
                        Id           = containerName,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address/zipCode"
                            }
                        },
                        IndexingPolicy = new IndexingPolicy
                        {
                            Automatic     = true,
                            IndexingMode  = IndexingMode.Consistent,
                            IncludedPaths = new List <IncludedPath>
                            {
                                new IncludedPath {
                                    Path = "/*"
                                }
                            },
                            ExcludedPaths = new List <ExcludedPath>
                            {
                                new ExcludedPath {
                                    Path = "/pathToNotIndex/*"
                                }
                            },
                            CompositeIndexes = new List <IList <CompositePath> >
                            {
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath2", Order = CompositePathSortOrder.Descending
                                    }
                                },
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath4", Order = CompositePathSortOrder.Descending
                                    }
                                }
                            }
                        }
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput
                    }
                };

                SqlContainerGetResults sqlContainerGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainerGetResults);

                IEnumerable <SqlContainerGetResults> sqlContainers = cosmosDBManagementClient.SqlResources.ListSqlContainersWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainers);

                SqlStoredProcedureCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlStoredProcedureCreateUpdateParameters
                {
                    Resource = new SqlStoredProcedureResource
                    {
                        Id   = storedProcedureName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlStoredProcedureGetResults sqlStoredProcedureGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlStoredProcedureWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, storedProcedureName, sqlStoredProcedureCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedureGetResults);
                Assert.Equal(sqlStoredProcedureGetResults.Resource.Body, sqlStoredProcedureGetResults.Resource.Body);

                IEnumerable <SqlStoredProcedureGetResults> sqlStoredProcedures = cosmosDBManagementClient.SqlResources.ListSqlStoredProceduresWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedures);

                foreach (SqlStoredProcedureGetResults sqlStoredProcedure in sqlStoredProcedures)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlStoredProcedureWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlStoredProcedure.Name);
                }

                SqlUserDefinedFunctionCreateUpdateParameters sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters
                {
                    Resource = new SqlUserDefinedFunctionResource
                    {
                        Id   = userDefinedFunctionName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlUserDefinedFunctionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlUserDefinedFunctionGetResults);
                Assert.Equal(sqlUserDefinedFunctionGetResults.Resource.Body, sqlUserDefinedFunctionGetResults.Resource.Body);


                IEnumerable <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = cosmosDBManagementClient.SqlResources.ListSqlUserDefinedFunctionsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlUserDefinedFunctions);

                foreach (SqlUserDefinedFunctionGetResults sqlUserDefinedFunction in sqlUserDefinedFunctions)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlUserDefinedFunctionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlUserDefinedFunction.Name);
                }

                SqlTriggerCreateUpdateParameters sqlTriggerCreateUpdateParameters = new SqlTriggerCreateUpdateParameters
                {
                    Resource = new SqlTriggerResource
                    {
                        Id = triggerName,
                        TriggerOperation = "All",
                        TriggerType      = "Pre",
                        Body             = "function () { var context = getContext(); " +
                                           "var response = context.getResponse();" +
                                           "response.setBody('Hello, World');" +
                                           "}"
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlTriggerGetResults sqlTriggerGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlTriggerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, triggerName, sqlTriggerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggerGetResults);
                Assert.Equal(sqlTriggerGetResults.Resource.TriggerType, sqlTriggerCreateUpdateParameters.Resource.TriggerType);
                Assert.Equal(sqlTriggerGetResults.Resource.TriggerOperation, sqlTriggerCreateUpdateParameters.Resource.TriggerOperation);
                Assert.Equal(sqlTriggerGetResults.Resource.Body, sqlTriggerCreateUpdateParameters.Resource.Body);

                IEnumerable <SqlTriggerGetResults> sqlTriggers = cosmosDBManagementClient.SqlResources.ListSqlTriggersWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggers);

                foreach (SqlTriggerGetResults sqlTrigger in sqlTriggers)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlTriggerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlTrigger.Name);
                }

                foreach (SqlContainerGetResults sqlContainer in sqlContainers)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlContainerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, sqlContainer.Name);
                }

                foreach (SqlDatabaseGetResults sqlDatabase in sqlDatabases)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, sqlDatabase.Name);
                }
            }
        }
        public void SqlCRUDTests()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                // Create client
                CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler1);
                ResourceManagementClient resourcesClient          = CosmosDBTestUtilities.GetResourceManagementClient(context, handler2);

                string resourceGroupName   = "CosmosDBResourceGroup822"; // Using a pre-existing ResourceGroup and DatabaseAccount, because Database Account provisioning takes some time
                string databaseAccountName = "db9934";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    List <Location> locations = new List <Location>();
                    locations.Add(new Location(locationName: "East US"));
                    DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    {
                        Location  = "EAST US",
                        Kind      = "GlobalDocumentDB",
                        Locations = locations
                    };

                    databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string databaseName  = "databaseName822";
                string databaseName2 = "databaseName2822";
                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters = new SqlDatabaseCreateUpdateParameters
                {
                    Resource = new SqlDatabaseResource {
                        Id = databaseName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlDatabaseGetResults sqlDatabaseGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, sqlDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults);
                Assert.Equal(databaseName, sqlDatabaseGetResults.Name);

                SqlDatabaseGetResults sqlDatabaseGetResults2 = cosmosDBManagementClient.SqlResources.GetSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults2);
                Assert.Equal(databaseName, sqlDatabaseGetResults2.Name);

                VerifyEqualSqlDatabases(sqlDatabaseGetResults, sqlDatabaseGetResults2);

                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters2 = new SqlDatabaseCreateUpdateParameters
                {
                    Location = "EAST US",
                    Tags     = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" }
                    },
                    Resource = new SqlDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                SqlDatabaseGetResults sqlDatabaseGetResults3 = cosmosDBManagementClient.SqlResources.CreateUpdateSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, sqlDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults3);
                Assert.Equal(databaseName2, sqlDatabaseGetResults3.Name);

                IEnumerable <SqlDatabaseGetResults> sqlDatabases = cosmosDBManagementClient.SqlResources.ListSqlDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.SqlResources.GetSqlDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings", throughputSettingsGetResults.Type);

                string containerName = "containerName822";

                SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters
                {
                    Resource = new SqlContainerResource {
                        Id           = containerName,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address/zipCode"
                            }
                        }
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                SqlContainerGetResults sqlContainerGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainerGetResults);

                IEnumerable <SqlContainerGetResults> sqlContainers = cosmosDBManagementClient.SqlResources.ListSqlContainersWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainers);

                string storedProcedureName = "storedProcedureName822";

                SqlStoredProcedureCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlStoredProcedureCreateUpdateParameters
                {
                    Resource = new SqlStoredProcedureResource
                    {
                        Id   = storedProcedureName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlStoredProcedureGetResults sqlStoredProcedureGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlStoredProcedureWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, storedProcedureName, sqlStoredProcedureCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedureGetResults);

                IEnumerable <SqlStoredProcedureGetResults> sqlStoredProcedures = cosmosDBManagementClient.SqlResources.ListSqlStoredProceduresWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedures);

                foreach (SqlStoredProcedureGetResults sqlStoredProcedure in sqlStoredProcedures)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlStoredProcedureWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlStoredProcedure.Name);
                }

                string userDefinedFunctionName = "userDefinedFunctionName822";

                SqlUserDefinedFunctionCreateUpdateParameters sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters
                {
                    Resource = new SqlUserDefinedFunctionResource
                    {
                        Id   = userDefinedFunctionName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlUserDefinedFunctionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedureGetResults);

                IEnumerable <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = cosmosDBManagementClient.SqlResources.ListSqlUserDefinedFunctionsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlUserDefinedFunctions);

                foreach (SqlUserDefinedFunctionGetResults sqlUserDefinedFunction in sqlUserDefinedFunctions)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlUserDefinedFunctionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlUserDefinedFunction.Name);
                }

                string triggerName = "triggerName822";

                SqlTriggerCreateUpdateParameters sqlTriggerCreateUpdateParameters = new SqlTriggerCreateUpdateParameters
                {
                    Resource = new SqlTriggerResource
                    {
                        Id = triggerName,
                        TriggerOperation = "All",
                        TriggerType      = "Pre",
                        Body             = "function () { var context = getContext(); " +
                                           "var response = context.getResponse();" +
                                           "response.setBody('Hello, World');" +
                                           "}"
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlTriggerGetResults sqlTriggerGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlTriggerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, triggerName, sqlTriggerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggerGetResults);

                IEnumerable <SqlTriggerGetResults> sqlTriggers = cosmosDBManagementClient.SqlResources.ListSqlTriggersWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggers);

                foreach (SqlTriggerGetResults sqlTrigger in sqlTriggers)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlTriggerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlTrigger.Name);
                }

                foreach (SqlContainerGetResults sqlContainer in sqlContainers)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlContainerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, sqlContainer.Name);
                }

                foreach (SqlDatabaseGetResults sqlDatabase in sqlDatabases)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, sqlDatabase.Name);
                }
            }
        }
        public async Task SqlCRUDTests()
        {
            CosmosDBManagementClient  cosmosDBManagementClient = GetCosmosDBManagementClient();
            DatabaseAccountGetResults databaseAccount          = null;

            var locations = new List <Location>()
            {
                { new Location(id: default(string), locationName: location, documentEndpoint: default(string), provisioningState: default(string), failoverPriority: default(int?), isZoneRedundant: default(bool?)) }
            };
            DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations)
            {
                Location = location,
                Kind     = DatabaseAccountKind.GlobalDocumentDB,
            };

            databaseAccount = await WaitForCompletionAsync(await cosmosDBManagementClient.DatabaseAccounts.StartCreateOrUpdateAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters));

            Assert.AreEqual(databaseAccount.Name, databaseAccountName);

            Response isDatabaseNameExists = await cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsAsync(databaseAccountName);

            Assert.AreEqual(200, isDatabaseNameExists.Status);

            //Create sql database
            SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters = new SqlDatabaseCreateUpdateParameters(new SqlDatabaseResource(databaseName), new CreateUpdateOptions());
            SqlDatabaseGetResults             sqlDatabaseGetResults             = await WaitForCompletionAsync(await cosmosDBManagementClient.SqlResources.StartCreateUpdateSqlDatabaseAsync(resourceGroupName, databaseAccountName, databaseName, sqlDatabaseCreateUpdateParameters));

            Assert.NotNull(sqlDatabaseGetResults);
            Assert.AreEqual(databaseName, sqlDatabaseGetResults.Name);

            SqlDatabaseGetResults sqlDatabaseGetResults2 = (await cosmosDBManagementClient.SqlResources.GetSqlDatabaseAsync(resourceGroupName, databaseAccountName, databaseName)).Value;

            Assert.NotNull(sqlDatabaseGetResults2);
            Assert.AreEqual(databaseName, sqlDatabaseGetResults2.Name);
            VerifyEqualSqlDatabases(sqlDatabaseGetResults, sqlDatabaseGetResults2);

            SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters2 = new SqlDatabaseCreateUpdateParameters(id: default(string), name: default(string), type: default(string), location: location, tags: tags, resource: new SqlDatabaseResource(databaseName2), options: new CreateUpdateOptions {
                Throughput = sampleThroughput
            });
            SqlDatabaseGetResults sqlDatabaseGetResults3 = await WaitForCompletionAsync(await cosmosDBManagementClient.SqlResources.StartCreateUpdateSqlDatabaseAsync(resourceGroupName, databaseAccountName, databaseName2, sqlDatabaseCreateUpdateParameters2));

            Assert.NotNull(sqlDatabaseGetResults3);
            Assert.AreEqual(databaseName2, sqlDatabaseGetResults3.Name);

            IAsyncEnumerable <SqlDatabaseGetResults> sqlDatabases = cosmosDBManagementClient.SqlResources.ListSqlDatabasesAsync(resourceGroupName, databaseAccountName);

            Assert.NotNull(sqlDatabases);

            ThroughputSettingsGetResults throughputSettingsGetResults = (await cosmosDBManagementClient.SqlResources.GetSqlDatabaseThroughputAsync(resourceGroupName, databaseAccountName, databaseName2)).Value;

            Assert.NotNull(throughputSettingsGetResults);
            Assert.NotNull(throughputSettingsGetResults.Name);
            Assert.AreEqual(sqlThroughputType, throughputSettingsGetResults.Type);

            //Create sql container
            SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters(
                resource: new SqlContainerResource(containerName)
            {
                PartitionKey = new ContainerPartitionKey(new List <string> {
                    "/address/zipCode"
                }, null, null)
                {
                    Kind = new PartitionKind("Hash")
                },
                IndexingPolicy = new IndexingPolicy(true, IndexingMode.Consistent,
                                                    new List <IncludedPath>
                {
                    new IncludedPath {
                        Path = "/*"
                    }
                },
                                                    new List <ExcludedPath>
                {
                    new ExcludedPath {
                        Path = "/pathToNotIndex/*"
                    }
                },
                                                    new List <IList <CompositePath> >
                {
                    new List <CompositePath>
                    {
                        new CompositePath {
                            Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending
                        },
                        new CompositePath {
                            Path = "/orderByPath2", Order = CompositePathSortOrder.Descending
                        }
                    },
                    new List <CompositePath>
                    {
                        new CompositePath {
                            Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending
                        },
                        new CompositePath {
                            Path = "/orderByPath4", Order = CompositePathSortOrder.Descending
                        }
                    }
                },
                                                    new List <SpatialSpec>
                {
                    new SpatialSpec
                    (
                        "/*",
                        new List <SpatialType>
                    {
                        new SpatialType("Point")
                    }
                    ),
                }
                                                    )
            },
                options: new CreateUpdateOptions
            {
                Throughput = sampleThroughput
            }
                );
            SqlContainerGetResults sqlContainerGetResults = await WaitForCompletionAsync(await cosmosDBManagementClient.SqlResources.StartCreateUpdateSqlContainerAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters));

            Assert.NotNull(sqlContainerGetResults);
            VerifySqlContainerCreation(sqlContainerGetResults, sqlContainerCreateUpdateParameters);

            IAsyncEnumerable <SqlContainerGetResults> sqlContainers = cosmosDBManagementClient.SqlResources.ListSqlContainersAsync(resourceGroupName, databaseAccountName, databaseName);

            Assert.NotNull(sqlContainers);

            //Create stored procedure
            SqlStoredProcedureCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlStoredProcedureCreateUpdateParameters(
                new SqlStoredProcedureResource(storedProcedureName)
            {
                Body = "function () { var context = getContext(); " +
                       "var response = context.getResponse();" +
                       "response.setBody('Hello, World');" +
                       "}"
            },
                new CreateUpdateOptions()
                );

            SqlStoredProcedureGetResults sqlStoredProcedureGetResults = await WaitForCompletionAsync(await cosmosDBManagementClient.SqlResources.StartCreateUpdateSqlStoredProcedureAsync(resourceGroupName, databaseAccountName, databaseName, containerName, storedProcedureName, sqlStoredProcedureCreateUpdateParameters));

            Assert.NotNull(sqlStoredProcedureGetResults);
            Assert.AreEqual(sqlStoredProcedureGetResults.Resource.Body, sqlStoredProcedureGetResults.Resource.Body);

            IAsyncEnumerable <SqlStoredProcedureGetResults> sqlStoredProcedures = cosmosDBManagementClient.SqlResources.ListSqlStoredProceduresAsync(resourceGroupName, databaseAccountName, databaseName, containerName);

            Assert.NotNull(sqlStoredProcedures);

            //Create defined function
            SqlUserDefinedFunctionCreateUpdateParameters sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters(
                resource: new SqlUserDefinedFunctionResource(userDefinedFunctionName)
            {
                Body = "function () { var context = getContext(); " +
                       "var response = context.getResponse();" +
                       "response.setBody('Hello, World');" +
                       "}"
            },
                options: new CreateUpdateOptions()
                );

            SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = await WaitForCompletionAsync(await cosmosDBManagementClient.SqlResources.StartCreateUpdateSqlUserDefinedFunctionAsync(resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters));

            Assert.NotNull(sqlUserDefinedFunctionGetResults);
            Assert.AreEqual(sqlUserDefinedFunctionGetResults.Resource.Body, sqlUserDefinedFunctionGetResults.Resource.Body);


            IAsyncEnumerable <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = cosmosDBManagementClient.SqlResources.ListSqlUserDefinedFunctionsAsync(resourceGroupName, databaseAccountName, databaseName, containerName);

            Assert.NotNull(sqlUserDefinedFunctions);


            //Create trigger
            SqlTriggerCreateUpdateParameters sqlTriggerCreateUpdateParameters = new SqlTriggerCreateUpdateParameters(
                resource: new SqlTriggerResource(triggerName)
            {
                TriggerOperation = "All",
                TriggerType      = "Pre",
                Body             = "function () { var context = getContext(); " +
                                   "var response = context.getResponse();" +
                                   "response.setBody('Hello, World');" +
                                   "}"
            },
                options: new CreateUpdateOptions()
                );

            SqlTriggerGetResults sqlTriggerGetResults = await WaitForCompletionAsync(await cosmosDBManagementClient.SqlResources.StartCreateUpdateSqlTriggerAsync(resourceGroupName, databaseAccountName, databaseName, containerName, triggerName, sqlTriggerCreateUpdateParameters));

            Assert.NotNull(sqlTriggerGetResults);
            Assert.AreEqual(sqlTriggerGetResults.Resource.TriggerType, sqlTriggerCreateUpdateParameters.Resource.TriggerType);
            Assert.AreEqual(sqlTriggerGetResults.Resource.TriggerOperation, sqlTriggerCreateUpdateParameters.Resource.TriggerOperation);
            Assert.AreEqual(sqlTriggerGetResults.Resource.Body, sqlTriggerCreateUpdateParameters.Resource.Body);

            IAsyncEnumerable <SqlTriggerGetResults> sqlTriggers = cosmosDBManagementClient.SqlResources.ListSqlTriggersAsync(resourceGroupName, databaseAccountName, databaseName, containerName);

            Assert.NotNull(sqlTriggers);

            //Delete operations
            await foreach (SqlStoredProcedureGetResults sqlStoredProcedure in sqlStoredProcedures)
            {
                await cosmosDBManagementClient.SqlResources.StartDeleteSqlStoredProcedureAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlStoredProcedure.Name);
            }

            await foreach (SqlUserDefinedFunctionGetResults sqlUserDefinedFunction in sqlUserDefinedFunctions)
            {
                await cosmosDBManagementClient.SqlResources.StartDeleteSqlStoredProcedureAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlUserDefinedFunction.Name);
            }

            await foreach (SqlTriggerGetResults sqlTrigger in sqlTriggers)
            {
                await cosmosDBManagementClient.SqlResources.StartDeleteSqlTriggerAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlTrigger.Name);
            }
            await foreach (SqlContainerGetResults sqlContainer in sqlContainers)
            {
                await cosmosDBManagementClient.SqlResources.StartDeleteSqlContainerAsync(resourceGroupName, databaseAccountName, databaseName, sqlContainer.Name);
            }

            await foreach (SqlDatabaseGetResults sqlDatabase in sqlDatabases)
            {
                await cosmosDBManagementClient.SqlResources.StartDeleteSqlDatabaseAsync(resourceGroupName, databaseAccountName, sqlDatabase.Name);
            }
        }
示例#12
0
        public void SqlCRUDTests()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                fixture.Init(context);
                var client = this.fixture.CosmosDBManagementClient.SqlResources;

                var databaseAccountName = this.fixture.GetDatabaseAccountName(TestFixture.AccountType.PitrSql);

                var databaseName = TestUtilities.GenerateName("database");
                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters = new SqlDatabaseCreateUpdateParameters
                {
                    Resource = new SqlDatabaseResource {
                        Id = databaseName
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlDatabaseGetResults sqlDatabaseGetResults = client.CreateUpdateSqlDatabaseWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName,
                    sqlDatabaseCreateUpdateParameters
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults);
                Assert.Equal(databaseName, sqlDatabaseGetResults.Name);

                SqlDatabaseGetResults sqlDatabaseGetResults2 = client.GetSqlDatabaseWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults2);
                Assert.Equal(databaseName, sqlDatabaseGetResults2.Name);

                VerifyEqualSqlDatabases(sqlDatabaseGetResults, sqlDatabaseGetResults2);

                var databaseName2 = TestUtilities.GenerateName("database");
                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters2 = new SqlDatabaseCreateUpdateParameters
                {
                    Location = this.fixture.Location,
                    Tags     = tags,
                    Resource = new SqlDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput
                    }
                };

                SqlDatabaseGetResults sqlDatabaseGetResults3 = client.CreateUpdateSqlDatabaseWithHttpMessagesAsync(
                    this.fixture.ResourceGroupName,
                    databaseAccountName,
                    databaseName2,
                    sqlDatabaseCreateUpdateParameters2
                    ).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults3);
                Assert.Equal(databaseName2, sqlDatabaseGetResults3.Name);

                IEnumerable <SqlDatabaseGetResults> sqlDatabases = client.ListSqlDatabasesWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = client.GetSqlDatabaseThroughputWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal(sqlThroughputType, throughputSettingsGetResults.Type);

                var containerName = TestUtilities.GenerateName("container");
                SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters
                {
                    Resource = new SqlContainerResource
                    {
                        Id           = containerName,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address/zipCode"
                            }
                        },
                        IndexingPolicy = new IndexingPolicy
                        {
                            Automatic     = true,
                            IndexingMode  = IndexingMode.Consistent,
                            IncludedPaths = new List <IncludedPath>
                            {
                                new IncludedPath {
                                    Path = "/*"
                                }
                            },
                            ExcludedPaths = new List <ExcludedPath>
                            {
                                new ExcludedPath {
                                    Path = "/pathToNotIndex/*"
                                }
                            },
                            CompositeIndexes = new List <IList <CompositePath> >
                            {
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath1", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath2", Order = CompositePathSortOrder.Descending
                                    }
                                },
                                new List <CompositePath>
                                {
                                    new CompositePath {
                                        Path = "/orderByPath3", Order = CompositePathSortOrder.Ascending
                                    },
                                    new CompositePath {
                                        Path = "/orderByPath4", Order = CompositePathSortOrder.Descending
                                    }
                                }
                            }
                        }
                    },
                    Options = new CreateUpdateOptions
                    {
                        Throughput = sampleThroughput
                    }
                };

                SqlContainerGetResults sqlContainerGetResults = client.CreateUpdateSqlContainerWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainerGetResults);

                IEnumerable <SqlContainerGetResults> sqlContainers = client.ListSqlContainersWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainers);

                var storedProcedureName = TestUtilities.GenerateName("storedproc");
                SqlStoredProcedureCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlStoredProcedureCreateUpdateParameters
                {
                    Resource = new SqlStoredProcedureResource
                    {
                        Id   = storedProcedureName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlStoredProcedureGetResults sqlStoredProcedureGetResults = client.CreateUpdateSqlStoredProcedureWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, storedProcedureName, sqlStoredProcedureCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedureGetResults);
                Assert.Equal(sqlStoredProcedureGetResults.Resource.Body, sqlStoredProcedureGetResults.Resource.Body);

                IEnumerable <SqlStoredProcedureGetResults> sqlStoredProcedures = client.ListSqlStoredProceduresWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedures);

                foreach (SqlStoredProcedureGetResults sqlStoredProcedure in sqlStoredProcedures)
                {
                    client.DeleteSqlStoredProcedureWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, sqlStoredProcedure.Name);
                }

                var userDefinedFunctionName = TestUtilities.GenerateName("udf");
                SqlUserDefinedFunctionCreateUpdateParameters sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters
                {
                    Resource = new SqlUserDefinedFunctionResource
                    {
                        Id   = userDefinedFunctionName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = client.CreateUpdateSqlUserDefinedFunctionWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlUserDefinedFunctionGetResults);
                Assert.Equal(sqlUserDefinedFunctionGetResults.Resource.Body, sqlUserDefinedFunctionGetResults.Resource.Body);


                IEnumerable <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = client.ListSqlUserDefinedFunctionsWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlUserDefinedFunctions);

                foreach (SqlUserDefinedFunctionGetResults sqlUserDefinedFunction in sqlUserDefinedFunctions)
                {
                    client.DeleteSqlUserDefinedFunctionWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, sqlUserDefinedFunction.Name);
                }

                var triggerName = TestUtilities.GenerateName("trigger");
                SqlTriggerCreateUpdateParameters sqlTriggerCreateUpdateParameters = new SqlTriggerCreateUpdateParameters
                {
                    Resource = new SqlTriggerResource
                    {
                        Id = triggerName,
                        TriggerOperation = "All",
                        TriggerType      = "Pre",
                        Body             = "function () { var context = getContext(); " +
                                           "var response = context.getResponse();" +
                                           "response.setBody('Hello, World');" +
                                           "}"
                    },
                    Options = new CreateUpdateOptions()
                };

                SqlTriggerGetResults sqlTriggerGetResults = client.CreateUpdateSqlTriggerWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, triggerName, sqlTriggerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggerGetResults);
                Assert.Equal(sqlTriggerGetResults.Resource.TriggerType, sqlTriggerCreateUpdateParameters.Resource.TriggerType);
                Assert.Equal(sqlTriggerGetResults.Resource.TriggerOperation, sqlTriggerCreateUpdateParameters.Resource.TriggerOperation);
                Assert.Equal(sqlTriggerGetResults.Resource.Body, sqlTriggerCreateUpdateParameters.Resource.Body);

                IEnumerable <SqlTriggerGetResults> sqlTriggers = client.ListSqlTriggersWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggers);

                foreach (SqlTriggerGetResults sqlTrigger in sqlTriggers)
                {
                    client.DeleteSqlTriggerWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, containerName, sqlTrigger.Name);
                }

                foreach (SqlContainerGetResults sqlContainer in sqlContainers)
                {
                    client.DeleteSqlContainerWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, databaseName, sqlContainer.Name);
                }

                foreach (SqlDatabaseGetResults sqlDatabase in sqlDatabases)
                {
                    client.DeleteSqlDatabaseWithHttpMessagesAsync(this.fixture.ResourceGroupName, databaseAccountName, sqlDatabase.Name);
                }
            }
        }