Skip to content

Commit feac143

Browse files
committed
Add tests for Directory.Build.targets
1 parent b2fcc7d commit feac143

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

Sources/Kysect.DotnetProjectSystem.Tests/SolutionModification/DotnetSolutionModifierFactoryTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,23 @@ public void Create_SolutionWithDirectoryBuildTargets_ReturnTargetFileContent()
134134
.ToXmlString(_syntaxFormatter)
135135
.Should().Be(directoryBuildTargetContent);
136136
}
137+
138+
[Fact]
139+
public void Create_SolutionWithoutDirectoryBuildTargets_ReturnEmptyTargetFileContent()
140+
{
141+
string directoryBuildTargetContent = """
142+
<Project>
143+
</Project>
144+
""";
145+
146+
_solutionFileStructureBuilderFactory.Create("Solution")
147+
.Save(_currentPath);
148+
149+
DotnetSolutionModifier solutionModifier = _solutionModifierFactory.Create("Solution.sln");
150+
151+
solutionModifier
152+
.GetOrCreateDirectoryBuildTargetFile()
153+
.ToXmlString(_syntaxFormatter)
154+
.Should().Be(directoryBuildTargetContent);
155+
}
137156
}

Sources/Kysect.DotnetProjectSystem.Tests/SolutionModification/DotnetSolutionModifierTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Kysect.DotnetProjectSystem.FileStructureBuilding;
22
using Kysect.DotnetProjectSystem.Parsing;
3+
using Kysect.DotnetProjectSystem.Projects;
34
using Kysect.DotnetProjectSystem.SolutionModification;
45
using Kysect.DotnetProjectSystem.Tests.Asserts;
56
using Kysect.DotnetProjectSystem.Tools;
67
using Kysect.DotnetProjectSystem.Xml;
8+
using Microsoft.Language.Xml;
79
using System.IO.Abstractions.TestingHelpers;
810

911
namespace Kysect.DotnetProjectSystem.Tests.SolutionModification;
@@ -83,4 +85,31 @@ public void Save_AfterAddingValueToDirectoryBuildProps_FileSaved()
8385
.ShouldExists()
8486
.ShouldHaveContent(expectedContent);
8587
}
88+
89+
[Fact]
90+
public void Save_AfterModifyDirectoryBuildTargets_FileSaved()
91+
{
92+
var expectedContent = """
93+
<Project>
94+
<NewNode></NewNode>
95+
</Project>
96+
""";
97+
98+
_solutionFileStructureBuilderFactory.Create("Solution")
99+
.AddDirectoryBuildTargets(DirectoryBuildTargetFile.CreateEmpty())
100+
.Save(_currentPath);
101+
102+
DotnetSolutionModifier solutionModifier = _solutionModifierFactory.Create("Solution.sln");
103+
solutionModifier
104+
.GetOrCreateDirectoryBuildTargetFile()
105+
.UpdateDocument(d => d.ReplaceNode(
106+
d.Root.AsSyntaxElement.AsNode,
107+
d.Root.AsSyntaxElement.AddChild(ExtendedSyntaxFactory.XmlElement("NewNode")).AsNode));
108+
solutionModifier.Save();
109+
110+
_fileSystemAsserts
111+
.File(SolutionItemNameConstants.DirectoryBuildTargets)
112+
.ShouldExists()
113+
.ShouldHaveContent(expectedContent);
114+
}
86115
}

Sources/Kysect.DotnetProjectSystem/Xml/XmlElementSyntaxExtensions.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)