Exemplo n.º 1
0
        public async Task Cleanup()
        {
            CleanupResourceGroups();

            //Get
            Response <OrderItemResource> getOrderItemResourceResponse = await _orderItemResourceCollection.GetAsync(_orderItemName);

            OrderItemResource orderItemResource = getOrderItemResourceResponse.Value;

            //Cancel
            Response cancelOrderItemResponse = await orderItemResource.CancelOrderItemAsync(
                new CancellationReason("Test Order item cancelled"));

            //Get
            getOrderItemResourceResponse = await _orderItemResourceCollection.GetAsync(_orderItemName);

            orderItemResource = getOrderItemResourceResponse.Value;

            // Delete
            var deleteOrderItemByNameOperation = await orderItemResource.DeleteAsync(WaitUntil.Completed);

            await deleteOrderItemByNameOperation.WaitForCompletionResponseAsync();
        }
Exemplo n.º 2
0
        public async Task TestOrderItemCRUDOperations()
        {
            var resourceGroupName = Recording.GenerateAssetName("SdkRg");
            await EdgeOrderManagementTestUtilities.TryRegisterResourceGroupAsync(ResourceGroupsOperations,
                                                                                 EdgeOrderManagementTestUtilities.DefaultResourceLocation, resourceGroupName);

            var               orderItemName     = Recording.GenerateAssetName("Sdk-OrderItem");
            ContactDetails    contactDetails    = GetDefaultContactDetails();
            ShippingAddress   shippingAddress   = GetDefaultShippingAddress();
            AddressProperties addressProperties = new(contactDetails)
            {
                ShippingAddress = shippingAddress
            };
            AddressDetails addressDetails = new(addressProperties);
            string         orderId        = string.Format(EdgeOrderManagementTestUtilities.OrderArmIdFormat,
                                                          TestEnvironment.SubscriptionId, resourceGroupName, EdgeOrderManagementTestUtilities.DefaultResourceLocation, orderItemName);

            OrderItemResourceCollection _orderItemResourceCollection = await GetOrderItemResourceCollectionAsync(resourceGroupName);

            OrderItemResourceData orderItemResourceData = new(EdgeOrderManagementTestUtilities.DefaultResourceLocation,
                                                              GetDefaultOrderItemDetails(), addressDetails, orderId);

            // Create
            var createOrderItemOperation = await _orderItemResourceCollection.CreateOrUpdateAsync(WaitUntil.Completed, orderItemName, orderItemResourceData);

            await createOrderItemOperation.WaitForCompletionAsync();

            Assert.IsTrue(createOrderItemOperation.HasCompleted);
            Assert.IsTrue(createOrderItemOperation.HasValue);

            // Get
            Response <OrderItemResource> getOrderItemResourceResponse = await _orderItemResourceCollection.GetAsync(orderItemName);

            OrderItemResource orderItemResource = getOrderItemResourceResponse.Value;

            Assert.IsNotNull(orderItemResource);

            // Update
            addressProperties.ContactDetails.ContactName = "Updated contact name";
            PatchableOrderItemResourceData orderItemUpdateParameter = new()
            {
                ForwardAddress = addressProperties
            };
            var updateOrderItemOperation = await orderItemResource.UpdateAsync(WaitUntil.Completed, orderItemUpdateParameter);

            await updateOrderItemOperation.WaitForCompletionAsync();

            Assert.IsTrue(updateOrderItemOperation.HasCompleted);
            Assert.IsTrue(updateOrderItemOperation.HasValue);

            // Get
            getOrderItemResourceResponse = await _orderItemResourceCollection.GetAsync(orderItemName);

            orderItemResource = getOrderItemResourceResponse.Value;
            Assert.IsNotNull(orderItemResource);

            //Cancel
            Response cancelOrderItemResponse = await orderItemResource.CancelOrderItemAsync(
                new CancellationReason("Order item cancelled"));

            Assert.AreEqual(cancelOrderItemResponse.Status, 204);

            // Get
            getOrderItemResourceResponse = await _orderItemResourceCollection.GetAsync(orderItemName);

            orderItemResource = getOrderItemResourceResponse.Value;
            Assert.IsNotNull(orderItemResource);

            // Delete
            var deleteOrderItemByNameOperation = await orderItemResource.DeleteAsync(WaitUntil.Completed);

            await deleteOrderItemByNameOperation.WaitForCompletionResponseAsync();

            Assert.IsTrue(deleteOrderItemByNameOperation.HasCompleted);
        }
    }
}