7d2961702c
✨ Nuove funzionalità: - Aggiunto campo SourceDatabaseName nella tabella DataCouplerProfiles - Implementato recupero automatico del nome database dalle credenziali - Migliorata applicazione profili con supporto database specifico - Aggiornata logica di connessione database con selezione database 🔧 Modifiche tecniche: - Aggiunta migration per colonna SourceDatabaseName - Estesi modelli DataCouplerProfile e DataCouplerProfileDto - Aggiornato DataCouplerProfileService per gestire nuovo campo - Modificato ProfileSaver per recupero automatico database name - Implementato metodo ConnectToDatabaseWithSpecificDatabase 🐛 Correzioni: - Migliorata gestione connessioni database multi-database - Corretta formattazione codice e spaziature - Rimosse linee vuote eccessive nel codice sorgente 🧪
54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
using CredentialManager.Data;
|
|
using CredentialManager.Models;
|
|
using CredentialManager.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
Console.WriteLine("🧪 Testing SourceDatabaseName retrieval from credentials...");
|
|
|
|
// Configurazione del database temporaneo
|
|
var options = new DbContextOptionsBuilder<CredentialDbContext>()
|
|
.UseSqlite("Data Source=test_credential_db.db")
|
|
.Options;
|
|
|
|
using var context = new CredentialDbContext(options);
|
|
await context.Database.EnsureCreatedAsync();
|
|
|
|
var credentialService = new CredentialService(context);
|
|
|
|
// Test 1: Crea una credenziale database con nome database
|
|
var testCredential = new DatabaseCredential
|
|
{
|
|
Name = "TestDatabaseCredential",
|
|
DatabaseType = "SqlServer",
|
|
Host = "localhost",
|
|
Port = 1433,
|
|
DatabaseName = "MyProductionDB",
|
|
Username = "testuser",
|
|
Password = "testpassword"
|
|
};
|
|
|
|
Console.WriteLine($"📝 Creando credenziale con DatabaseName: {testCredential.DatabaseName}");
|
|
var credentialId = await credentialService.SaveDatabaseCredentialAsync(testCredential);
|
|
Console.WriteLine($"✅ Credenziale salvata con ID: {credentialId}");
|
|
|
|
// Test 2: Recupera la credenziale
|
|
var retrievedCredential = await credentialService.GetDatabaseCredentialAsync(credentialId);
|
|
Console.WriteLine($"✅ Credenziale recuperata: {retrievedCredential?.Name}");
|
|
Console.WriteLine($" DatabaseName: {retrievedCredential?.DatabaseName}");
|
|
|
|
// Test 3: Simula il recupero del database name come farebbe ProfileSaver
|
|
if (retrievedCredential != null && !string.IsNullOrEmpty(retrievedCredential.DatabaseName))
|
|
{
|
|
Console.WriteLine($"✅ SUCCESSO: DatabaseName recuperato dalle credenziali: {retrievedCredential.DatabaseName}");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("❌ ERRORE: DatabaseName non recuperato dalle credenziali");
|
|
}
|
|
|
|
// Pulizia
|
|
await context.Database.EnsureDeletedAsync();
|
|
Console.WriteLine("🧹 Database temporaneo eliminato");
|
|
|
|
Console.WriteLine("\n🎯 Test completato con successo!");
|