Restructure Form1 into a sequential wizard (database -> import -> raw -> recursive component resolution -> completeness/STEP report), fix case-sensitivity bugs in codice/tipo_file lookups and a word-boundary gap in the assembly scanner that missed _D100-style sub-assembly references, and treat the distinta's general assembly as an ordinary CSV row (derived from the DBP_<codice>_<timestamp> filename) instead of special-casing it throughout. Also adds CadSearchGui.Tests (xUnit) covering the scanner, filename parsing, and the case-insensitive DB lookup behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using CadSearchGui;
|
|
|
|
namespace CadSearchGui.Tests;
|
|
|
|
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); }
|
|
}
|
|
}
|