using Centron.BusinessLogic; using Centron.BusinessLogic.WebServices.DataExchange.TelekomDive; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.DataExchange.TelekomDive; using Microsoft.AspNetCore.Mvc.RazorPages; using NLog.Filters; using System; using System.Collections.Generic; using System.Linq; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.DataExchange.TelekomDive { public class TelekomDiveProfileTest : EndToEndTest { public TelekomDiveProfileTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { // Ignore date/version fields in snapshot verification as they change with each run this.Verifier.Settings.IgnoreProperty(f => f.CreatedDate); this.Verifier.Settings.IgnoreProperty(f => f.ChangedDate); } public override void Execute() { var savedProfiles = this.CreateAndSaveTwoProfiles(); this.LoadAndVerifyProfiles(savedProfiles); this.FilterProfilesByMandator(savedProfiles); this.FilterProfilesByVisibility(savedProfiles); } private List CreateAndSaveTwoProfiles() { using (var session = new BLSession()) { var user = this.GetLoggedInUser(); var profile1 = new TelekomDiveProfileDTO { ProfileName = "Test Profile 1 - Full Config", MandatorI3D = 1, OfferRecipient = "Customer A - Test Company GmbH", BasedOnFrameContract = true, FrameContractNumber = "FC-2025-001", PartnerVatId = "DE123456789", PartnerCreditorId = "CRED-A-001", DiveComment = "This is a test profile with all features enabled", UseFixedPaymentDeadline = true, FixedPaymentDeadline = "30 days net", ValidityPeriodInDays = 14, UseFixedPosDiscount = true, FixedPosDiscount = 10.50m, UseFixedVAT = true, FixedVAT = 19.00m, IsVisible = true }; var profile2 = new TelekomDiveProfileDTO { ProfileName = "Test Profile 2 - Minimal Config", MandatorI3D = 2, OfferRecipient = "Customer B - Another Test Company AG", BasedOnFrameContract = false, FrameContractNumber = null, PartnerVatId = "DE987654321", PartnerCreditorId = "CRED-B-002", DiveComment = "Minimal configuration test profile", UseFixedPaymentDeadline = false, FixedPaymentDeadline = null, ValidityPeriodInDays = 30, UseFixedPosDiscount = false, FixedPosDiscount = null, UseFixedVAT = false, FixedVAT = null, IsVisible = false }; var profilesToSave = new List { profile1, profile2 }; var saveResult = session.GetBL() .SaveTelekomDiveProfiles(profilesToSave, user); if(saveResult.IsSuccess == false) throw new Exception($"Failed to save profiles: {saveResult.MessageCode}"); this.Verifier.Verify("CreateAndSaveTwoProfiles", saveResult); return saveResult.Data.ToList(); } } private void LoadAndVerifyProfiles(List savedProfiles) { using (var session = new BLSession()) { var filter = new TelekomDiveProfileFilter(); var loadResult = session.GetBL() .GetTelekomDiveProfiles(filter); if (loadResult.IsSuccess == false) throw new Exception($"Failed to load profiles: {loadResult.MessageCode}"); this.Verifier.Verify("LoadAndVerifyProfiles", loadResult); if (loadResult.Data.Count != savedProfiles.Count) { throw new Exception($"Expected {savedProfiles.Count} profiles, but found {loadResult.Data.Count}"); } // Verify the saved profiles are in the loaded results foreach (var savedProfile in savedProfiles) { var loadedProfile = loadResult.Data.FirstOrDefault(p => p.I3D == savedProfile.I3D); if (loadedProfile == null) { throw new Exception($"Profile with I3D {savedProfile.I3D} was not found in loaded profiles"); } if (string.Equals(loadedProfile.ProfileName, savedProfile.ProfileName) == false) { throw new Exception($"ProfileName mismatch for I3D {savedProfile.I3D}"); } if (loadedProfile.MandatorI3D != savedProfile.MandatorI3D) { throw new Exception($"MandatorI3D mismatch for I3D {savedProfile.I3D}"); } if (string.Equals(loadedProfile.OfferRecipient, savedProfile.OfferRecipient) == false) { throw new Exception($"OfferRecipient mismatch for I3D {savedProfile.I3D}"); } } } } private void FilterProfilesByMandator(List savedProfiles) { using (var session = new BLSession()) { var user = this.GetLoggedInUser(); var mandatorI3D = savedProfiles.First().MandatorI3D; var filter = new TelekomDiveProfileFilter { MandatorI3D = mandatorI3D }; var filterResult = session.GetBL() .GetTelekomDiveProfiles(filter); if (filterResult.IsSuccess == false) throw new Exception($"Failed to load profiles by mandator filter: {filterResult.MessageCode}"); this.Verifier.Verify("FilterProfilesByMandator", filterResult); if (filterResult.Data.Any(p => p.MandatorI3D != mandatorI3D)) { throw new Exception("Filter by MandatorI3D failed - found profiles with different MandatorI3D"); } } } private void FilterProfilesByVisibility(List savedProfiles) { using (var session = new BLSession()) { var user = this.GetLoggedInUser(); var savedVisibleI3D = savedProfiles.First(p => p.IsVisible).I3D; var savedInvisibleI3D = savedProfiles.First(p => !p.IsVisible).I3D; var visibleFilter = new TelekomDiveProfileFilter { IsVisible = true }; var visibleResult = session.GetBL() .GetTelekomDiveProfiles(visibleFilter); if (visibleResult.IsSuccess == false) throw new Exception($"Failed to load profiles by visible filter: {visibleResult.MessageCode}"); this.Verifier.Verify("FilterProfilesByVisibility_Visible", visibleResult); // Verify invisible profile is not in results if (visibleResult.Data.Any(p => p.I3D == savedInvisibleI3D)) { throw new Exception("Filter by IsVisible=true failed - found invisible profile"); } // Filter for invisible profiles only var invisibleFilter = new TelekomDiveProfileFilter { IsVisible = false }; var invisibleResult = session.GetBL() .GetTelekomDiveProfiles(invisibleFilter); if (invisibleResult.IsSuccess == false) throw new Exception($"Failed to load profiles by invisible filter: {invisibleResult.MessageCode}"); this.Verifier.Verify("FilterProfilesByVisibility_Invisible", invisibleResult); // Verify visible profile is not in results if (invisibleResult.Data.Any(p => p.I3D == savedVisibleI3D)) { throw new Exception("Filter by IsVisible=false failed - found visible profile"); } } } } }