|
| 1 | +using System.IO.Compression; |
| 2 | +using System.Reflection.PortableExecutable; |
1 | 3 | using Workleap.DotNet.CodingStandards.Tests.Helpers;
|
2 | 4 | using Xunit.Abstractions;
|
3 | 5 |
|
@@ -142,6 +144,7 @@ public async Task ReportVulnerablePackage_Debug_ShouldReportWarning()
|
142 | 144 | Assert.False(data.HasError("NU1903"));
|
143 | 145 | Assert.True(data.HasWarning("NU1903"));
|
144 | 146 | }
|
| 147 | + |
145 | 148 | [Fact]
|
146 | 149 | public async Task ReportVulnerablePackage_DisabledWarningOnPackage()
|
147 | 150 | {
|
@@ -170,4 +173,80 @@ public async Task ReportVulnerablePackage_DisabledWarningOnPackage()
|
170 | 173 | Assert.False(data.HasError("NU1903"));
|
171 | 174 | Assert.False(data.HasWarning("NU1903"));
|
172 | 175 | }
|
| 176 | + |
| 177 | + [Fact] |
| 178 | + public async Task PdbShouldBeEmbedded_Dotnet_Build() |
| 179 | + { |
| 180 | + using var project = new ProjectBuilder(fixture, testOutputHelper); |
| 181 | + project.AddFile("test.csproj", $""" |
| 182 | + <Project Sdk="Microsoft.NET.Sdk"> |
| 183 | + <PropertyGroup> |
| 184 | + <TargetFramework>net8.0</TargetFramework> |
| 185 | + <ImplicitUsings>enable</ImplicitUsings> |
| 186 | + <Nullable>enable</Nullable> |
| 187 | + <ErrorLog>{ProjectBuilder.SarifFileName},version=2.1</ErrorLog> |
| 188 | + <RootNamespace>Foo</RootNamespace> |
| 189 | + </PropertyGroup> |
| 190 | + |
| 191 | + <ItemGroup> |
| 192 | + <PackageReference Include="Workleap.DotNet.CodingStandards" Version="*" /> |
| 193 | + </ItemGroup> |
| 194 | + </Project> |
| 195 | + """); |
| 196 | + |
| 197 | + project.AddFile("Sample.cs", """ |
| 198 | + namespace Foo; |
| 199 | + public static class Sample { } |
| 200 | + """); |
| 201 | + var data = await project.BuildAndGetOutput(["--configuration", "Release"]); |
| 202 | + |
| 203 | + var outputFiles = Directory.GetFiles(Path.Combine(project.RootFolder, "bin", "Release", "net8.0")); |
| 204 | + await AssertPdbIsEmbedded(outputFiles); |
| 205 | + } |
| 206 | + |
| 207 | + [Fact] |
| 208 | + public async Task PdbShouldBeEmbedded_Dotnet_Pack() |
| 209 | + { |
| 210 | + using var project = new ProjectBuilder(fixture, testOutputHelper); |
| 211 | + project.AddFile("test.csproj", $""" |
| 212 | + <Project Sdk="Microsoft.NET.Sdk"> |
| 213 | + <PropertyGroup> |
| 214 | + <TargetFramework>net8.0</TargetFramework> |
| 215 | + <ImplicitUsings>enable</ImplicitUsings> |
| 216 | + <Nullable>enable</Nullable> |
| 217 | + <ErrorLog>{ProjectBuilder.SarifFileName},version=2.1</ErrorLog> |
| 218 | + <RootNamespace>Foo</RootNamespace> |
| 219 | + </PropertyGroup> |
| 220 | + |
| 221 | + <ItemGroup> |
| 222 | + <PackageReference Include="Workleap.DotNet.CodingStandards" Version="*" /> |
| 223 | + </ItemGroup> |
| 224 | + </Project> |
| 225 | + """); |
| 226 | + |
| 227 | + project.AddFile("Sample.cs", """ |
| 228 | + namespace Foo; |
| 229 | + public static class Sample { } |
| 230 | + """); |
| 231 | + var data = await project.PackAndGetOutput(["--configuration", "Release"]); |
| 232 | + |
| 233 | + var extractedPath = Path.Combine(project.RootFolder, "extracted"); |
| 234 | + var files = Directory.GetFiles(Path.Combine(project.RootFolder, "bin", "Release")); |
| 235 | + Assert.Single(files); // Only the .nupkg should be generated |
| 236 | + var nupkg = files.Single(f => f.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase)); |
| 237 | + ZipFile.ExtractToDirectory(nupkg, extractedPath); |
| 238 | + |
| 239 | + var outputFiles = Directory.GetFiles(extractedPath, "*", SearchOption.AllDirectories); |
| 240 | + await AssertPdbIsEmbedded(outputFiles); |
| 241 | + } |
| 242 | + |
| 243 | + private static async Task AssertPdbIsEmbedded(string[] outputFiles) |
| 244 | + { |
| 245 | + Assert.DoesNotContain(outputFiles, f => f.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)); |
| 246 | + var dllPath = outputFiles.Single(f => f.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)); |
| 247 | + await using var stream = File.OpenRead(dllPath); |
| 248 | + var peReader = new PEReader(stream); |
| 249 | + var debug = peReader.ReadDebugDirectory(); |
| 250 | + Assert.Contains(debug, entry => entry.Type == DebugDirectoryEntryType.EmbeddedPortablePdb); |
| 251 | + } |
173 | 252 | }
|
0 commit comments