using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts; using Centron.BusinessLogic.Sales.Receipts.Orders; using Centron.Data.Entities.Sales.Receipts.Orders; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket121005 { public class Ticket121005Tests : EndToEndTest { public Ticket121005Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { // The issue here is with the ReceiptOrderBL.SendOrderNotificationMails // Specifically the "article notification email" (ReceiptOrderBL.SendArticleNotificationEmail) // // When you create a new order (version 1) with many positions and other changes, and save it // and then, without closing the module, you created a new version (version 2) of it, with only minor changes // The "article notification mail" would only send a mail for the minor changes of version 2 (it used to compare current version with the one before that) // // But that is kind of incorrect, because the user just created that receipt, we wanna send the "article notification mail" for all changes in version 1 and 2 // One could say, that the order was in "version 0" before we started making changes // // Internally, the ReceiptOrderBL.SendArticleNotificationEmail uses the ReceiptOrderBL.GetAddedReceiptOrderPositionI3Ds to get a list of all added or changed position-I3Ds // Fix this method, to work correctly when you changed multiple versions this.VerifyAddedPositionsForOrderInAllVersions(orderI3D: 214, currentVersion: 5); this.VerifyAddedPositionsForOrderInAllVersions(orderI3D: 113, currentVersion: 5); this.VerifyAddedPositionsForOrderInAllVersions(orderI3D: 137, currentVersion: 3); } private void VerifyAddedPositionsForOrderInAllVersions(int orderI3D, int currentVersion) { // Run it once for the "previous version" this.VerifyAddedPositionsForOrder(orderI3D); // And then for all versions before that while (currentVersion > 0) { this.VerifyAddedPositionsForOrder(orderI3D, --currentVersion); } } private void VerifyAddedPositionsForOrder(int orderI3D, int previousVersion = -1) { using var session = new BLSession(); var order = session.GetBL().GetReceiptByI3D(orderI3D); var addedPositions = session.GetBL().GetAddedReceiptOrderPositionI3Ds(order, previousVersion); this.Verifier.Verify($"AddedPositions_Order_{orderI3D}_Version_{previousVersion}", addedPositions); } } }