Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CodeLineCounter.Tests/CsvExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ public void ExportToCsv_NullData_ThrowsNullReferenceException()
Assert.Throws<NullReferenceException>(() => CsvExporter.ExportToCsv(filePath, namespaceMetrics, projectTotals, totalLines, duplicationCodes, additionalInfo));
}

[Fact]
public void ExportCodeDuplicationsToCsv_ShouldCallSerializeWithCorrectParameters()
{
// Arrange
var filePath = "test4.csv";
var duplications = new List<DuplicationCode>
{
new DuplicationCode { CodeHash = "hash1", FilePath = "file1.cs", MethodName = "method1", StartLine = 10, NbLines = 20 },
new DuplicationCode { CodeHash = "hash2", FilePath = "file2.cs", MethodName = "method2", StartLine = 8, NbLines = 10 }
};


// Act
CsvExporter.ExportCodeDuplicationsToCsv(filePath, duplications);

// Assert
Assert.True(File.Exists(filePath));
var lines = File.ReadAllLines(filePath);
Assert.Equal(3, lines.Length);

// Cleanup
File.Delete(filePath);

}

private List<NamespaceMetrics> GetSampleNamespaceMetrics()
{
return new List<NamespaceMetrics>
Expand Down
2 changes: 1 addition & 1 deletion CodeLineCounter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static void AnalyzeAndExportSolution(string solutionPath, bool verbose)

Parallel.Invoke(
() => CsvExporter.ExportToCsv(csvFilePath, metrics.ToList(), projectTotals, totalLines, duplicationMap, solutionPath),
() => CsvExporter.ExportCodeDuplicationsToCsv(duplicationCsvFilePath, duplicationMap, solutionPath)
() => CsvExporter.ExportCodeDuplicationsToCsv(duplicationCsvFilePath, duplicationMap)
);

Console.WriteLine($"The data has been exported to {csvFilePath}");
Expand Down
2 changes: 1 addition & 1 deletion CodeLineCounter/Utils/CsvExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void ExportToCsv(string filePath, List<NamespaceMetrics> metrics,
}


public static void ExportCodeDuplicationsToCsv(string filePath, List<DuplicationCode> duplications, string? solutionPath)
public static void ExportCodeDuplicationsToCsv(string filePath, List<DuplicationCode> duplications)
{
CsvHandler.Serialize(duplications, filePath);
}
Expand Down