diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/api/Azure.DigitalTwins.Core.netstandard2.0.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/api/Azure.DigitalTwins.Core.netstandard2.0.cs index 2bdd72cf8777..f4d2c424039d 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/api/Azure.DigitalTwins.Core.netstandard2.0.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/api/Azure.DigitalTwins.Core.netstandard2.0.cs @@ -97,12 +97,12 @@ public DigitalTwinsClient(System.Uri endpoint, Azure.Core.TokenCredential creden public virtual System.Threading.Tasks.Task PublishTelemetryAsync(string digitalTwinId, string messageId, string payload, Azure.DigitalTwins.Core.PublishTelemetryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Pageable Query(string query, Azure.DigitalTwins.Core.QueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.AsyncPageable QueryAsync(string query, Azure.DigitalTwins.Core.QueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response UpdateComponent(string digitalTwinId, string componentName, string jsonPatch, Azure.DigitalTwins.Core.UpdateComponentOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task UpdateComponentAsync(string digitalTwinId, string componentName, string jsonPatch, Azure.DigitalTwins.Core.UpdateComponentOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response UpdateDigitalTwin(string digitalTwinId, string jsonPatch, Azure.DigitalTwins.Core.UpdateDigitalTwinOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task UpdateDigitalTwinAsync(string digitalTwinId, string jsonPatch, Azure.DigitalTwins.Core.UpdateDigitalTwinOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response UpdateRelationship(string digitalTwinId, string relationshipId, string jsonPatch, Azure.DigitalTwins.Core.UpdateRelationshipOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task UpdateRelationshipAsync(string digitalTwinId, string relationshipId, string jsonPatch, Azure.DigitalTwins.Core.UpdateRelationshipOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateComponent(string digitalTwinId, string componentName, Azure.JsonPatchDocument jsonPatchDocument, Azure.DigitalTwins.Core.UpdateComponentOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdateComponentAsync(string digitalTwinId, string componentName, Azure.JsonPatchDocument jsonPatchDocument, Azure.DigitalTwins.Core.UpdateComponentOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateDigitalTwin(string digitalTwinId, Azure.JsonPatchDocument jsonPatchDocument, Azure.DigitalTwins.Core.UpdateDigitalTwinOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdateDigitalTwinAsync(string digitalTwinId, Azure.JsonPatchDocument jsonPatchDocument, Azure.DigitalTwins.Core.UpdateDigitalTwinOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateRelationship(string digitalTwinId, string relationshipId, Azure.JsonPatchDocument jsonPatchDocument, Azure.DigitalTwins.Core.UpdateRelationshipOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdateRelationshipAsync(string digitalTwinId, string relationshipId, Azure.JsonPatchDocument jsonPatchDocument, Azure.DigitalTwins.Core.UpdateRelationshipOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } public partial class DigitalTwinsClientOptions : Azure.Core.ClientOptions { @@ -300,14 +300,6 @@ public ModelProperties() { } [System.Text.Json.Serialization.JsonPropertyNameAttribute("$metadata")] public Azure.DigitalTwins.Core.Serialization.ComponentMetadata Metadata { get { throw null; } } } - public partial class UpdateOperationsUtility - { - public UpdateOperationsUtility() { } - public void AppendAddOp(string path, object value) { } - public void AppendRemoveOp(string path) { } - public void AppendReplaceOp(string path, object value) { } - public string Serialize() { throw null; } - } public partial class WritableProperty { public WritableProperty() { } diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs index 629403d268ee..1b0fb85ee253 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/ComponentSamples.cs @@ -153,10 +153,9 @@ await client.CreateModelsAsync( // Update Component1 by replacing the property ComponentProp1 value, // using an optional utility to build the payload. - var componentUpdateUtility = new UpdateOperationsUtility(); - componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value"); - string updatePayload = componentUpdateUtility.Serialize(); - await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload); + var componentJsonPatchDocument = new JsonPatchDocument(); + componentJsonPatchDocument.AppendReplace("/ComponentProp1", "Some new value"); + await client.UpdateComponentAsync(basicDtId, "Component1", componentJsonPatchDocument); Console.WriteLine($"Updated component for digital twin '{basicDtId}'."); #endregion Snippet:DigitalTwinsSampleUpdateComponent diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md index 93ef64296694..ebbbd9a36596 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md @@ -288,10 +288,9 @@ To update a component or in other words to replace, remove and/or add a componen ```C# Snippet:DigitalTwinsSampleUpdateComponent // Update Component1 by replacing the property ComponentProp1 value, // using an optional utility to build the payload. -var componentUpdateUtility = new UpdateOperationsUtility(); -componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value"); -string updatePayload = componentUpdateUtility.Serialize(); -await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload); +var componentJsonPatchDocument = new JsonPatchDocument(); +componentJsonPatchDocument.AppendReplace("/ComponentProp1", "Some new value"); +await client.UpdateComponentAsync(basicDtId, "Component1", componentJsonPatchDocument); Console.WriteLine($"Updated component for digital twin '{basicDtId}'."); ``` diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Azure.DigitalTwins.Core.csproj b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Azure.DigitalTwins.Core.csproj index 78deb0cf0071..7ee621e5f3b6 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Azure.DigitalTwins.Core.csproj +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Azure.DigitalTwins.Core.csproj @@ -1,4 +1,4 @@ - + Digital Twins SDK @@ -51,5 +51,17 @@ - + + + + + + + + + diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs index 5c4c040acf1b..35b6a443eff7 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClient.cs @@ -298,7 +298,7 @@ public virtual Response DeleteDigitalTwin(string digitalTwinId, DeleteDigitalTwi /// Updates a digital twin asynchronously. /// /// The Id of the digital twin to update. - /// The application/json-patch+json operations to be performed on the specified digital twin. + /// The application/json-patch+json operations to be performed on the specified digital twin. /// The optional parameters for this request. If null, the default option values will be used. /// The cancellationToken. /// The http response . @@ -309,18 +309,19 @@ public virtual Response DeleteDigitalTwin(string digitalTwinId, DeleteDigitalTwi /// The exception that captures the errors from the service. Check the and properties for more details. /// /// - /// The exception is thrown when or is null. + /// The exception is thrown when or is null. /// - public virtual Task UpdateDigitalTwinAsync(string digitalTwinId, string jsonPatch, UpdateDigitalTwinOptions options = null, CancellationToken cancellationToken = default) + public virtual Task UpdateDigitalTwinAsync(string digitalTwinId, JsonPatchDocument jsonPatchDocument, UpdateDigitalTwinOptions options = null, CancellationToken cancellationToken = default) { - return _dtRestClient.UpdateAsync(digitalTwinId, jsonPatch, options, cancellationToken); + Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); + return _dtRestClient.UpdateAsync(digitalTwinId, jsonPatchDocument.ToString(), options, cancellationToken); } /// /// Updates a digital twin synchronously. /// /// The Id of the digital twin to update. - /// The application/json-patch+json operations to be performed on the specified digital twin. + /// The application/json-patch+json operations to be performed on the specified digital twin. /// The optional parameters for this request. If null, the default option values will be used. /// The cancellationToken. /// The http response . @@ -331,14 +332,15 @@ public virtual Task UpdateDigitalTwinAsync(string digitalTwinId, strin /// The exception that captures the errors from the service. Check the and properties for more details. /// /// - /// The exception is thrown when or is null. + /// The exception is thrown when or is null. /// - /// + /// /// See the asynchronous version of this method for examples. /// - public virtual Response UpdateDigitalTwin(string digitalTwinId, string jsonPatch, UpdateDigitalTwinOptions options = null, CancellationToken cancellationToken = default) + public virtual Response UpdateDigitalTwin(string digitalTwinId, JsonPatchDocument jsonPatchDocument, UpdateDigitalTwinOptions options = null, CancellationToken cancellationToken = default) { - return _dtRestClient.Update(digitalTwinId, jsonPatch, options, cancellationToken); + Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); + return _dtRestClient.Update(digitalTwinId, jsonPatchDocument.ToString(), options, cancellationToken); } /// @@ -399,7 +401,7 @@ public virtual Response GetComponent(string digitalTwinId, string compon /// /// The Id of the digital twin. /// The component being modified. - /// The application/json-patch+json operations to be performed on the specified digital twin's component. + /// The application/json-patch+json operations to be performed on the specified digital twin's component. /// The optional parameters for this request. If null, the default option values will be used. /// The cancellation token. /// The HTTP response . @@ -416,16 +418,16 @@ public virtual Response GetComponent(string digitalTwinId, string compon /// /// // Update Component1 by replacing the property ComponentProp1 value, /// // using an optional utility to build the payload. - /// var componentUpdateUtility = new UpdateOperationsUtility(); - /// componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value"); - /// string updatePayload = componentUpdateUtility.Serialize(); - /// await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload); + /// var componentJsonPatchDocument = new JsonPatchDocument(); + /// componentJsonPatchDocument.AppendReplace("/ComponentProp1", "Some new value"); + /// await client.UpdateComponentAsync(basicDtId, "Component1", componentJsonPatchDocument); /// Console.WriteLine($"Updated component for digital twin '{basicDtId}'."); /// /// - public virtual Task UpdateComponentAsync(string digitalTwinId, string componentName, string jsonPatch, UpdateComponentOptions options = null, CancellationToken cancellationToken = default) + public virtual Task UpdateComponentAsync(string digitalTwinId, string componentName, JsonPatchDocument jsonPatchDocument, UpdateComponentOptions options = null, CancellationToken cancellationToken = default) { - return _dtRestClient.UpdateComponentAsync(digitalTwinId, componentName, jsonPatch, options, cancellationToken); + Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); + return _dtRestClient.UpdateComponentAsync(digitalTwinId, componentName, jsonPatchDocument.ToString(), options, cancellationToken); } /// @@ -433,7 +435,7 @@ public virtual Task UpdateComponentAsync(string digitalTwinId, string /// /// The Id of the digital twin. /// The component being modified. - /// The application/json-patch+json operations to be performed on the specified digital twin's component. + /// The application/json-patch+json operations to be performed on the specified digital twin's component. /// The optional parameters for this request. If null, the default option values will be used. /// The cancellation token. /// The HTTP response . @@ -446,12 +448,13 @@ public virtual Task UpdateComponentAsync(string digitalTwinId, string /// /// The exception that captures the errors from the service. Check the and properties for more details. /// - /// + /// /// See the asynchronous version of this method for examples. /// - public virtual Response UpdateComponent(string digitalTwinId, string componentName, string jsonPatch, UpdateComponentOptions options = null, CancellationToken cancellationToken = default) + public virtual Response UpdateComponent(string digitalTwinId, string componentName, JsonPatchDocument jsonPatchDocument, UpdateComponentOptions options = null, CancellationToken cancellationToken = default) { - return _dtRestClient.UpdateComponent(digitalTwinId, componentName, jsonPatch, options, cancellationToken); + Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); + return _dtRestClient.UpdateComponent(digitalTwinId, componentName, jsonPatchDocument.ToString(), options, cancellationToken); } /// @@ -903,7 +906,7 @@ public virtual Response CreateRelationship(string digitalTwinId, string /// /// The Id of the source digital twin. /// The Id of the relationship to be updated. - /// The application/json-patch+json operations to be performed on the specified digital twin's relationship. + /// The application/json-patch+json operations to be performed on the specified digital twin's relationship. /// The optional parameters for this request. If null, the default option values will be used. /// The cancellation token. /// The http response . @@ -916,9 +919,10 @@ public virtual Response CreateRelationship(string digitalTwinId, string /// /// The exception is thrown when or is null. /// - public virtual Task UpdateRelationshipAsync(string digitalTwinId, string relationshipId, string jsonPatch, UpdateRelationshipOptions options = null, CancellationToken cancellationToken = default) + public virtual Task UpdateRelationshipAsync(string digitalTwinId, string relationshipId, JsonPatchDocument jsonPatchDocument, UpdateRelationshipOptions options = null, CancellationToken cancellationToken = default) { - return _dtRestClient.UpdateRelationshipAsync(digitalTwinId, relationshipId, jsonPatch, options, cancellationToken); + Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); + return _dtRestClient.UpdateRelationshipAsync(digitalTwinId, relationshipId, jsonPatchDocument.ToString(), options, cancellationToken); } /// @@ -926,7 +930,7 @@ public virtual Task UpdateRelationshipAsync(string digitalTwinId, stri /// /// The Id of the source digital twin. /// The Id of the relationship to be updated. - /// The application/json-patch+json operations to be performed on the specified digital twin's relationship. + /// The application/json-patch+json operations to be performed on the specified digital twin's relationship. /// The optional parameters for this request. If null, the default option values will be used. /// The cancellation token. /// The http response . @@ -939,12 +943,13 @@ public virtual Task UpdateRelationshipAsync(string digitalTwinId, stri /// /// The exception is thrown when or is null. /// - /// + /// /// See the asynchronous version of this method for examples. /// - public virtual Response UpdateRelationship(string digitalTwinId, string relationshipId, string jsonPatch, UpdateRelationshipOptions options = null, CancellationToken cancellationToken = default) + public virtual Response UpdateRelationship(string digitalTwinId, string relationshipId, JsonPatchDocument jsonPatchDocument, UpdateRelationshipOptions options = null, CancellationToken cancellationToken = default) { - return _dtRestClient.UpdateRelationship(digitalTwinId, relationshipId, jsonPatch, options, cancellationToken); + Argument.AssertNotNull(jsonPatchDocument, nameof(jsonPatchDocument)); + return _dtRestClient.UpdateRelationship(digitalTwinId, relationshipId, jsonPatchDocument.ToString(), options, cancellationToken); } /// diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs deleted file mode 100644 index 11637d46a00b..000000000000 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/src/Serialization/UpdateOperationsUtility.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Collections.Generic; -using System.Text.Json; - -namespace Azure.DigitalTwins.Core.Serialization -{ - /// - /// A utility to create the application/json-patch+json operations payload required for update operations. - /// - /// - /// For more samples, see our repo samples. - /// - /// - /// - /// // Update Component1 by replacing the property ComponentProp1 value, - /// // using an optional utility to build the payload. - /// var componentUpdateUtility = new UpdateOperationsUtility(); - /// componentUpdateUtility.AppendReplaceOp("/ComponentProp1", "Some new value"); - /// string updatePayload = componentUpdateUtility.Serialize(); - /// await client.UpdateComponentAsync(basicDtId, "Component1", updatePayload); - /// Console.WriteLine($"Updated component for digital twin '{basicDtId}'."); - /// - /// - public class UpdateOperationsUtility - { - private const string Op = "op"; - private const string Add = "add"; - private const string Replace = "replace"; - private const string Remove = "remove"; - private const string Path = "path"; - private const string Value = "value"; - - private readonly List> _ops = new List>(); - - /// - /// Include an add operation. - /// - /// The path to the property to be added. - /// The value to update to. - public void AppendAddOp(string path, object value) - { - var op = new Dictionary - { - { Op, Add }, - { Path, path }, - { Value, value }, - }; - _ops.Add(op); - } - - /// - /// Include a replace operation. - /// - /// The path to the property to be updated. - /// The value to update to. - public void AppendReplaceOp(string path, object value) - { - var op = new Dictionary - { - { Op, Replace }, - { Path, path }, - { Value, value }, - }; - _ops.Add(op); - } - - /// - /// Include a remove operation. - /// - /// The path to the property to be added. - public void AppendRemoveOp(string path) - { - var op = new Dictionary - { - { Op, Remove }, - { Path, path }, - }; - _ops.Add(op); - } - - /// - /// Serialize the constructed payload as json. - /// - /// A string of the json payload. - public string Serialize() - { - return JsonSerializer.Serialize(_ops); - } - } -} diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/ComponentTests.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/ComponentTests.cs index fe091b89826e..17e8fe591e37 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/ComponentTests.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/ComponentTests.cs @@ -58,11 +58,14 @@ public async Task Component_Lifecycle() getComponentResponse.GetRawResponse().Status.Should().Be((int)HttpStatusCode.OK); // Patch component + JsonPatchDocument componentUpdatePatchDocument = new JsonPatchDocument(); + componentUpdatePatchDocument.AppendReplace("/Network", "New Network"); + Response updateComponentResponse = await client .UpdateComponentAsync( roomWithWifiTwinId, wifiComponentName, - TestAssetsHelper.GetWifiComponentUpdatePayload()) + componentUpdatePatchDocument) .ConfigureAwait(false); // The response to the Patch request should be 204 (No content) diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinRelationshipTests.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinRelationshipTests.cs index 02acf309b279..c0493a919bfc 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinRelationshipTests.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinRelationshipTests.cs @@ -73,7 +73,8 @@ public async Task Relationships_Lifecycle() string floorTwinCoolsRelationshipPayload = TestAssetsHelper.GetRelationshipPayload(floorTwinId, CoolsRelationship); string floorTwinContainedInRelationshipPayload = TestAssetsHelper.GetRelationshipPayload(floorTwinId, ContainedInRelationship); string floorCooledByHvacPayload = TestAssetsHelper.GetRelationshipPayload(hvacTwinId, CooledByRelationship); - string floorContainsRoomUpdatePayload = TestAssetsHelper.GetRelationshipUpdatePayload("/isAccessRestricted", false); + JsonPatchDocument floorContainsRoomUpdatePayload = new JsonPatchDocument(); + floorContainsRoomUpdatePayload.AppendReplace("/isAccessRestricted", false); // CREATE relationships diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinTests.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinTests.cs index 725e3d964292..92c9fff10f97 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinTests.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/DigitalTwinTests.cs @@ -47,14 +47,17 @@ public async Task DigitalTwins_Lifecycle() await client.GetDigitalTwinAsync(roomTwinId).ConfigureAwait(false); // update twin - string updateTwin = TestAssetsHelper.GetRoomTwinUpdatePayload(); + JsonPatchDocument updateTwinPatchDocument = new JsonPatchDocument(); + updateTwinPatchDocument.AppendAdd("/Humidity", 30); + updateTwinPatchDocument.AppendReplace("/Temperature", 70); + updateTwinPatchDocument.AppendRemove("/EmployeeId"); var requestOptions = new UpdateDigitalTwinOptions { IfMatch = "*" }; - await client.UpdateDigitalTwinAsync(roomTwinId, updateTwin, requestOptions).ConfigureAwait(false); + await client.UpdateDigitalTwinAsync(roomTwinId, updateTwinPatchDocument, requestOptions).ConfigureAwait(false); // delete a twin await client.DeleteDigitalTwinAsync(roomTwinId).ConfigureAwait(false); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/TestAssetsHelper.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/TestAssetsHelper.cs index 2eb1e23618a4..fc5ad724dfba 100644 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/TestAssetsHelper.cs +++ b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/TestAssetsHelper.cs @@ -50,22 +50,6 @@ public static string GetWardModelPayload(string wardModelId) return RemoveNewLines(TestAssets.WardModelPayload.Replace("WARD_MODEL_ID", wardModelId)); } - public static string GetRoomTwinUpdatePayload() - { - var uou = new UpdateOperationsUtility(); - uou.AppendAddOp("/Humidity", 30); - uou.AppendReplaceOp("/Temperature", 70); - uou.AppendRemoveOp("/EmployeeId"); - return RemoveNewLines(uou.Serialize()); - } - - public static string GetWifiComponentUpdatePayload() - { - var uou = new UpdateOperationsUtility(); - uou.AppendReplaceOp("/Network", "New Network"); - return RemoveNewLines(uou.Serialize()); - } - public static string GetFloorTwinPayload(string floorModelId) { return RemoveNewLines(TestAssets.FloorTwinPayload.Replace("FLOOR_MODEL_ID", floorModelId)); @@ -92,13 +76,6 @@ public static string GetRelationshipWithPropertyPayload(string targetTwinId, str .Replace("\"PROPERTY_VALUE\"", propertyValue.ToString().ToLower())); } - public static string GetRelationshipUpdatePayload(string propertyName, bool propertyValue) - { - var uou = new UpdateOperationsUtility(); - uou.AppendReplaceOp(propertyName, propertyValue); - return RemoveNewLines(uou.Serialize()); - } - public static string GetWifiModelPayload(string wifiModelId) { return RemoveNewLines(TestAssets.WifiModelPayload.Replace("WIFI_MODEL_ID", wifiModelId)); diff --git a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/UpdateOperationsUtilityUnitTests.cs b/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/UpdateOperationsUtilityUnitTests.cs deleted file mode 100644 index 716a7737a470..000000000000 --- a/sdk/digitaltwins/Azure.DigitalTwins.Core/tests/UpdateOperationsUtilityUnitTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Text.Json; -using Azure.DigitalTwins.Core.Serialization; -using FluentAssertions; -using NUnit.Framework; - -namespace Azure.DigitalTwins.Core.Tests -{ - [Category("Unit")] - [Parallelizable(ParallelScope.All)] - public class UpdateOperationsUtilityUnitTests - { - [Test] - public void UpdateOperationsUtility_BuildAdd() - { - // arrange - - const string addOp = "add"; - const string replaceOp = "replace"; - const string removeOp = "remove"; - - const string addPath = "/addComponentPath123"; - const string addValue = "value123"; - const string replacePath = "/replaceComponentPath123"; - const string replaceValue = "value456"; - const string removePath = "/removeComponentPath123"; - - var dtUpdateUtility = new UpdateOperationsUtility(); - dtUpdateUtility.AppendAddOp(addPath, addValue); - dtUpdateUtility.AppendReplaceOp(replacePath, replaceValue); - dtUpdateUtility.AppendRemoveOp(removePath); - - // act - string actual = dtUpdateUtility.Serialize(); - - // assert - - JsonDocument parsed = JsonDocument.Parse(actual); - parsed.RootElement.ValueKind.Should().Be(JsonValueKind.Array, "operations should be nested in an array"); - parsed.RootElement.GetArrayLength().Should().Be(3, "three operations were included"); - - JsonElement addElement = parsed.RootElement[0]; - addElement.GetProperty("op").GetString().Should().Be(addOp); - addElement.GetProperty("path").GetString().Should().Be(addPath); - addElement.GetProperty("value").GetString().Should().Be(addValue); - - JsonElement replaceElement = parsed.RootElement[1]; - replaceElement.GetProperty("op").GetString().Should().Be(replaceOp); - replaceElement.GetProperty("path").GetString().Should().Be(replacePath); - replaceElement.GetProperty("value").GetString().Should().Be(replaceValue); - - JsonElement removeElement = parsed.RootElement[2]; - removeElement.GetProperty("op").GetString().Should().Be(removeOp); - removeElement.GetProperty("path").GetString().Should().Be(removePath); - removeElement.TryGetProperty("value", out _).Should().BeFalse(); - } - } -}