Skip to content

Commit

Permalink
File IO abstraction part 5 (#16238)
Browse files Browse the repository at this point in the history
Cherry-picking specific changes from my main file I/O migration branch
to keep the PRs more manageable. This PR focuses on addressing
`IFileHandle` functionality gaps to ensure it fully covers
`FileResolver` before its deprecation.

Additionally, it includes updates to align the `MSTest.TestFramework`
version with `MSTest.TestAdapter`, as the version mismatch was causing
test crashes when running through Visual Studio on my machine.
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/16238)
  • Loading branch information
shenglol authored Jan 29, 2025
1 parent 7141454 commit 1f5e087
Show file tree
Hide file tree
Showing 40 changed files with 594 additions and 133 deletions.
2 changes: 1 addition & 1 deletion Bicep.sln
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{C6CAFEE8
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bicep.Tools.Benchmark", "src\Bicep.Tools.Benchmark\Bicep.Tools.Benchmark.csproj", "{A4127F6F-A282-47F3-BAFE-6A154F994B4E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8F8DCFBC-A0DC-4E40-93C8-B4FB99FBD757}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Local", "Local", "{8F8DCFBC-A0DC-4E40-93C8-B4FB99FBD757}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bicep.Local.Extension", "src\Bicep.Local.Extension\Bicep.Local.Extension.csproj", "{E84C0368-0D02-4284-A3CB-110B14FA8314}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Bicep.Cli.IntegrationTests/RestoreCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure.Identity;
using Bicep.Cli.UnitTests.Assertions;
using Bicep.Core.Configuration;
using Bicep.Core.Extensions;
using Bicep.Core.Modules;
using Bicep.Core.Registry;
using Bicep.Core.Registry.Oci;
Expand Down Expand Up @@ -193,7 +194,7 @@ public async Task Restore_Artifacts_BackwardsAndForwardsCompatibility(string? me
";

var restoredFile = cacheRootDirectory.GetFile("restored.bicep");
restoredFile.WriteAllText(bicep);
restoredFile.Write(bicep);

var restoredFilePath = restoredFile.Uri.GetLocalFilePath();
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);
Expand Down Expand Up @@ -273,7 +274,7 @@ public async Task Restore_Artifacts_LayerMediaTypes(string[] layerMediaTypes, st
";

var restoredFile = cacheRootDirectory.GetFile("restored.bicep");
restoredFile.WriteAllText(bicep);
restoredFile.Write(bicep);

var restoredFilePath = restoredFile.Uri.GetLocalFilePath();

Expand Down
20 changes: 14 additions & 6 deletions src/Bicep.Cli.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
},
"MSTest.TestFramework": {
"type": "Direct",
"requested": "[3.6.4, )",
"resolved": "3.6.4",
"contentHash": "3nV+2CJluKmiJpCSqQfXu5idCq35+vqFywjScyauTIz0Zk7KJw7Qpzv8gtwow0To7pxIlIvwkq9rbMB+V6eOow=="
"requested": "[3.7.3, )",
"resolved": "3.7.3",
"contentHash": "Eg4F4zOsAFKlSiLI3tOJfg6BGXeppLhgdupAfVlnpZBXa3rNqxINIeZDJ5/KpoW5BRZyUSZW76Q8yNNk0GqCEQ==",
"dependencies": {
"MSTest.Analyzers": "3.7.3"
}
},
"Nerdbank.GitVersioning": {
"type": "Direct",
Expand Down Expand Up @@ -815,6 +818,11 @@
"Castle.Core": "5.1.1"
}
},
"MSTest.Analyzers": {
"type": "Transitive",
"resolved": "3.7.3",
"contentHash": "5KcyyxIP0UBRKBs135+S3JQJALc1PmZMzhpR86JIXQ2Dnd/lDiOGNDD8R23X015mWi1K95KQWsGWw+3e7DUrgg=="
},
"Nerdbank.Streams": {
"type": "Transitive",
"resolved": "2.11.74",
Expand Down Expand Up @@ -1648,7 +1656,7 @@
"dependencies": {
"FluentAssertions": "[7.0.0, )",
"MSTest.TestAdapter": "[3.7.3, )",
"MSTest.TestFramework": "[3.6.4, )",
"MSTest.TestFramework": "[3.7.3, )",
"Microsoft.NET.Test.Sdk": "[17.12.0, )",
"bicep": "[1.0.0, )"
}
Expand All @@ -1660,7 +1668,7 @@
"Bicep.Core.UnitTests": "[1.0.0, )",
"FluentAssertions": "[7.0.0, )",
"MSTest.TestAdapter": "[3.7.3, )",
"MSTest.TestFramework": "[3.6.4, )",
"MSTest.TestFramework": "[3.7.3, )",
"Microsoft.NET.Test.Sdk": "[17.12.0, )"
}
},
Expand All @@ -1673,7 +1681,7 @@
"FluentAssertions": "[7.0.0, )",
"JsonDiffPatch.Net": "[2.3.0, )",
"MSTest.TestAdapter": "[3.7.3, )",
"MSTest.TestFramework": "[3.6.4, )",
"MSTest.TestFramework": "[3.7.3, )",
"Microsoft.NET.Test.Sdk": "[17.12.0, )",
"Moq": "[4.20.72, )",
"Newtonsoft.Json.Schema": "[4.0.1, )",
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Cli.UnitTests/Bicep.Cli.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 11 additions & 3 deletions src/Bicep.Cli.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
},
"MSTest.TestFramework": {
"type": "Direct",
"requested": "[3.6.4, )",
"resolved": "3.6.4",
"contentHash": "3nV+2CJluKmiJpCSqQfXu5idCq35+vqFywjScyauTIz0Zk7KJw7Qpzv8gtwow0To7pxIlIvwkq9rbMB+V6eOow=="
"requested": "[3.7.3, )",
"resolved": "3.7.3",
"contentHash": "Eg4F4zOsAFKlSiLI3tOJfg6BGXeppLhgdupAfVlnpZBXa3rNqxINIeZDJ5/KpoW5BRZyUSZW76Q8yNNk0GqCEQ==",
"dependencies": {
"MSTest.Analyzers": "3.7.3"
}
},
"Nerdbank.GitVersioning": {
"type": "Direct",
Expand Down Expand Up @@ -779,6 +782,11 @@
"System.Web.Services.Description": "4.10.0"
}
},
"MSTest.Analyzers": {
"type": "Transitive",
"resolved": "3.7.3",
"contentHash": "5KcyyxIP0UBRKBs135+S3JQJALc1PmZMzhpR86JIXQ2Dnd/lDiOGNDD8R23X015mWi1K95KQWsGWw+3e7DUrgg=="
},
"Nerdbank.Streams": {
"type": "Transitive",
"resolved": "2.11.74",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
18 changes: 13 additions & 5 deletions src/Bicep.Core.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
},
"MSTest.TestFramework": {
"type": "Direct",
"requested": "[3.6.4, )",
"resolved": "3.6.4",
"contentHash": "3nV+2CJluKmiJpCSqQfXu5idCq35+vqFywjScyauTIz0Zk7KJw7Qpzv8gtwow0To7pxIlIvwkq9rbMB+V6eOow=="
"requested": "[3.7.3, )",
"resolved": "3.7.3",
"contentHash": "Eg4F4zOsAFKlSiLI3tOJfg6BGXeppLhgdupAfVlnpZBXa3rNqxINIeZDJ5/KpoW5BRZyUSZW76Q8yNNk0GqCEQ==",
"dependencies": {
"MSTest.Analyzers": "3.7.3"
}
},
"Nerdbank.GitVersioning": {
"type": "Direct",
Expand Down Expand Up @@ -785,6 +788,11 @@
"Castle.Core": "5.1.1"
}
},
"MSTest.Analyzers": {
"type": "Transitive",
"resolved": "3.7.3",
"contentHash": "5KcyyxIP0UBRKBs135+S3JQJALc1PmZMzhpR86JIXQ2Dnd/lDiOGNDD8R23X015mWi1K95KQWsGWw+3e7DUrgg=="
},
"Nerdbank.Streams": {
"type": "Transitive",
"resolved": "2.10.69",
Expand Down Expand Up @@ -1563,7 +1571,7 @@
"Bicep.Core.UnitTests": "[1.0.0, )",
"FluentAssertions": "[7.0.0, )",
"MSTest.TestAdapter": "[3.7.3, )",
"MSTest.TestFramework": "[3.6.4, )",
"MSTest.TestFramework": "[3.7.3, )",
"Microsoft.NET.Test.Sdk": "[17.12.0, )"
}
},
Expand All @@ -1576,7 +1584,7 @@
"FluentAssertions": "[7.0.0, )",
"JsonDiffPatch.Net": "[2.3.0, )",
"MSTest.TestAdapter": "[3.7.3, )",
"MSTest.TestFramework": "[3.6.4, )",
"MSTest.TestFramework": "[3.7.3, )",
"Microsoft.NET.Test.Sdk": "[17.12.0, )",
"Moq": "[4.20.72, )",
"Newtonsoft.Json.Schema": "[4.0.1, )",
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.Samples/Bicep.Core.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
16 changes: 12 additions & 4 deletions src/Bicep.Core.Samples/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
},
"MSTest.TestFramework": {
"type": "Direct",
"requested": "[3.6.4, )",
"resolved": "3.6.4",
"contentHash": "3nV+2CJluKmiJpCSqQfXu5idCq35+vqFywjScyauTIz0Zk7KJw7Qpzv8gtwow0To7pxIlIvwkq9rbMB+V6eOow=="
"requested": "[3.7.3, )",
"resolved": "3.7.3",
"contentHash": "Eg4F4zOsAFKlSiLI3tOJfg6BGXeppLhgdupAfVlnpZBXa3rNqxINIeZDJ5/KpoW5BRZyUSZW76Q8yNNk0GqCEQ==",
"dependencies": {
"MSTest.Analyzers": "3.7.3"
}
},
"Nerdbank.GitVersioning": {
"type": "Direct",
Expand Down Expand Up @@ -785,6 +788,11 @@
"Castle.Core": "5.1.1"
}
},
"MSTest.Analyzers": {
"type": "Transitive",
"resolved": "3.7.3",
"contentHash": "5KcyyxIP0UBRKBs135+S3JQJALc1PmZMzhpR86JIXQ2Dnd/lDiOGNDD8R23X015mWi1K95KQWsGWw+3e7DUrgg=="
},
"Nerdbank.Streams": {
"type": "Transitive",
"resolved": "2.10.69",
Expand Down Expand Up @@ -1565,7 +1573,7 @@
"FluentAssertions": "[7.0.0, )",
"JsonDiffPatch.Net": "[2.3.0, )",
"MSTest.TestAdapter": "[3.7.3, )",
"MSTest.TestFramework": "[3.6.4, )",
"MSTest.TestFramework": "[3.7.3, )",
"Microsoft.NET.Test.Sdk": "[17.12.0, )",
"Moq": "[4.20.72, )",
"Newtonsoft.Json.Schema": "[4.0.1, )",
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.UnitTests/Bicep.Core.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading

0 comments on commit 1f5e087

Please sign in to comment.