< Summary

Class:Azure.DigitalTwins.Core.Serialization.BasicRelationship
Assembly:Azure.DigitalTwins.Core
File(s):C:\Git\azure-sdk-for-net\sdk\digitaltwins\Azure.DigitalTwins.Core\src\Serialization\BasicRelationship.cs
Covered lines:4
Uncovered lines:1
Coverable lines:5
Total lines:83
Line coverage:80% (4 of 5)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Id()-100%100%
get_TargetId()-100%100%
get_SourceId()-100%100%
get_Name()-100%100%
get_CustomProperties()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\digitaltwins\Azure.DigitalTwins.Core\src\Serialization\BasicRelationship.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Text.Json.Serialization;
 6
 7namespace Azure.DigitalTwins.Core.Serialization
 8{
 9    /// <summary>
 10    /// Although relationships have a user-defined schema, these properties should exist on every instance. This is
 11    /// useful to use as a base class to ensure your custom relationships have the necessary properties.
 12    /// </summary>
 13    /// <remarks>
 14    /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/digitaltwins/Azure.D
 15    /// </remarks>
 16    /// <example>
 17    /// Here's an example of how to use the BasicRelationship helper class to serialize and create a relationship from a
 18    ///
 19    /// <code snippet="Snippet:DigitalTwinsSampleCreateBasicRelationship">
 20    /// var buildingFloorRelationshipPayload = new BasicRelationship
 21    /// {
 22    ///     Id = &quot;buildingFloorRelationshipId&quot;,
 23    ///     SourceId = &quot;buildingTwinId&quot;,
 24    ///     TargetId = &quot;floorTwinId&quot;,
 25    ///     Name = &quot;contains&quot;,
 26    ///     CustomProperties =
 27    ///     {
 28    ///         { &quot;Prop1&quot;, &quot;Prop1 value&quot; },
 29    ///         { &quot;Prop2&quot;, 6 }
 30    ///     }
 31    /// };
 32    ///
 33    /// string serializedRelationship = JsonSerializer.Serialize(buildingFloorRelationshipPayload);
 34    /// await client.CreateRelationshipAsync(&quot;buildingTwinId&quot;, &quot;buildingFloorRelationshipId&quot;, serial
 35    /// Console.WriteLine($&quot;Created a digital twin relationship &apos;buildingFloorRelationshipId&apos; from twin &
 36    /// </code>
 37    ///
 38    /// Here's an example of how to use the BasicRelationship helper class to get and deserialize a relationship.
 39    ///
 40    /// <code snippet="Snippet:DigitalTwinsSampleGetBasicRelationship">
 41    /// Response&lt;string&gt; getBasicRelationshipResponse = await client.GetRelationshipAsync(&quot;buildingTwinId&quo
 42    /// if (getBasicRelationshipResponse.GetRawResponse().Status == (int)HttpStatusCode.OK)
 43    /// {
 44    ///     BasicRelationship basicRelationship = JsonSerializer.Deserialize&lt;BasicRelationship&gt;(getBasicRelationsh
 45    ///     Console.WriteLine($&quot;Retrieved relationship &apos;{basicRelationship.Id}&apos; from twin {basicRelations
 46    ///         $&quot;Prop1: {basicRelationship.CustomProperties[&quot;Prop1&quot;]}\n\t&quot; +
 47    ///         $&quot;Prop2: {basicRelationship.CustomProperties[&quot;Prop2&quot;]}&quot;);
 48    /// }
 49    /// </code>
 50    /// </example>
 51    public class BasicRelationship
 52    {
 53        /// <summary>
 54        /// The unique Id of the relationship. This field is present on every relationship.
 55        /// </summary>
 56        [JsonPropertyName("$relationshipId")]
 457        public string Id { get; set; }
 58
 59        /// <summary>
 60        /// The unique Id of the target digital twin. This field is present on every relationship.
 61        /// </summary>
 62        [JsonPropertyName("$targetId")]
 463        public string TargetId { get; set; }
 64
 65        /// <summary>
 66        /// The unique Id of the source digital twin. This field is present on every relationship.
 67        /// </summary>
 68        [JsonPropertyName("$sourceId")]
 469        public string SourceId { get; set; }
 70
 71        /// <summary>
 72        /// The name of the relationship, which defines the type of link (e.g. Contains). This field is present on every
 73        /// </summary>
 74        [JsonPropertyName("$relationshipName")]
 475        public string Name { get; set; }
 76
 77        /// <summary>
 78        /// Additional properties defined in the model. This field will contain any properties of the relationship that 
 79        /// </summary>
 80        [JsonExtensionData]
 081        public IDictionary<string, object> CustomProperties { get; set; } = new Dictionary<string, object>();
 82    }
 83}