Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 52 additions & 22 deletions tests/Fallout.Migrate.Specs/RewriteCsprojsStepSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public async Task Cryptography_package_pin_remove_pattern_does_not_act_greedy()
}

[Fact]
public void Recognizes_a_version_variable_prefixed_with_Nuke()
public async Task Recognizes_a_version_variable_prefixed_with_Nuke()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -312,16 +312,19 @@ public void Recognizes_a_version_variable_prefixed_with_Nuke()
</ItemGroup>
</Project>
""";
(tempDirectory / "build" / "_build.csproj").WriteAllText(input);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
Comment thread
dennisdoomen marked this conversation as resolved.
var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

result.Content.Should().NotContain("NukeVersion")
buildCsproj.Should().NotContain("NukeVersion")
.And.Contain("$(FalloutVersion)", Exactly.Twice())
.And.Contain("<FalloutVersion >11.0.0</FalloutVersion >");
}

[Fact]
public void Leaves_an_arbitrary_version_variable_alone_but_updates_the_version()
public async Task Leaves_an_arbitrary_version_variable_alone_but_updates_the_version()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -337,15 +340,19 @@ public void Leaves_an_arbitrary_version_variable_alone_but_updates_the_version()
</Project>
""";

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
(tempDirectory / "build" / "_build.csproj").WriteAllText(input);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

result.Content.Should().NotContain("FalloutVersion")
var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

buildCsproj.Should().NotContain("FalloutVersion")
.And.Contain("$(CiProjectVersion)", Exactly.Twice())
.And.Contain("<CiProjectVersion>11.0.0</CiProjectVersion>");
}

[Fact]
public void Leaves_an_unreferenced_arbitrary_variable_alone()
public async Task Leaves_an_unreferenced_arbitrary_variable_alone()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -359,15 +366,19 @@ public void Leaves_an_unreferenced_arbitrary_variable_alone()
</Project>
""";

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
(tempDirectory / "build" / "_build.csproj").WriteAllText(input);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

result.Content.Should().Contain("<UnreferencedVersion>10.3.49</UnreferencedVersion>")
var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

buildCsproj.Should().Contain("<UnreferencedVersion>10.3.49</UnreferencedVersion>")
.And.Contain("<CiProjectVersion>11.0.0</CiProjectVersion>")
.And.Contain("$(CiProjectVersion)", Exactly.Once());
}

[Fact]
public void Does_not_bump_variables_used_for_non_Fallout_packages()
public async Task Does_not_bump_variables_used_for_non_Fallout_packages()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -380,14 +391,18 @@ public void Does_not_bump_variables_used_for_non_Fallout_packages()
</Project>
""";

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
(tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

result.EditCount.Should().Be(0);
result.Content.Should().Be(input);
summary.EditCount.Should().Be(0);
buildCsproj.Should().Be(input);
}

[Fact]
public void Decouples_ambiguously_used_variables()
public async Task Decouples_ambiguously_used_variables()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -401,15 +416,20 @@ public void Decouples_ambiguously_used_variables()
</Project>
""";

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
result.Content.Should()
(tempDirectory / "build" / "_build.csproj").WriteAllText(input);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

buildCsproj.Should()
.Contain("<PkgVersion>10.1.0</PkgVersion>")
.And.Contain("<FalloutVersion>")
.And.Contain("$(FalloutVersion)", Exactly.Once());
}

[Fact]
public void Decouples_ambiguously_used_variables_even_when_no_property_group_found()
public async Task Decouples_ambiguously_used_variables_even_when_no_property_group_found()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -420,16 +440,21 @@ public void Decouples_ambiguously_used_variables_even_when_no_property_group_fou
</Project>
""";

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
result.Content.Should()
(tempDirectory / "build" / "_build.csproj").WriteAllText(input);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

buildCsproj.Should()
.Contain("<PropertyGroup>")
.And.Contain("<FalloutVersion>11.0.0</FalloutVersion>")
.And.Contain("$(FalloutVersion)", Exactly.Once())
.And.Contain("$(PkgVersion)");
}

[Fact]
public void Decouples_ambiguously_used_variables_when_a_property_group_but_no_variable_exists()
public async Task Decouples_ambiguously_used_variables_when_a_property_group_but_no_variable_exists()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
Expand All @@ -442,8 +467,13 @@ public void Decouples_ambiguously_used_variables_when_a_property_group_but_no_va
</Project>
""";

var result = RewriteCsprojsStep.Rewrite(input, TestFalloutVersion);
result.Content.Should()
(tempDirectory / "build" / "_build.csproj").WriteAllText(input);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();

buildCsproj.Should()
.Contain("<PropertyGroup>")
.And.Contain("<FalloutVersion>11.0.0</FalloutVersion>")
.And.Contain("$(FalloutVersion)", Exactly.Once())
Expand Down
Loading