2026-09-21 11:18:43 +02:00
|
|
|
using PrepStep;
|
2026-09-16 16:25:52 +02:00
|
|
|
|
2026-09-21 11:18:43 +02:00
|
|
|
namespace PrepStep.Tests;
|
2026-09-16 16:25:52 +02:00
|
|
|
|
|
|
|
|
public class DistintaBaseImporterTests
|
|
|
|
|
{
|
|
|
|
|
private const string SpreadsheetMlMinimo = """
|
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">
|
|
|
|
|
<Worksheet ss:Name="Distinta Base" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
|
|
|
|
|
<Table>
|
|
|
|
|
<Row><Cell ss:Index="2"><Data>Componente</Data></Cell><Cell><Data>Descrizione</Data></Cell></Row>
|
|
|
|
|
<Row><Cell ss:Index="2"><Data>1234567890</Data></Cell><Cell><Data>Vite</Data></Cell></Row>
|
|
|
|
|
</Table>
|
|
|
|
|
</Worksheet>
|
|
|
|
|
</Workbook>
|
|
|
|
|
""";
|
|
|
|
|
|
|
|
|
|
private static string ScriviFileDistinta(string nomeFile, string contenuto)
|
|
|
|
|
{
|
|
|
|
|
string percorso = Path.Combine(Path.GetTempPath(), $"cadsearch_test_{Guid.NewGuid():N}", nomeFile);
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(percorso)!);
|
|
|
|
|
File.WriteAllText(percorso, contenuto);
|
|
|
|
|
return percorso;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Aggiunge_assieme_generale_dedotto_dal_nome_file_DBP()
|
|
|
|
|
{
|
|
|
|
|
string percorso = ScriviFileDistinta("DBP_9244228573_20260916144238.xls", SpreadsheetMlMinimo);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (_, righe) = DistintaBaseImporter.ConvertiInCsv(percorso);
|
|
|
|
|
|
|
|
|
|
Assert.Contains(righe, r => r.Componente == "9244228573" && r.Descrizione == "Assieme generale");
|
|
|
|
|
Assert.Contains(righe, r => r.Componente == "1234567890");
|
|
|
|
|
}
|
|
|
|
|
finally { Directory.Delete(Path.GetDirectoryName(percorso)!, recursive: true); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Non_duplica_lassieme_generale_se_gia_presente_tra_i_componenti()
|
|
|
|
|
{
|
|
|
|
|
// Caso limite: il codice del nome file coincide con un componente già elencato nel foglio.
|
|
|
|
|
string contenutoConGeneraleGiaPresente = SpreadsheetMlMinimo.Replace("1234567890", "9244228573");
|
|
|
|
|
string percorso = ScriviFileDistinta("DBP_9244228573_20260916144238.xls", contenutoConGeneraleGiaPresente);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (_, righe) = DistintaBaseImporter.ConvertiInCsv(percorso);
|
|
|
|
|
|
|
|
|
|
Assert.Single(righe, r => r.Componente == "9244228573");
|
|
|
|
|
}
|
|
|
|
|
finally { Directory.Delete(Path.GetDirectoryName(percorso)!, recursive: true); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Nessun_assieme_generale_aggiunto_se_il_nome_file_non_segue_il_pattern_DBP()
|
|
|
|
|
{
|
|
|
|
|
string percorso = ScriviFileDistinta("estrazione_qualsiasi.xls", SpreadsheetMlMinimo);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (_, righe) = DistintaBaseImporter.ConvertiInCsv(percorso);
|
|
|
|
|
|
|
|
|
|
Assert.DoesNotContain(righe, r => r.Descrizione == "Assieme generale");
|
|
|
|
|
Assert.Single(righe);
|
|
|
|
|
}
|
|
|
|
|
finally { Directory.Delete(Path.GetDirectoryName(percorso)!, recursive: true); }
|
|
|
|
|
}
|
|
|
|
|
}
|