Skip to content

Commit 3c4f358

Browse files
committed
test: Add tests for PropertyGroup Condition attribute in Target elements
Confirms that Condition attributes are correctly emitted on PropertyGroup elements inside Target elements. No code changes needed - functionality already working correctly.
1 parent 7a3d1b9 commit 3c4f358

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using JD.MSBuild.Fluent.Fluent;
2+
using JD.MSBuild.Fluent.Render;
3+
using Xunit;
4+
using Xunit.Abstractions;
5+
6+
namespace JD.MSBuild.Fluent.Tests;
7+
8+
public class PropertyGroupInTargetTests
9+
{
10+
private readonly ITestOutputHelper _output;
11+
12+
public PropertyGroupInTargetTests(ITestOutputHelper output)
13+
{
14+
_output = output;
15+
}
16+
17+
[Fact]
18+
public void PropertyGroup_WithCondition_InsideTarget_EmitsConditionAttribute()
19+
{
20+
// Arrange
21+
var project = Package.Define("TestPackage")
22+
.Targets(t =>
23+
{
24+
t.Target("TestTarget", target =>
25+
{
26+
target.PropertyGroup("'$(MyProp)' == ''", group =>
27+
{
28+
group.Property("MyProp", "DefaultValue");
29+
});
30+
});
31+
})
32+
.Build();
33+
34+
// Act
35+
var renderer = new MsBuildXmlRenderer();
36+
var xml = renderer.RenderToString(project.Targets);
37+
_output.WriteLine("Generated XML:");
38+
_output.WriteLine(xml);
39+
40+
// Assert
41+
Assert.Contains("<PropertyGroup Condition=\"'$(MyProp)' == ''\">", xml);
42+
Assert.Contains("<MyProp>DefaultValue</MyProp>", xml);
43+
}
44+
45+
[Fact]
46+
public void PropertyGroup_WithoutCondition_InsideTarget_EmitsWithoutConditionAttribute()
47+
{
48+
// Arrange
49+
var project = Package.Define("TestPackage")
50+
.Targets(t =>
51+
{
52+
t.Target("TestTarget", target =>
53+
{
54+
target.PropertyGroup(null, group =>
55+
{
56+
group.Property("MyProp", "Value");
57+
});
58+
});
59+
})
60+
.Build();
61+
62+
// Act
63+
var renderer = new MsBuildXmlRenderer();
64+
var xml = renderer.RenderToString(project.Targets);
65+
_output.WriteLine("Generated XML:");
66+
_output.WriteLine(xml);
67+
68+
// Assert
69+
Assert.Contains("<PropertyGroup>", xml);
70+
Assert.DoesNotContain("<PropertyGroup Condition=", xml);
71+
Assert.Contains("<MyProp>Value</MyProp>", xml);
72+
}
73+
}

0 commit comments

Comments
 (0)