Skip to content

Commit

Permalink
Another case of duplicate files fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-visual-studio committed Oct 22, 2023
1 parent d533d0f commit 6d72a24
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
14 changes: 7 additions & 7 deletions DPackRx.Tests/Features/FileBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "ShowFiles", null)).Returns(showFiles).Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "IgnoreFolders", null)).Returns(ignoreFolders).Verifiable();

_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code, true)).Returns(true).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.None, true)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.ImageFile, true)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code)).Returns(true).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.None)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.ImageFile)).Returns(false).Verifiable();

viewModel.OnInitialize(null);

Expand All @@ -170,15 +170,15 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "IgnoreFolders", null), Times.Once);
if (allFiles)
{
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code, true), Times.Never);
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.None, true), Times.Never);
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code), Times.Never);
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.None), Times.Never);
}
else
{
if (expectedCodeFileCount > 0)
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code, true), Times.AtLeast(expectedCodeFileCount));
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(FileSubType.Code), Times.AtLeast(expectedCodeFileCount));
if (expectedNoneCodeFileCount > 0)
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsNotIn(FileSubType.Code), true), Times.AtLeast(expectedNoneCodeFileCount));
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsNotIn(FileSubType.Code)), Times.AtLeast(expectedNoneCodeFileCount));
}
_searchMatchServiceMock.Verify(s => s.MatchItems(search, It.IsAny<IEnumerable<IMatchItem>>()), Times.Once);
}
Expand Down
6 changes: 3 additions & 3 deletions DPackRx.Tests/Services/SearchMatchServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public int CompareTo(object obj)
public void Setup()
{
_fileTypeResolverMock = new Mock<IFileTypeResolver>();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(It.IsAny<FileSubType>(), true)).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code, true)).Returns(true).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(It.IsAny<FileSubType>())).Returns(false).Verifiable();
_fileTypeResolverMock.Setup(r => r.IsCodeSubType(FileSubType.Code)).Returns(true).Verifiable();

_wildcardMatchMock = new Mock<IWildcardMatch>();
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public void MatchItems(string filter, int codeRank, int nonCodeRank, string erro
Assert.That(codeItem.Rank, Is.EqualTo(codeRank), $"Code item: {error}");
Assert.That(nonCodeItem.Rank, Is.EqualTo(nonCodeRank), $"Non-code item: {error}");

_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsAny<FileSubType>(), true), Times.Exactly(items.Count));
_fileTypeResolverMock.Verify(r => r.IsCodeSubType(It.IsAny<FileSubType>()), Times.Exactly(items.Count));
}

[TestCase("test", false)]
Expand Down
5 changes: 3 additions & 2 deletions DPackRx/CodeModel/FileTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public FileSubType GetExtensionSubType(object projectItem, LanguageSettings lang
/// <param name="itemSubType">File sub-type.</param>
/// <param name="miscFilesAsCode">Treat miscellaneous files as code ones.</param>
/// <returns>File sub-type status.</returns>
public bool IsCodeSubType(FileSubType itemSubType, bool miscFilesAsCode = true)
public bool IsCodeSubType(FileSubType itemSubType)
{
switch (itemSubType)
{
Expand All @@ -173,8 +173,9 @@ public bool IsCodeSubType(FileSubType itemSubType, bool miscFilesAsCode = true)
return true;
case FileSubType.JScript:
case FileSubType.XmlFile:
return true;
case FileSubType.ConfigFile:
return miscFilesAsCode;
return false;
default:
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions DPackRx/CodeModel/IFileTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public interface IFileTypeResolver
/// Checks whether a given file sub-type is a code one.
/// </summary>
/// <param name="itemSubType">File sub-type.</param>
/// <param name="miscFilesAsCode">Treat miscellaneous files as code ones.</param>
/// <returns>File sub-type status.</returns>
bool IsCodeSubType(FileSubType itemSubType, bool miscFilesAsCode = true);
bool IsCodeSubType(FileSubType itemSubType);

/// <summary>
/// Checks whether a given file sub-type is a web one with both design and code views.
Expand Down
10 changes: 10 additions & 0 deletions DPackRx/CodeModel/ProjectProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ private void ProcessProjectItems(List<FileModel> model, ProcessorFlags flags, Co
add = false;
}

// Check for nested duplicate files
if (add)
{
if ((parentItem != null) &&
(parentItem.FileCount > 0) &&
(projectItem.FileCount > 0) &&
parentItem.FileNames[0].Equals(projectItem.FileNames[0], StringComparison.OrdinalIgnoreCase))
add = false;
}

// Used to collect skipped files here as well... something to keep an eye out out for
if (add)
{
Expand Down

0 comments on commit 6d72a24

Please sign in to comment.