| 1 | using RoslynMcp.ServiceLayer; |
| 2 | |
| 3 | namespace RoslynMcp.Tests; |
| 4 | |
| 5 | public sealed class DependentUponCsprojTests |
| 6 | { |
| 7 | [Fact] |
| 8 | public void TryRemoveRedundantSdkCompileInclude_removes_matching_include() |
| 9 | { |
| 10 | var dir = Path.Combine(Path.GetTempPath(), "roslyn-mcp-sdk-compile-" + Guid.NewGuid().ToString("N")); |
| 11 | Directory.CreateDirectory(dir); |
| 12 | var path = Path.Combine(dir, "Test.csproj"); |
| 13 | File.WriteAllText(path, """ |
| 14 | <Project Sdk="Microsoft.NET.Sdk"> |
| 15 | <ItemGroup> |
| 16 | <Compile Include="ViewModels\Foo.cs" /> |
| 17 | </ItemGroup> |
| 18 | </Project> |
| 19 | """); |
| 20 | |
| 21 | var msg = DependentUponCsproj.TryRemoveRedundantSdkCompileInclude(path, "ViewModels/Foo.cs"); |
| 22 | |
| 23 | Assert.Contains("removed", msg, StringComparison.Ordinal); |
| 24 | var xml = File.ReadAllText(path); |
| 25 | Assert.DoesNotContain("Include=\"ViewModels", xml, StringComparison.Ordinal); |
| 26 | } |
| 27 | |
| 28 | [Fact] |
| 29 | public void TryRemoveRedundantSdkCompileInclude_skips_when_EnableDefaultCompileItems_false() |
| 30 | { |
| 31 | var dir = Path.Combine(Path.GetTempPath(), "roslyn-mcp-sdk-compile-" + Guid.NewGuid().ToString("N")); |
| 32 | Directory.CreateDirectory(dir); |
| 33 | var path = Path.Combine(dir, "Test.csproj"); |
| 34 | File.WriteAllText(path, """ |
| 35 | <Project Sdk="Microsoft.NET.Sdk"> |
| 36 | <PropertyGroup> |
| 37 | <EnableDefaultCompileItems>false</EnableDefaultCompileItems> |
| 38 | </PropertyGroup> |
| 39 | <ItemGroup> |
| 40 | <Compile Include="ViewModels\Foo.cs" /> |
| 41 | </ItemGroup> |
| 42 | </Project> |
| 43 | """); |
| 44 | |
| 45 | var msg = DependentUponCsproj.TryRemoveRedundantSdkCompileInclude(path, "ViewModels\\Foo.cs"); |
| 46 | |
| 47 | Assert.Contains("EnableDefaultCompileItems=false", msg, StringComparison.Ordinal); |
| 48 | Assert.Contains("Compile Include", File.ReadAllText(path), StringComparison.Ordinal); |
| 49 | } |
| 50 | } |
| 51 | |