private void DiffBetween(Folder exist, Folder other)
{
if (exist.Path != other.Path) return;
foreach (var oldFile in exist.Files)
{
if (other.FindFile(oldFile.FullName) == null) _res.RemovedFiles.Add(oldFile.FullName);
}
foreach (var newFile in other.Files)
{
if (exist.FindFile(newFile.FullName) == null) _res.AddedFiles.Add(newFile.FullName);
}
foreach (var oldFolder in exist.SubFolders)
{
if (other[oldFolder.Path] == null)
{
_res.RemovedFolders.Add(oldFolder.Path);
RemoveSubFolders(oldFolder);
}
}
foreach (var newFolder in other.SubFolders)
{
if (exist[newFolder.Path] == null)
{
_res.AddedFolders.Add(newFolder.Path);
AddSubFolders(newFolder);
}
else
{
var oldFolder = exist[newFolder.Path];
DiffBetween(oldFolder, newFolder);
}
}
}
Assert.IsTrue(result.AddedFiles.Contains(_files[4]));
Assert.IsTrue(result.AddedFiles.Contains(_files[5]));
Assert.IsTrue(result.AddedFiles.Contains(_files[6]));
Assert.IsTrue(result.AddedFiles.Contains(_files[7]));
Assert.IsTrue(result.RemovedFiles.Contains(_files[0]));
Assert.IsTrue(result.RemovedFiles.Contains(_files[1]));
Assert.IsTrue(result.RemovedFiles.Contains(_files[2]));
Assert.IsTrue(result.RemovedFiles.Contains(_files[8]));
Assert.IsTrue(result.AddedFolders.Contains(_folders[4]));
Assert.IsTrue(result.AddedFolders.Contains(_folders[5]));
Assert.IsTrue(result.AddedFolders.Contains(_folders[6]));
Assert.IsTrue(result.RemovedFolders.Contains(_folders[0]));
Assert.IsTrue(result.RemovedFolders.Contains(_folders[1]));
Assert.IsTrue(result.RemovedFolders.Contains(_folders[2]));
private void DiffBetween(Folder exist, Folder other)
{
if (exist.Path != other.Path) return;
foreach (var oldFolder in exist.SubFolders)
{
if (other[oldFolder.Path] == null)
{
_res.RemovedFolders.Add(oldFolder.Path);
RemoveSubFolders(oldFolder);
}
}
foreach (var newFolder in other.SubFolders)
{
if (exist[newFolder.Path] == null)
{
_res.AddedFolders.Add(newFolder.Path);
AddSubFolders(newFolder);
}
else
{
var oldFolder = exist[newFolder.Path];
DiffBetween(oldFolder, newFolder);
}
}
}
private void AddSubFolders(Folder folder)
{
AddFiles(folder);
foreach (Folder item in folder.SubFolders)
{
_res.AddedFolders.Add(item.Path);
AddSubFolders(item);
}
}
private void RemoveSubFolders(Folder folder)
{
RemoveFiles(folder);
foreach (Folder item in folder.SubFolders)
{
_res.RemovedFolders.Add(item.Path);
RemoveSubFolders(item);
}
}
private void AddFiles(Folder folder)
{
foreach (var file in folder.Files)
{
_res.AddedFiles.Add(file.FullName);
}
}
private void RemoveFiles(Folder folder)
{
foreach (var file in folder.Files)
{
_res.RemovedFiles.Add(file.FullName);
}
}