using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Data.WebServices.Sales.Receipts.Orders; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.Receipts.InsertReceipts; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.EntitiesWrongPlace.Sales.Receipts.DataAndResults; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket133705; public class Ticket133705Tests : EndToEndTest { public Ticket133705Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public const int OfferI3D = 6732; public const int OtherOfferI3D = 141; public override void Execute() { this.PrepareDatabase(); var order = this.ForwardOfferToOrder(); this.Verifier.Verify("ServiceProperties", new { order.IsServiceActive, order.ServiceFee, order.ServiceMonths, order.ServiceRatePercent, order.ServiceRatePerMonth, Items = order.Items.Select(s => new { s.ArticleCode, s.IsService}).ToList() }); this.Verifier.Verify("LeasingProperties", new { order.IsLeasingActive, order.LeasingFee, order.LeasingMonths, order.LeasingRatePercent, order.LeasingRatePerMonth, Items = order.Items.Select(s => new { s.ArticleCode, s.IsLeasing}).ToList() }); this.CanNotForwardMultipleReceiptsWithDifferentLeasing(); } private void PrepareDatabase() { this.Sql($"UPDATE dbo.AngKopf SET IsServiceShare = 1, ServiceRate = 10 WHERE I3D = {OfferI3D}"); this.Sql("UPDATE AngPos SET isService = 1, isLeasing = 1 WHERE I3D IN (21086, 21087)"); } private ReceiptOrderDTO ForwardOfferToOrder() { using var session = new BLSession(); var forwardResult = session.GetBL().ForwardReceipt( CentronObjectKindNumeric.OrderClass, this.GetLoggedInUser().User, new ForwardReceiptData { IgnoreCallbacks = true, CreateReceiptData = new CreateReceiptData { IgnoreCallbacks = true, }, CreateReceiptItemsFromExistingItemsData = new List { new() { IgnoreCallbacks = true, }, }, }, new List { new() { ReceiptKind = CentronObjectKindNumeric.OfferClass, ReceiptI3D = OfferI3D } }, null, InsertReceiptTakeoverOptions.Copy, onlyTakeoverAvailableQuantity: false, ignoreDefaultContract: false).ThrowIfError(); return (ReceiptOrderDTO)forwardResult.Receipt; } private void CanNotForwardMultipleReceiptsWithDifferentLeasing() { using var session = new BLSession(); var forwardResult = session.GetBL().ForwardReceipt( CentronObjectKindNumeric.OrderClass, this.GetLoggedInUser().User, new ForwardReceiptData { IgnoreCallbacks = true, CreateReceiptData = new CreateReceiptData { IgnoreCallbacks = true, }, CreateReceiptItemsFromExistingItemsData = new List { new() { IgnoreCallbacks = true, }, }, }, new List { new() { ReceiptKind = CentronObjectKindNumeric.OfferClass, ReceiptI3D = OfferI3D }, new() { ReceiptKind = CentronObjectKindNumeric.OfferClass, ReceiptI3D = OtherOfferI3D } }, null, InsertReceiptTakeoverOptions.Copy, onlyTakeoverAvailableQuantity: false, ignoreDefaultContract: false); Assert.Equal(ResultStatus.Error, forwardResult.Status); this.Verifier.Verify("ForwardFailedMessage", forwardResult.Message); } }