From 10f6ad0c6416ee7b84427b30a3068fec2005e6aa Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Wed, 24 Mar 2021 16:18:02 -0700 Subject: [PATCH 1/5] Change the accessbility to virtual for Resource.Id --- .../Azure.ResourceManager.Core/src/Resources/Resource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs index 86a35ac05cf7..a8638d1c689b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs @@ -14,7 +14,7 @@ public abstract class Resource : IEquatable, IEquatable, IComp /// /// Gets or sets the resource identifier. /// - public abstract ResourceIdentifier Id { get; protected set; } + public virtual ResourceIdentifier Id { get; protected set; } /// /// Gets the name. From 17415b6906540957c827072cd6d78c36a1db82c3 Mon Sep 17 00:00:00 2001 From: George Arama Date: Wed, 26 May 2021 18:29:00 -0700 Subject: [PATCH 2/5] Sub resource template and tests --- .../Resources/SubResource.Serialization.cs | 6 +- .../src/Resources/SubResource.cs | 71 +++++++++++++++--- .../WritableSubResource.Serialization.cs | 12 ++-- .../src/Resources/WritableSubResource.cs | 72 ++++++++++++++++--- .../tests/Unit/SubResourceTests.cs | 65 +++++++++++++++++ .../tests/Unit/WritableSubResourceTests.cs | 65 +++++++++++++++++ 6 files changed, 266 insertions(+), 25 deletions(-) create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs index 764903ec8171..e3c703fa9eb1 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs @@ -10,7 +10,7 @@ namespace Azure.ResourceManager.Core /// /// A class representing a sub-resource that contains only the ID. /// - public partial class SubResource : IUtf8JsonSerializable + public partial class SubResource : IUtf8JsonSerializable { /// /// Serialize the input SubResource object. @@ -37,7 +37,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) /// /// The JSON element to be deserialized. /// Deserialized SubResource object. - internal static SubResource DeserializeSubResource(JsonElement element) + internal static SubResource DeserializeSubResource(JsonElement element) { Optional id = default; foreach (var property in element.EnumerateObject()) @@ -48,7 +48,7 @@ internal static SubResource DeserializeSubResource(JsonElement element) continue; } } - return new SubResource(id.Value); + return new SubResource(id.Value); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs index 49a2b46b604b..19c78528df6a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -1,34 +1,89 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; + namespace Azure.ResourceManager.Core { + /// + /// A class representing the a sub resource of ResourceIdentifier. + /// + public class SubResource : SubResource + { + /// + /// Initializes an empty instance of for mocking. + /// + [InitializationConstructor] + protected SubResource() { } + + /// Initializes a new instance of . + /// ARM resource Id. + [SerializationConstructor] + protected internal SubResource(string id) : base(id) { } + } + /// /// A class representing a sub-resource that contains only the ID. /// [ReferenceType] - public partial class SubResource + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")] + public partial class SubResource : IEquatable>, IEquatable, + IComparable>, IComparable where TIdentifier : ResourceIdentifier { /// - /// Initializes an empty instance of for mocking. + /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - public SubResource() - { - } + protected SubResource() { } - /// Initializes a new instance of SubResource. + /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] protected internal SubResource(string id) { - Id = id; + Id = ResourceIdentifier.Create(id) as TIdentifier; } /// /// Gets the ARM resource identifier. /// /// - public virtual ResourceIdentifier Id { get; } + public virtual TIdentifier Id { get; } + + /// + public int CompareTo(string other) + { + return string.Compare(Id, other, StringComparison.InvariantCultureIgnoreCase); + } + + /// + public int CompareTo(SubResource other) + { + if (other is null) + return 1; + + if (ReferenceEquals(this, other)) + return 0; + + return Id.CompareTo(other.Id); + } + + /// + public bool Equals(SubResource other) + { + if (Id is null) + return false; + + return Id.Equals(other?.Id); + } + + /// + public bool Equals(string other) + { + if (Id is null) + return false; + + return Id.Equals(other); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs index 7e742920b67d..bd26e9e0dcde 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs @@ -10,10 +10,10 @@ namespace Azure.ResourceManager.Core /// /// A class representing a sub-resource that contains only the ID. /// - public partial class WritableSubResource : IUtf8JsonSerializable + public partial class WritableSubResource : IUtf8JsonSerializable { /// - /// Serialize the input SubResourceReadOnly object. + /// Serialize the input WritableSubResource object. /// /// Input Json writer. void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) @@ -28,11 +28,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } /// - /// Deserialize the input JSON element to a SubResourceReadOnly object. + /// Deserialize the input JSON element to a WritableSubResource object. /// /// The JSON element to be deserialized. - /// Deserialized SubResourceReadOnly object. - internal static WritableSubResource DeserializeSubResourceReadOnly(JsonElement element) + /// Deserialized WritableSubResource object. + internal static WritableSubResource DeserializeWritableSubResource(JsonElement element) { Optional id = default; foreach (var property in element.EnumerateObject()) @@ -43,7 +43,7 @@ internal static WritableSubResource DeserializeSubResourceReadOnly(JsonElement e continue; } } - return new WritableSubResource(id.Value); + return new WritableSubResource(id.Value); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs index b18a480d3bd2..9e429e4a3c67 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs @@ -1,32 +1,88 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; + namespace Azure.ResourceManager.Core { + /// + /// A class representing the a writable sub resource of ResourceIdentifier. + /// + public class WritableSubResource : WritableSubResource + { + /// + /// Initializes an empty instance of for mocking. + /// + [InitializationConstructor] + protected WritableSubResource() { } + + /// Initializes a new instance of . + /// ARM resource Id. + [SerializationConstructor] + protected internal WritableSubResource(string id) : base(id) { } + } + /// /// A class representing a sub-resource that contains only the read-only ID. /// [ReferenceType] - public partial class WritableSubResource + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")] + public partial class WritableSubResource : IEquatable>, IEquatable, + IComparable>, IComparable where TIdentifier : ResourceIdentifier { - /// Initializes a new instance of SubResourceReadOnly. + /// + /// Initializes an empty instance of for mocking. + /// [InitializationConstructor] - public WritableSubResource() - { - } + protected WritableSubResource() { } - /// Initializes a new instance of SubResourceReadOnly. + /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] protected internal WritableSubResource(string id) { - Id = id; + Id = ResourceIdentifier.Create(id) as TIdentifier; } /// /// Gets or sets the ARM resource identifier. /// /// - public virtual ResourceIdentifier Id { get; set; } + public virtual TIdentifier Id { get; set; } + + /// + public int CompareTo(string other) + { + return string.Compare(Id, other, StringComparison.InvariantCultureIgnoreCase); + } + + /// + public int CompareTo(WritableSubResource other) + { + if (other is null) + return 1; + + if (ReferenceEquals(this, other)) + return 0; + return Id.CompareTo(other.Id); + } + + /// + public bool Equals(WritableSubResource other) + { + if (Id is null) + return false; + + return Id.Equals(other?.Id); + } + + /// + public bool Equals(string other) + { + if (Id is null) + return false; + + return Id.Equals(other); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs new file mode 100644 index 000000000000..14dc2a8f9902 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/SubResourceTests.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using NUnit.Framework; + +namespace Azure.ResourceManager.Core.Tests +{ + [Parallelizable] + public class SubResourceTests + { + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] + [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + public void CompareToObject(int expected, string id1, string id2) + { + SubResource resource1 = new SubResource(id1); + SubResource resource2 = new SubResource(id2); + Assert.AreEqual(expected, resource1.CompareTo(resource2)); + } + + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] + [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + public void CompareToString(int expected, string id1, string id2) + { + SubResource resource1 = new SubResource(id1); + Assert.AreEqual(expected, resource1.CompareTo(id2)); + } + + [Test] + public void CompareToNull() + { + var resource1 = new SubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); + SubResource resource2 = null; + Assert.AreEqual(1, resource1.CompareTo(resource2)); + Assert.AreEqual(1, resource1.CompareTo((string)null)); + } + + [Test] + public void CompareToSame() + { + var resource1 = new SubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); + var resource2 = resource1; + Assert.AreEqual(0, resource1.CompareTo(resource2)); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs new file mode 100644 index 000000000000..a5141148820f --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Unit/WritableSubResourceTests.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using NUnit.Framework; + +namespace Azure.ResourceManager.Core.Tests +{ + [Parallelizable] + public class WritableSubResourceTests + { + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] + [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + public void CompareToObject(int expected, string id1, string id2) + { + WritableSubResource resource1 = new WritableSubResource(id1); + WritableSubResource resource2 = new WritableSubResource(id2); + Assert.AreEqual(expected, resource1.CompareTo(resource2)); + } + + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.classicStorage/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account2")] + [TestCase(1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.DiffSpace/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + [TestCase(0, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.${?>._`/storageAccounts/account1")] + [TestCase(-1, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/${?>._`", + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account2")] + public void CompareToString(int expected, string id1, string id2) + { + WritableSubResource resource1 = new WritableSubResource(id1); + Assert.AreEqual(expected, resource1.CompareTo(id2)); + } + + [Test] + public void CompareToNull() + { + var resource1 = new WritableSubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); + WritableSubResource resource2 = null; + Assert.AreEqual(1, resource1.CompareTo(resource2)); + Assert.AreEqual(1, resource1.CompareTo((string)null)); + } + + [Test] + public void CompareToSame() + { + var resource1 = new WritableSubResource("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testRg/providers/Microsoft.ClassicStorage/storageAccounts/account1"); + var resource2 = resource1; + Assert.AreEqual(0, resource1.CompareTo(resource2)); + } + } +} From 81b73ad47629da70a40b5b6b4c567ae25da666be Mon Sep 17 00:00:00 2001 From: George Arama Date: Thu, 27 May 2021 09:44:16 -0700 Subject: [PATCH 3/5] public class , public constructor --- .../Azure.ResourceManager.Core/src/Resources/SubResource.cs | 4 ++-- .../src/Resources/WritableSubResource.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs index 19c78528df6a..5bac91dbd934 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -19,7 +19,7 @@ protected SubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - protected internal SubResource(string id) : base(id) { } + public SubResource(string id) : base(id) { } } /// @@ -39,7 +39,7 @@ protected SubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - protected internal SubResource(string id) + public SubResource(string id) { Id = ResourceIdentifier.Create(id) as TIdentifier; } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs index 9e429e4a3c67..8881ecb1dd42 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs @@ -19,7 +19,7 @@ protected WritableSubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - protected internal WritableSubResource(string id) : base(id) { } + public WritableSubResource(string id) : base(id) { } } /// @@ -39,7 +39,7 @@ protected WritableSubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - protected internal WritableSubResource(string id) + public WritableSubResource(string id) { Id = ResourceIdentifier.Create(id) as TIdentifier; } From 81f8d7352ae8e30d00baf1c813736075907bbf06 Mon Sep 17 00:00:00 2001 From: George Arama Date: Thu, 27 May 2021 10:00:31 -0700 Subject: [PATCH 4/5] some PR comments --- .../src/Resources/SubResource.cs | 20 +++++++++---------- .../src/Resources/WritableSubResource.cs | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs index 5bac91dbd934..2ee2649e8c5d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -8,13 +8,16 @@ namespace Azure.ResourceManager.Core /// /// A class representing the a sub resource of ResourceIdentifier. /// + [ReferenceType] public class SubResource : SubResource { /// /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - protected SubResource() { } + protected SubResource() + { + } /// Initializes a new instance of . /// ARM resource Id. @@ -28,20 +31,23 @@ public SubResource(string id) : base(id) { } [ReferenceType] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")] public partial class SubResource : IEquatable>, IEquatable, - IComparable>, IComparable where TIdentifier : ResourceIdentifier + IComparable>, IComparable + where TIdentifier : ResourceIdentifier { /// /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - protected SubResource() { } + protected SubResource() + { + } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] public SubResource(string id) { - Id = ResourceIdentifier.Create(id) as TIdentifier; + Id = (TIdentifier)id; } /// @@ -71,18 +77,12 @@ public int CompareTo(SubResource other) /// public bool Equals(SubResource other) { - if (Id is null) - return false; - return Id.Equals(other?.Id); } /// public bool Equals(string other) { - if (Id is null) - return false; - return Id.Equals(other); } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs index 8881ecb1dd42..c0b2256fe7e6 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs @@ -8,13 +8,16 @@ namespace Azure.ResourceManager.Core /// /// A class representing the a writable sub resource of ResourceIdentifier. /// + [ReferenceType] public class WritableSubResource : WritableSubResource { /// /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - protected WritableSubResource() { } + protected WritableSubResource() + { + } /// Initializes a new instance of . /// ARM resource Id. @@ -28,20 +31,23 @@ public WritableSubResource(string id) : base(id) { } [ReferenceType] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Types differ by type argument only")] public partial class WritableSubResource : IEquatable>, IEquatable, - IComparable>, IComparable where TIdentifier : ResourceIdentifier + IComparable>, IComparable + where TIdentifier : ResourceIdentifier { /// /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - protected WritableSubResource() { } + protected WritableSubResource() + { + } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] public WritableSubResource(string id) { - Id = ResourceIdentifier.Create(id) as TIdentifier; + Id = (TIdentifier)id; } /// @@ -70,18 +76,12 @@ public int CompareTo(WritableSubResource other) /// public bool Equals(WritableSubResource other) { - if (Id is null) - return false; - return Id.Equals(other?.Id); } /// public bool Equals(string other) { - if (Id is null) - return false; - return Id.Equals(other); } } From 28ca370fc4e5749697f22996e146df3123dc5421 Mon Sep 17 00:00:00 2001 From: George Arama Date: Thu, 27 May 2021 10:58:50 -0700 Subject: [PATCH 5/5] PR comments and phonecall around silent errors and casting --- .../src/Resources/SubResource.Serialization.cs | 4 ++-- .../src/Resources/SubResource.cs | 10 +++++----- .../src/Resources/WritableSubResource.Serialization.cs | 4 ++-- .../src/Resources/WritableSubResource.cs | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs index e3c703fa9eb1..962adbabbb4a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.Serialization.cs @@ -39,7 +39,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) /// Deserialized SubResource object. internal static SubResource DeserializeSubResource(JsonElement element) { - Optional id = default; + string id = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) @@ -48,7 +48,7 @@ internal static SubResource DeserializeSubResource(JsonElement elem continue; } } - return new SubResource(id.Value); + return new SubResource(id); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs index 2ee2649e8c5d..1a68edf72652 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/SubResource.cs @@ -15,14 +15,14 @@ public class SubResource : SubResource /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - protected SubResource() + public SubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - public SubResource(string id) : base(id) { } + protected internal SubResource(string id) : base(id) { } } /// @@ -38,16 +38,16 @@ public partial class SubResource : IEquatable for mocking. /// [InitializationConstructor] - protected SubResource() + public SubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - public SubResource(string id) + protected internal SubResource(string id) { - Id = (TIdentifier)id; + Id = (TIdentifier)id; } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs index bd26e9e0dcde..5978b65b4b43 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.Serialization.cs @@ -34,7 +34,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) /// Deserialized WritableSubResource object. internal static WritableSubResource DeserializeWritableSubResource(JsonElement element) { - Optional id = default; + string id = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) @@ -43,7 +43,7 @@ internal static WritableSubResource DeserializeWritableSubResource( continue; } } - return new WritableSubResource(id.Value); + return new WritableSubResource(id); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs index c0b2256fe7e6..ff38cd31f7cb 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/WritableSubResource.cs @@ -15,14 +15,14 @@ public class WritableSubResource : WritableSubResource /// Initializes an empty instance of for mocking. /// [InitializationConstructor] - protected WritableSubResource() + public WritableSubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - public WritableSubResource(string id) : base(id) { } + protected internal WritableSubResource(string id) : base(id) { } } /// @@ -38,16 +38,16 @@ public partial class WritableSubResource : IEquatable for mocking. /// [InitializationConstructor] - protected WritableSubResource() + public WritableSubResource() { } /// Initializes a new instance of . /// ARM resource Id. [SerializationConstructor] - public WritableSubResource(string id) + protected internal WritableSubResource(string id) { - Id = (TIdentifier)id; + Id = (TIdentifier)id; } ///