< Summary

Class:Azure.AI.FormRecognizer.Training.CopyAuthorization
Assembly:Azure.AI.FormRecognizer
File(s):C:\Git\azure-sdk-for-net\sdk\formrecognizer\Azure.AI.FormRecognizer\src\CopyAuthorization.cs
Covered lines:35
Uncovered lines:0
Coverable lines:35
Total lines:82
Line coverage:100% (35 of 35)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_ModelId()-100%100%
get_ExpiresOn()-100%100%
get_AccessToken()-100%100%
get_ResourceId()-100%100%
get_Region()-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
FromJson(...)-100%100%
ToJson()-100%100%
get_modelId()-100%100%
get_accessToken()-100%100%
get_expirationDateTimeTicks()-100%100%
get_resourceId()-100%100%
get_resourceRegion()-100%100%
.ctor()-100%100%
.ctor(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\formrecognizer\Azure.AI.FormRecognizer\src\CopyAuthorization.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text.Json;
 6using Azure.AI.FormRecognizer.Models;
 7
 8namespace Azure.AI.FormRecognizer.Training
 9{
 10    /// <summary>
 11    /// Authorization for copying a custom model into the target Form Recognizer resource.
 12    /// </summary>
 13    public class CopyAuthorization
 14    {
 15        /// <summary>Model identifier in the target Form Recognizer Resource. </summary>
 5216        public string ModelId { get; }
 17        /// <summary> The time when the access token expires. The date is represented as the number of seconds from 1970
 2818        public DateTimeOffset ExpiresOn { get; }
 19        /// <summary> Token claim used to authorize the request. </summary>
 2820        internal string AccessToken { get; }
 21        /// <summary> Azure Resource Id of the target Form Recognizer resource where the model is copied to. </summary>
 2822        internal string ResourceId { get; }
 23        /// <summary> Location of the target Form Recognizer resource. A valid Azure region name supported by Cognitive 
 2824        internal string Region { get; }
 25
 2826        internal CopyAuthorization(string modelId, string accessToken, long expirationDateTimeTicks, string resourceId, 
 27        {
 2828            ModelId = modelId;
 2829            AccessToken = accessToken;
 2830            ExpiresOn = DateTimeOffset.FromUnixTimeSeconds(expirationDateTimeTicks);
 2831            ResourceId = resourceId;
 2832            Region = region;
 2833        }
 34
 35        internal CopyAuthorization(CopyAuthorizationResult copyAuth, string resourceId, string region)
 4036            : this(copyAuth.ModelId, copyAuth.AccessToken, copyAuth.ExpirationDateTimeTicks, resourceId, region) { }
 37
 38        /// <summary>
 39        /// Deserializes an opaque string into a <see cref="CopyAuthorization"/> object.
 40        /// </summary>
 41        /// <param name="copyAuthorization">Opaque string with the copy authorization information for a specific model.<
 42        public static CopyAuthorization FromJson(string copyAuthorization)
 43        {
 444            CopyAuthorizationParse parse = JsonSerializer.Deserialize<CopyAuthorizationParse>(copyAuthorization);
 445            return new CopyAuthorization(
 446                parse.modelId,
 447                parse.accessToken,
 448                parse.expirationDateTimeTicks,
 449                parse.resourceId,
 450                parse.resourceRegion);
 51        }
 52
 53        /// <summary>
 54        /// Converts the CopyAuthorization object to its equivalent JSON representation.
 55        /// </summary>
 56        public string ToJson()
 57        {
 458            var toParse = new CopyAuthorizationParse(this);
 459            return JsonSerializer.Serialize(toParse);
 60        }
 61
 62        private class CopyAuthorizationParse
 63        {
 1664            public string modelId { get; set; }
 1665            public string accessToken { get; set; }
 1666            public long expirationDateTimeTicks { get; set; }
 1667            public string resourceId { get; set; }
 1668            public string resourceRegion { get; set; }
 69
 870            public CopyAuthorizationParse() { }
 71
 472            public CopyAuthorizationParse(CopyAuthorization target)
 73            {
 474                modelId = target.ModelId;
 475                accessToken = target.AccessToken;
 476                expirationDateTimeTicks = target.ExpiresOn.ToUnixTimeSeconds();
 477                resourceId = target.ResourceId;
 478                resourceRegion = target.Region;
 479            }
 80        }
 81    }
 82}