Skip to content

Commit

Permalink
Throw error when unknown file is found in csproj (legacy style). (#26)
Browse files Browse the repository at this point in the history
Added unit test and changed other unittests that are impacted by this change.
  • Loading branch information
MichielOda authored Apr 4, 2024
1 parent c45aac1 commit 27f91f0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Parsers.Common/Parsers.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
<ItemGroup>
<InternalsVisibleTo Include="Skyline.DataMiner.CICD.Parsers.Protocol" />
<InternalsVisibleTo Include="Assemblers.AutomationTests" />
<InternalsVisibleTo Include="Assemblers.ProtocolTests" />
<InternalsVisibleTo Include="Assemblers.ProtocolTests" />
<InternalsVisibleTo Include="Parsers.CommonTests" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion Parsers.Common/VisualStudio/Projects/LegacyStyleParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
Expand Down Expand Up @@ -194,7 +195,7 @@ public IEnumerable<ProjectFile> GetCompileFiles()

if (!FileSystem.File.Exists(absolutePath))
{
continue;
throw new FileNotFoundException($"File '{relativePath}' was not found. Please add the file or remove it from the project.");
}

yield return new ProjectFile(relativePath, FileSystem.File.ReadAllText(FileSystem.Path.GetFullPath(absolutePath), Encoding.UTF8));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Parsers.CommonTests.VisualStudio.Projects
{
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

using FluentAssertions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Skyline.DataMiner.CICD.Parsers.Common.VisualStudio.Projects;

[TestClass]
public class LegacyStyleParserTests
{
[TestMethod]
public void GetCompileFilesTest()
{
// Arrange
string path = Path.GetFullPath(@".\VisualStudio\TestFiles\ProjectsForTesting\Files\Files_UnknownFile.csproj");
string projectDir = Path.GetDirectoryName(path);
var xmlContent = File.ReadAllText(path, Encoding.UTF8);
var document = XDocument.Parse(xmlContent);
LegacyStyleParser legacyStyleParser = new LegacyStyleParser(document, projectDir);

// Act
Action action = () => _ = legacyStyleParser.GetCompileFiles().ToList();

// Assert
action.Should().Throw<FileNotFoundException>();
}
}
}
1 change: 0 additions & 1 deletion Parsers.CommonTests/VisualStudio/Projects/ProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void Load_TargetFrameWorkMoniker(string fileName, string expectedResult)
[TestMethod]
[DataRow("Files_Valid.csproj", 2)]
[DataRow("Files_NoFiles.csproj", 0)]
[DataRow("Files_UnknownFile.csproj", 0)]
[DataRow("SharedProject.projitems", 2)]
[DataRow("SharedProject.shproj", 2)]
[DataRow("Files_ValidSharedProject.csproj", 4)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<Content Include=".editorconfig" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SpecialChar_1.cs" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 27f91f0

Please sign in to comment.