Beispiel #1
0
        public async Task SqlTriggerCreateAndUpdate()
        {
            var trigger = await CreateSqlTrigger(null);

            Assert.AreEqual(_triggerName, trigger.Data.Resource.Id);
            Assert.That(trigger.Data.Resource.Body, Contains.Substring("First Hello World"));
            Assert.AreEqual(trigger.Data.Resource.TriggerOperation, TriggerOperation.All);
            Assert.AreEqual(trigger.Data.Resource.TriggerType, TriggerType.Pre);

            // Seems bug in swagger definition
            //Assert.AreEqual(TestThroughput1, container.Data.Options.Throughput);

            bool ifExists = await SqlTriggerCollection.ExistsAsync(_triggerName);

            Assert.True(ifExists);

            SqlTriggerResource trigger2 = await SqlTriggerCollection.GetAsync(_triggerName);

            Assert.AreEqual(_triggerName, trigger2.Data.Resource.Id);

            VerifySqlTriggers(trigger, trigger2);

            var updateOptions = new SqlTriggerCreateOrUpdateContent(AzureLocation.WestUS, new Models.SqlTriggerResource(_triggerName)
            {
                TriggerOperation = TriggerOperation.Create,
                TriggerType      = TriggerType.Post,
                Body             = @"function () { var updatetext = getContext();
    var response = context.getResponse();
    response.setBody('Second Hello World');
}"
            });

            trigger = (await SqlTriggerCollection.CreateOrUpdateAsync(WaitUntil.Completed, _triggerName, updateOptions)).Value;
            Assert.AreEqual(_triggerName, trigger.Data.Resource.Id);
            Assert.That(trigger.Data.Resource.Body, Contains.Substring("Second Hello World"));
            Assert.AreEqual(trigger.Data.Resource.TriggerOperation, TriggerOperation.Create);
            Assert.AreEqual(trigger.Data.Resource.TriggerType, TriggerType.Post);

            trigger2 = await SqlTriggerCollection.GetAsync(_triggerName);

            VerifySqlTriggers(trigger, trigger2);
        }
Beispiel #2
0
        internal async Task <SqlTriggerResource> CreateSqlTrigger(AutoscaleSettings autoscale)
        {
            _triggerName = Recording.GenerateAssetName("sql-trigger-");
            var sqlDatabaseCreateUpdateOptions = new SqlTriggerCreateOrUpdateContent(AzureLocation.WestUS,
                                                                                     new Models.SqlTriggerResource(_triggerName)
            {
                TriggerOperation = TriggerOperation.All,
                TriggerType      = TriggerType.Pre,
                Body             = @"function () {
    var updatetext = getContext();
    var response = context.getResponse();
    response.setBody('First Hello World');
}"
            })
            {
                Options = BuildDatabaseCreateUpdateOptions(TestThroughput1, autoscale),
            };
            var sqlContainerLro = await SqlTriggerCollection.CreateOrUpdateAsync(WaitUntil.Completed, _triggerName, sqlDatabaseCreateUpdateOptions);

            return(sqlContainerLro.Value);
        }
        public virtual ArmOperation <SqlTriggerResource> Update(WaitUntil waitUntil, SqlTriggerCreateOrUpdateContent content, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(content, nameof(content));

            using var scope = _sqlTriggerSqlResourcesClientDiagnostics.CreateScope("SqlTriggerResource.Update");
            scope.Start();
            try
            {
                var response  = _sqlTriggerSqlResourcesRestClient.CreateUpdateSqlTrigger(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, content, cancellationToken);
                var operation = new CosmosDBArmOperation <SqlTriggerResource>(new SqlTriggerOperationSource(Client), _sqlTriggerSqlResourcesClientDiagnostics, Pipeline, _sqlTriggerSqlResourcesRestClient.CreateCreateUpdateSqlTriggerRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Parent.Name, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, content).Request, response, OperationFinalStateVia.Location);
                if (waitUntil == WaitUntil.Completed)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }