From f8f907ea169327e7db5ffad36e33c6fb708c999a Mon Sep 17 00:00:00 2001 From: Alexander Batishchev Date: Wed, 18 Oct 2023 08:00:32 -0700 Subject: [PATCH] Redo (#39060) --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net472.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net5.0.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 2 +- .../api/Azure.Core.netcoreapp2.1.cs | 2 +- .../api/Azure.Core.netstandard2.0.cs | 2 +- sdk/core/Azure.Core/src/ResourceIdentifier.cs | 4 +-- .../tests/ResourceIdentifierTests.cs | 32 +++++++++++-------- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 3f774979daad9..49995b0e56e38 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -651,7 +651,7 @@ public ResourceIdentifier(string resourceId) { } public static bool operator <=(Azure.Core.ResourceIdentifier left, Azure.Core.ResourceIdentifier right) { throw null; } public static Azure.Core.ResourceIdentifier Parse(string input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(string input, out Azure.Core.ResourceIdentifier? result) { throw null; } + public static bool TryParse(string? input, out Azure.Core.ResourceIdentifier? result) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceType : System.IEquatable diff --git a/sdk/core/Azure.Core/api/Azure.Core.net472.cs b/sdk/core/Azure.Core/api/Azure.Core.net472.cs index 3f774979daad9..49995b0e56e38 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net472.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net472.cs @@ -651,7 +651,7 @@ public ResourceIdentifier(string resourceId) { } public static bool operator <=(Azure.Core.ResourceIdentifier left, Azure.Core.ResourceIdentifier right) { throw null; } public static Azure.Core.ResourceIdentifier Parse(string input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(string input, out Azure.Core.ResourceIdentifier? result) { throw null; } + public static bool TryParse(string? input, out Azure.Core.ResourceIdentifier? result) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceType : System.IEquatable diff --git a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs index a1bbd8de4d835..6d7fede912ffc 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs @@ -654,7 +654,7 @@ public ResourceIdentifier(string resourceId) { } public static bool operator <=(Azure.Core.ResourceIdentifier left, Azure.Core.ResourceIdentifier right) { throw null; } public static Azure.Core.ResourceIdentifier Parse(string input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(string input, out Azure.Core.ResourceIdentifier? result) { throw null; } + public static bool TryParse(string? input, out Azure.Core.ResourceIdentifier? result) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceType : System.IEquatable diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index dec24e4181499..16d3e7cb99ce2 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -654,7 +654,7 @@ public ResourceIdentifier(string resourceId) { } public static bool operator <=(Azure.Core.ResourceIdentifier left, Azure.Core.ResourceIdentifier right) { throw null; } public static Azure.Core.ResourceIdentifier Parse(string input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(string input, out Azure.Core.ResourceIdentifier? result) { throw null; } + public static bool TryParse(string? input, out Azure.Core.ResourceIdentifier? result) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceType : System.IEquatable diff --git a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs index 3f774979daad9..49995b0e56e38 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs @@ -651,7 +651,7 @@ public ResourceIdentifier(string resourceId) { } public static bool operator <=(Azure.Core.ResourceIdentifier left, Azure.Core.ResourceIdentifier right) { throw null; } public static Azure.Core.ResourceIdentifier Parse(string input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(string input, out Azure.Core.ResourceIdentifier? result) { throw null; } + public static bool TryParse(string? input, out Azure.Core.ResourceIdentifier? result) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceType : System.IEquatable diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 3f774979daad9..49995b0e56e38 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -651,7 +651,7 @@ public ResourceIdentifier(string resourceId) { } public static bool operator <=(Azure.Core.ResourceIdentifier left, Azure.Core.ResourceIdentifier right) { throw null; } public static Azure.Core.ResourceIdentifier Parse(string input) { throw null; } public override string ToString() { throw null; } - public static bool TryParse(string input, out Azure.Core.ResourceIdentifier? result) { throw null; } + public static bool TryParse(string? input, out Azure.Core.ResourceIdentifier? result) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceType : System.IEquatable diff --git a/sdk/core/Azure.Core/src/ResourceIdentifier.cs b/sdk/core/Azure.Core/src/ResourceIdentifier.cs index 03e1694dab93f..b83e164ed64ad 100644 --- a/sdk/core/Azure.Core/src/ResourceIdentifier.cs +++ b/sdk/core/Azure.Core/src/ResourceIdentifier.cs @@ -526,13 +526,13 @@ public static ResourceIdentifier Parse(string input) /// If the method returns false, result will be null. /// /// True if the parse operation was successful; otherwise, false. - public static bool TryParse(string input, out ResourceIdentifier? result) + public static bool TryParse(string? input, out ResourceIdentifier? result) { result = null; if (string.IsNullOrEmpty(input)) return false; - result = new ResourceIdentifier(input); + result = new ResourceIdentifier(input!); var error = result.Parse(); if (error is null) return true; diff --git a/sdk/core/Azure.Core/tests/ResourceIdentifierTests.cs b/sdk/core/Azure.Core/tests/ResourceIdentifierTests.cs index d9733037eae6e..4c47f0f1c2d43 100644 --- a/sdk/core/Azure.Core/tests/ResourceIdentifierTests.cs +++ b/sdk/core/Azure.Core/tests/ResourceIdentifierTests.cs @@ -816,27 +816,33 @@ public void InvalidTenantID(string id) Assert.IsFalse(ResourceIdentifier.TryParse(id, out var result)); } + [TestCase(null)] + public void NullInput(string invalidID) + { + Assert.Throws(() => { _ = new ResourceIdentifier(invalidID).Name; }); + Assert.Throws(() => ResourceIdentifier.Parse(invalidID)); + Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result)); + } + [TestCase("")] + public void EmptyInput(string invalidID) + { + Assert.Throws(() => { _ = new ResourceIdentifier(invalidID).Name; }); + Assert.Throws(() => ResourceIdentifier.Parse(invalidID)); + Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result)); + } + [TestCase(" ")] [TestCase("asdfghj")] [TestCase("123456")] [TestCase("!@#$%^&*/")] [TestCase("/subscriptions/")] [TestCase("/0c2f6471-1bf0-4dda-aec3-cb9272f09575/myRg/")] - public void InvalidRPIds(string invalidID) + public void InvalidInput(string invalidID) { - if (invalidID == String.Empty) - { - Assert.Throws(() => { _ = new ResourceIdentifier(invalidID).Name; }); - Assert.Throws(() => ResourceIdentifier.Parse(invalidID)); - Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result)); - } - else - { - Assert.Throws(() => { _ = new ResourceIdentifier(invalidID).Name; }); - Assert.Throws(() => ResourceIdentifier.Parse(invalidID)); - Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result)); - } + Assert.Throws(() => { _ = new ResourceIdentifier(invalidID).Name; }); + Assert.Throws(() => ResourceIdentifier.Parse(invalidID)); + Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result)); } [TestCase(TrackedResourceId)]