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() .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!");