< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
CreateGetRequest()-0%100%
GetAsync()-0%0%
Get(...)-0%0%
CreateSetRequest(...)-0%100%
SetAsync()-0%0%
Set(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Generated\FaultInjectionRestClient.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 FaultInjectionRestClient
 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 FaultInjectionRestClient. </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 FaultInjectionRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null,
 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 CreateGetRequest()
 47        {
 048            var message = _pipeline.CreateMessage();
 049            var request = message.Request;
 050            request.Method = RequestMethod.Get;
 051            var uri = new RawRequestUriBuilder();
 052            uri.Reset(endpoint);
 053            uri.AppendPath("/faultInjection", false);
 054            uri.AppendQuery("api-version", apiVersion, true);
 055            request.Uri = uri;
 056            return message;
 57        }
 58
 59        /// <summary> Gets the FaultInjection entity. </summary>
 60        /// <param name="cancellationToken"> The cancellation token to use. </param>
 61        public async Task<Response<FaultInjectionProperties>> GetAsync(CancellationToken cancellationToken = default)
 62        {
 063            using var message = CreateGetRequest();
 064            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 065            switch (message.Response.Status)
 66            {
 67                case 200:
 68                    {
 69                        FaultInjectionProperties value = default;
 070                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 071                        value = FaultInjectionProperties.DeserializeFaultInjectionProperties(document.RootElement);
 072                        return Response.FromValue(value, message.Response);
 73                    }
 74                default:
 075                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 76            }
 077        }
 78
 79        /// <summary> Gets the FaultInjection entity. </summary>
 80        /// <param name="cancellationToken"> The cancellation token to use. </param>
 81        public Response<FaultInjectionProperties> Get(CancellationToken cancellationToken = default)
 82        {
 083            using var message = CreateGetRequest();
 084            _pipeline.Send(message, cancellationToken);
 085            switch (message.Response.Status)
 86            {
 87                case 200:
 88                    {
 89                        FaultInjectionProperties value = default;
 090                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 091                        value = FaultInjectionProperties.DeserializeFaultInjectionProperties(document.RootElement);
 092                        return Response.FromValue(value, message.Response);
 93                    }
 94                default:
 095                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 96            }
 097        }
 98
 99        internal HttpMessage CreateSetRequest(FaultInjectionProperties value)
 100        {
 0101            var message = _pipeline.CreateMessage();
 0102            var request = message.Request;
 0103            request.Method = RequestMethod.Put;
 0104            var uri = new RawRequestUriBuilder();
 0105            uri.Reset(endpoint);
 0106            uri.AppendPath("/faultInjection", false);
 0107            uri.AppendQuery("api-version", apiVersion, true);
 0108            request.Uri = uri;
 0109            request.Headers.Add("Content-Type", "application/json");
 0110            var content = new Utf8JsonRequestContent();
 0111            content.JsonWriter.WriteObjectValue(value);
 0112            request.Content = content;
 0113            return message;
 114        }
 115
 116        /// <summary> Creates or updates the FaultInjection entity. </summary>
 117        /// <param name="value"> The FaultInjectionProperties to use. </param>
 118        /// <param name="cancellationToken"> The cancellation token to use. </param>
 119        /// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
 120        public async Task<Response> SetAsync(FaultInjectionProperties value, CancellationToken cancellationToken = defau
 121        {
 0122            if (value == null)
 123            {
 0124                throw new ArgumentNullException(nameof(value));
 125            }
 126
 0127            using var message = CreateSetRequest(value);
 0128            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0129            switch (message.Response.Status)
 130            {
 131                case 200:
 0132                    return message.Response;
 133                default:
 0134                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 135            }
 0136        }
 137
 138        /// <summary> Creates or updates the FaultInjection entity. </summary>
 139        /// <param name="value"> The FaultInjectionProperties to use. </param>
 140        /// <param name="cancellationToken"> The cancellation token to use. </param>
 141        /// <exception cref="ArgumentNullException"> <paramref name="value"/> is null. </exception>
 142        public Response Set(FaultInjectionProperties value, CancellationToken cancellationToken = default)
 143        {
 0144            if (value == null)
 145            {
 0146                throw new ArgumentNullException(nameof(value));
 147            }
 148
 0149            using var message = CreateSetRequest(value);
 0150            _pipeline.Send(message, cancellationToken);
 0151            switch (message.Response.Status)
 152            {
 153                case 200:
 0154                    return message.Response;
 155                default:
 0156                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 157            }
 0158        }
 159    }
 160}