Skip to content

Commit

Permalink
fix: remove duplicate projects from output (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejgawel authored Jan 2, 2023
1 parent b581708 commit 49b0eb9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public async Task Execute(IEnumerable<IProjectInfo> projects,
var formatterDictionary = formatters
.ToDictionary(t => t, FindFormatter);

var allProjects = projects.ToList();
var allProjects = projects
.GroupBy(project => project.FilePath)
.Select(group => group.First())
.ToList();

foreach (var (type, formatter) in formatterDictionary)
{
Expand Down
29 changes: 29 additions & 0 deletions test/dotnet-affected.Tests/Formatters/FormatterExecutorTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DotnetAffected.Testing.Utils;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -36,5 +37,33 @@ await executor.Execute(projects, new[]

Assert.Contains(msBuildProject.FullPath, outputContents);
}

[Fact]
public async Task Should_write_deduplicated_projects()
{
// Arrange
const string formatterType = "text";
const string projectName = "InventoryManagement";
const string outputFileName = "affected";
var msBuildProject = this.Repository.CreateCsProject(projectName);
var executor = this.ServiceProvider.GetRequiredService<IOutputFormatterExecutor>();
var projects = new[]
{
new ProjectInfo("DuplicatedTestProject", msBuildProject.FullPath),
new ProjectInfo("DuplicatedTestProject", msBuildProject.FullPath),
};

// Act
await executor.Execute(projects, new[]
{
formatterType
}, Repository.Path, outputFileName, false, true);

// Assert
var outputPath = Path.Combine(Repository.Path, $"{outputFileName}.txt");
var outputContents = await File.ReadAllLinesAsync(outputPath);
Assert.Single(outputContents);
Assert.Equal(msBuildProject.FullPath, outputContents.First());
}
}
}

0 comments on commit 49b0eb9

Please sign in to comment.