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 🧪
63 lines
2.3 KiB
C#
63 lines
2.3 KiB
C#
using CredentialManager.Data;
|
|
using CredentialManager.Models;
|
|
using CredentialManager.Services;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
Console.WriteLine("🧪 Testing SourceDatabaseName database persistence...");
|
|
|
|
// Configurazione del database temporaneo
|
|
var options = new DbContextOptionsBuilder<CredentialDbContext>()
|
|
.UseSqlite("Data Source=test_sourcedatabase.db")
|
|
.Options;
|
|
|
|
using var context = new CredentialDbContext(options);
|
|
await context.Database.EnsureCreatedAsync();
|
|
|
|
var profileService = new DataCouplerProfileService(context);
|
|
|
|
// Test: Creazione e salvataggio di un profilo con SourceDatabaseName
|
|
var testProfile = new DataCouplerProfile
|
|
{
|
|
Name = "Test Profile DB",
|
|
Description = "Test per verificare il salvataggio del SourceDatabaseName",
|
|
SourceType = "database",
|
|
SourceDatabaseName = "MyProductionDatabase",
|
|
SourceSchema = "dbo",
|
|
SourceTable = "customers",
|
|
DestinationType = "rest",
|
|
DestinationEndpoint = "/api/customers",
|
|
CreatedBy = "TestUser"
|
|
};
|
|
|
|
Console.WriteLine($"📝 Creando profilo con SourceDatabaseName: {testProfile.SourceDatabaseName}");
|
|
|
|
// Salvataggio nel database
|
|
var savedProfile = await profileService.SaveProfileAsync(testProfile);
|
|
Console.WriteLine($"✅ Profilo salvato con ID: {savedProfile.Id}");
|
|
|
|
// Recupero dal database
|
|
var retrievedProfile = await profileService.GetProfileByIdAsync(savedProfile.Id);
|
|
Console.WriteLine($"✅ Profilo recuperato dal database");
|
|
|
|
// Verifica che il SourceDatabaseName sia stato salvato e recuperato correttamente
|
|
if (retrievedProfile != null && retrievedProfile.SourceDatabaseName == testProfile.SourceDatabaseName)
|
|
{
|
|
Console.WriteLine($"✅ SUCCESSO: SourceDatabaseName salvato e recuperato correttamente: {retrievedProfile.SourceDatabaseName}");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"❌ ERRORE: SourceDatabaseName non salvato correttamente");
|
|
Console.WriteLine($" Originale: {testProfile.SourceDatabaseName}");
|
|
Console.WriteLine($" Recuperato: {retrievedProfile?.SourceDatabaseName ?? "NULL"}");
|
|
}
|
|
|
|
// Test conversione DTO
|
|
var dto = profileService.ToDto(retrievedProfile!);
|
|
Console.WriteLine($"✅ DTO convertito con SourceDatabaseName: {dto.SourceDatabaseName}");
|
|
|
|
// Pulizia
|
|
await context.Database.EnsureDeletedAsync();
|
|
Console.WriteLine("🧹 Database temporaneo eliminato");
|
|
|
|
Console.WriteLine("\n🎯 Test completato con successo!");
|