< Summary

Class:Azure.Iot.Hub.Service.MessagesRestClient
Assembly:Azure.Iot.Hub.Service
File(s):C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\MessagesRestClient.cs
Covered lines:0
Uncovered lines:40
Coverable lines:40
Total lines:115
Line coverage:0% (0 of 40)
Covered branches:0
Total branches:12
Branch coverage:0% (0 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
CreatePurgeCloudToDeviceMessageQueueRequest(...)-0%100%
PurgeCloudToDeviceMessageQueueAsync()-0%0%
PurgeCloudToDeviceMessageQueue(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\MessagesRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.Iot.Hub.Service.Models;
 16
 17namespace Azure.Iot.Hub.Service
 18{
 19    internal partial class MessagesRestClient
 20    {
 21        private Uri endpoint;
 22        private string apiVersion;
 23        private ClientDiagnostics _clientDiagnostics;
 24        private HttpPipeline _pipeline;
 25
 26        /// <summary> Initializes a new instance of MessagesRestClient. </summary>
 27        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 28        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 29        /// <param name="endpoint"> server parameter. </param>
 30        /// <param name="apiVersion"> Api Version. </param>
 31        /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception>
 032        public MessagesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, strin
 33        {
 034            endpoint ??= new Uri("https://fully-qualified-iothubname.azure-devices.net");
 035            if (apiVersion == null)
 36            {
 037                throw new ArgumentNullException(nameof(apiVersion));
 38            }
 39
 040            this.endpoint = endpoint;
 041            this.apiVersion = apiVersion;
 042            _clientDiagnostics = clientDiagnostics;
 043            _pipeline = pipeline;
 044        }
 45
 46        internal HttpMessage CreatePurgeCloudToDeviceMessageQueueRequest(string id)
 47        {
 048            var message = _pipeline.CreateMessage();
 049            var request = message.Request;
 050            request.Method = RequestMethod.Delete;
 051            var uri = new RawRequestUriBuilder();
 052            uri.Reset(endpoint);
 053            uri.AppendPath("/devices/", false);
 054            uri.AppendPath(id, true);
 055            uri.AppendPath("/commands", false);
 056            uri.AppendQuery("api-version", apiVersion, true);
 057            request.Uri = uri;
 058            return message;
 59        }
 60
 61        /// <summary> Deletes all the pending commands for a device in the IoT Hub. </summary>
 62        /// <param name="id"> The unique identifier of the device. </param>
 63        /// <param name="cancellationToken"> The cancellation token to use. </param>
 64        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 65        public async Task<Response<PurgeMessageQueueResult>> PurgeCloudToDeviceMessageQueueAsync(string id, Cancellation
 66        {
 067            if (id == null)
 68            {
 069                throw new ArgumentNullException(nameof(id));
 70            }
 71
 072            using var message = CreatePurgeCloudToDeviceMessageQueueRequest(id);
 073            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 074            switch (message.Response.Status)
 75            {
 76                case 200:
 77                    {
 78                        PurgeMessageQueueResult value = default;
 079                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 080                        value = PurgeMessageQueueResult.DeserializePurgeMessageQueueResult(document.RootElement);
 081                        return Response.FromValue(value, message.Response);
 82                    }
 83                default:
 084                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 85            }
 086        }
 87
 88        /// <summary> Deletes all the pending commands for a device in the IoT Hub. </summary>
 89        /// <param name="id"> The unique identifier of the device. </param>
 90        /// <param name="cancellationToken"> The cancellation token to use. </param>
 91        /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception>
 92        public Response<PurgeMessageQueueResult> PurgeCloudToDeviceMessageQueue(string id, CancellationToken cancellatio
 93        {
 094            if (id == null)
 95            {
 096                throw new ArgumentNullException(nameof(id));
 97            }
 98
 099            using var message = CreatePurgeCloudToDeviceMessageQueueRequest(id);
 0100            _pipeline.Send(message, cancellationToken);
 0101            switch (message.Response.Status)
 102            {
 103                case 200:
 104                    {
 105                        PurgeMessageQueueResult value = default;
 0106                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0107                        value = PurgeMessageQueueResult.DeserializePurgeMessageQueueResult(document.RootElement);
 0108                        return Response.FromValue(value, message.Response);
 109                    }
 110                default:
 0111                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 112            }
 0113        }
 114    }
 115}