-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ResourceIdentifier
fixes and enhancements (#15656)
- Updated `ResourceIdentifier` to address minor bugs and enhance compliance with the URI RFC. - Introduced new public and extension methods to support the file abstraction migration and minimize changes required in subsequent PRs. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/15656)
- Loading branch information
Showing
6 changed files
with
466 additions
and
93 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/Bicep.IO.UnitTests/Abstraction/ResourceIdentifierExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using Bicep.IO.Abstraction; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.IO.UnitTests.Abstraction | ||
{ | ||
[TestClass] | ||
public class ResourceIdentifierExtensionsTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow("/a/b/c.txt", ".txt")] | ||
[DataRow("/a/b/c.tar.gz", ".gz")] | ||
[DataRow("/a/b/c", "")] | ||
[DataRow("/a/b/c.", "")] | ||
[DataRow("/a/b/c.d/e", "")] | ||
public void GetExtension_ValidPaths_ReturnsCorrectExtension(string path, string expectedExtension) | ||
{ | ||
// Arrange. | ||
var resourceIdentifier = new ResourceIdentifier("file", "", path); | ||
|
||
// Act. | ||
var extension = resourceIdentifier.GetExtension(); | ||
|
||
// Assert. | ||
extension.ToString().Should().Be(expectedExtension); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow("/a/b/c.txt", ".bak", "/a/b/c.bak")] | ||
[DataRow("/a/b/c.tar.gz", ".zip", "/a/b/c.tar.zip")] | ||
[DataRow("/a/b/c.tar.gz", "zip", "/a/b/c.tar.zip")] | ||
[DataRow("/a/b/c", ".txt", "/a/b/c.txt")] | ||
[DataRow("/a/b/c.", ".txt", "/a/b/c.txt")] | ||
[DataRow("/a/b/c.d/e", ".txt", "/a/b/c.d/e.txt")] | ||
public void WithExtension_ValidPaths_ReturnsPathWithNewExtension(string path, string newExtension, string expectedPath) | ||
{ | ||
// Arrange | ||
var resourceIdentifier = new ResourceIdentifier("file", "", path); | ||
|
||
// Act | ||
var newResourceIdentifier = resourceIdentifier.WithExtension(newExtension); | ||
|
||
// Assert | ||
newResourceIdentifier.Path.Should().Be(expectedPath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.