using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Core.Extensions; using Centron.Data.WebServices.Sales.Receipts.Offers; using Centron.Interfaces; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket134995; public class Ticket134995Test : EndToEndTest { public Ticket134995Test(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } const int Customer1I3D = 10000; const int Customer1ContractI3D = 10; const int Customer2I3D = 10003; const int Customer2ContractI3D = 5; const int Customer3I3D = 10005; const int Customer3ContractI3D = 19; public override void Execute() { this.PrepareDatabase(); // Should not have a contractI3D now this.UpdateContracts(null); this.RunTest(null); // Should have Customer1 ContractI3D this.UpdateContracts(Customer1ContractI3D); this.RunTest(Customer1ContractI3D); // Should have Customer2 ContractI3D (first company-group) this.UpdateContracts(Customer2ContractI3D); this.RunTest(Customer2ContractI3D); // Should have Customer3 ContractI3D (2 levels of company-groups) this.UpdateContracts(Customer3ContractI3D); this.RunTest(Customer3ContractI3D); // Create a endless loop in company-groups, and test that the code finishes (Ticket 137341) this.PrepareDatabaseForEndlessLoopInCompanyGroups(); this.UpdateContracts(null); this.RunTest(null); } private void PrepareDatabase() { this.Sql($"INSERT INTO dbo.KundeToKonzern (KundenI3D, KonzernI3D) VALUES ({Customer1I3D}, {Customer2I3D})"); this.Sql($"INSERT INTO dbo.KundeToKonzern (KundenI3D, KonzernI3D) VALUES ({Customer2I3D}, {Customer3I3D})"); } private void PrepareDatabaseForEndlessLoopInCompanyGroups() { this.Sql($"INSERT INTO dbo.KundeToKonzern (KundenI3D, KonzernI3D) VALUES ({Customer3I3D}, {Customer1I3D})"); } private void UpdateContracts(int? defaultContractI3D) { this.Sql($"UPDATE dbo.VertragKopf SET Rahmenvertrag = {(defaultContractI3D == Customer1ContractI3D).ToOneZeroInteger()} WHERE I3D = {Customer1ContractI3D}"); this.Sql($"UPDATE dbo.VertragKopf SET Rahmenvertrag = {(defaultContractI3D == Customer2ContractI3D).ToOneZeroInteger()} WHERE I3D = {Customer2ContractI3D}"); this.Sql($"UPDATE dbo.VertragKopf SET Rahmenvertrag = {(defaultContractI3D == Customer3ContractI3D).ToOneZeroInteger()} WHERE I3D = {Customer3ContractI3D}"); } private void RunTest(int? expectedContractI3D) { using var session = new BLSession(); var receipt = session.GetBL().CreateNewReceipt( CentronObjectKindNumeric.OfferClass, this.GetLoggedInUser(), Customer1I3D, new CreateReceiptData(), addressI3D: null, contactPersonI3D: null, insertSalutationAndAgreement: false, ignoreDefaultContract: false, // Important insertCustomerDiscount: false); var offer = (ReceiptOfferDTO)receipt.Data.Receipt; Assert.Equal(expectedContractI3D, offer.ContractI3D); } }