예제 #1
0
        public async Task TestMergeReservationOrder()
        {
            var response = await Collection.GetAsync(ReservationOrderId);

            Assert.AreEqual(200, response.GetRawResponse().Status);
            Assert.IsNotNull(response.Value);
            Assert.IsNotNull(response.Value.Data);
            Assert.IsNotNull(response.Value.Data.Reservations);
            Assert.AreEqual(3, response.Value.Data.Reservations.Count);

            var fullyQualifiedId1 = response.Value.Data.Reservations[0].Id.ToString();

            AsyncPageable <ReservationResponseResource> reservationResponse  = response.Value.GetReservationResponses().GetAllAsync();
            List <ReservationResponseResource>          reservationResources = await reservationResponse.ToEnumerableAsync();

            Assert.AreEqual(3, reservationResources.Count);

            // Find the two sub RIs
            List <ReservationResponseResource> subRIs = reservationResources.FindAll(i => i.Data.Properties.ProvisioningState == ProvisioningState.Succeeded);
            var mergeContent = new MergeContent();

            foreach (var ri in subRIs)
            {
                mergeContent.Sources.Add(ri.Id.ToString());
            }
            var mergeResponse = await response.Value.MergeReservationAsync(WaitUntil.Completed, mergeContent);

            Assert.IsNotNull(mergeResponse.Value);
            Assert.AreEqual(3, mergeResponse.Value.Count);
            Assert.AreEqual(1, mergeResponse.Value[0].Properties.Quantity);
            Assert.AreEqual(ProvisioningState.Cancelled, mergeResponse.Value[0].Properties.ProvisioningState);
            Assert.AreEqual(9, mergeResponse.Value[1].Properties.Quantity);
            Assert.AreEqual(ProvisioningState.Cancelled, mergeResponse.Value[1].Properties.ProvisioningState);
            Assert.AreEqual(10, mergeResponse.Value[2].Properties.Quantity);
            Assert.AreEqual(ProvisioningState.Succeeded, mergeResponse.Value[2].Properties.ProvisioningState);
        }
        public virtual ArmOperation <IList <ReservationResponseData> > MergeReservation(WaitUntil waitUntil, MergeContent content, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(content, nameof(content));

            using var scope = _reservationResponseReservationClientDiagnostics.CreateScope("ReservationOrderResponseResource.MergeReservation");
            scope.Start();
            try
            {
                var response  = _reservationResponseReservationRestClient.Merge(Id.Name, content, cancellationToken);
                var operation = new ReservationsArmOperation <IList <ReservationResponseData> >(new IListOperationSource(), _reservationResponseReservationClientDiagnostics, Pipeline, _reservationResponseReservationRestClient.CreateMergeRequest(Id.Name, content).Request, response, OperationFinalStateVia.Location);
                if (waitUntil == WaitUntil.Completed)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }