Skip to content

Commit

Permalink
Redo (#39060)
Browse files Browse the repository at this point in the history
  • Loading branch information
abatishchev authored and drielenr committed Oct 24, 2023
1 parent 934aa15 commit f8f907e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Azure.Core.ResourceType>
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/api/Azure.Core.net472.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Azure.Core.ResourceType>
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Azure.Core.ResourceType>
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Azure.Core.ResourceType>
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Azure.Core.ResourceType>
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Azure.Core.ResourceType>
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/src/ResourceIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ public static ResourceIdentifier Parse(string input)
/// If the method returns false, result will be null.
/// </param>
/// <returns> True if the parse operation was successful; otherwise, false. </returns>
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;
Expand Down
32 changes: 19 additions & 13 deletions sdk/core/Azure.Core/tests/ResourceIdentifierTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArgumentNullException>(() => { _ = new ResourceIdentifier(invalidID).Name; });
Assert.Throws<ArgumentNullException>(() => ResourceIdentifier.Parse(invalidID));
Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result));
}

[TestCase("")]
public void EmptyInput(string invalidID)
{
Assert.Throws<ArgumentException>(() => { _ = new ResourceIdentifier(invalidID).Name; });
Assert.Throws<ArgumentException>(() => 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<ArgumentException>(() => { _ = new ResourceIdentifier(invalidID).Name; });
Assert.Throws<ArgumentException>(() => ResourceIdentifier.Parse(invalidID));
Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result));
}
else
{
Assert.Throws<FormatException>(() => { _ = new ResourceIdentifier(invalidID).Name; });
Assert.Throws<FormatException>(() => ResourceIdentifier.Parse(invalidID));
Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result));
}
Assert.Throws<FormatException>(() => { _ = new ResourceIdentifier(invalidID).Name; });
Assert.Throws<FormatException>(() => ResourceIdentifier.Parse(invalidID));
Assert.IsFalse(ResourceIdentifier.TryParse(invalidID, out var result));
}

[TestCase(TrackedResourceId)]
Expand Down

0 comments on commit f8f907e

Please sign in to comment.