Working folder (phase 1): CSV/raw/step/step_finali all used to live split across two different implicit locations (CSV in the "repo root" found by walking up for CLAUDE.md, raw/step next to the input distinta file) with neither shown to the user. That repo-root lookup also silently breaks once the app runs as a standalone published exe on a machine with no repo/ CLAUDE.md at all. Replaced both with one explicit "cartella di lavoro", auto-suggested (last used, remembered the same way as the DB path) and changeable from phase 1, with no dependency on any repo marker file. Rename: CadSearchGui was the working name from before the app had a product identity; renamed folders, csproj files, namespace and the AppData settings folder to PrepStep throughout, matching the exe name already in use. Product-facing name stays "Cevolani StepPrep". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using PrepStep;
|
|
|
|
namespace PrepStep.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); }
|
|
}
|
|
}
|