using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.Sales.Support; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Data.WebServices.Sales.Receipts.Invoices; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket136175; public class Ticket136175Tests : EndToEndTest { public Ticket136175Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.IgnoreProperty(f => f.BalanceID); } public const int CustomerI3D = 10010; public const int ContractI3D = 25; // Is a contingent contract of customer 10010 public const int WorkItemBalanceArticleI3D = 111; public override void Execute() { this.PrepareDatabase(); // In this ticket the problem was: // That contract-contingent-balance-items were created for the work-item-balance-item // That is incorrect, and we shouldn't create those contract-contingent-balance-items var invoice = this.CreateNewInvoice(); invoice.ContractI3D = ContractI3D; //Assign contract, to make sure we get contingent-balance-items var items = this.CreateItems(invoice); this.Verifier.Verify("CreatedItems", items); Assert.DoesNotContain(items, f => f.BalanceID is not null); //Assert that no balance-items were created } private void PrepareDatabase() { var helpdeskSettings = this.WithSession(s => s.GetBL().GetHelpdeskSettings()); helpdeskSettings.TimerBillingArticleWorkItemBalanceArticleI3D = WorkItemBalanceArticleI3D; this.WithSession(s => s.GetBL().UpdateHelpdeskSettings(helpdeskSettings)); this.Sql($"DELETE FROM dbo.GroupToContingent"); this.Sql($"INSERT INTO dbo.GroupToContingent (ContractI3D, Kind, ElementI3D) VALUES (0, 1, 3)"); } private ReceiptInvoiceDTO CreateNewInvoice() { using var session = new BLSession(); var createNewReceiptData = session.GetBL().CreateNewReceipt( CentronObjectKindNumeric.InvoiceClass, this.GetLoggedInUser(), CustomerI3D, new CreateReceiptData { IgnoreCallbacks = true }, addressI3D: null, contactPersonI3D: null, insertSalutationAndAgreement: false, ignoreDefaultContract: true, insertCustomerDiscount: false).ThrowIfError(); return (ReceiptInvoiceDTO)createNewReceiptData.Receipt; } private List CreateItems(ReceiptInvoiceDTO invoice) { using var session = new BLSession(); var itemsResult = session.GetBL().CreateArticleReceiptItems( invoice, isExternalArticle: false, WorkItemBalanceArticleI3D, externalArticleKind: null, externalArticleId: null, warehouseI3D: -1, //Use main warehouse this.GetLoggedInUser()).ThrowIfError(); return itemsResult.ReceiptItems.Cast().ToList(); } }