using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.Warehousing; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Warehousing; using Centron.Data.Entities.Administration.Logins; using Centron.Data.WebServices.Sales.Receipts.DeliveryLists; using Centron.Interfaces; using Centron.Interfaces.Administration.Environment; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.Receipts; using Centron.Interfaces.Warehousing; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket119564 { public class Ticket119564Tests : EndToEndTest { public Ticket119564Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { // This test validates that the SaveReceipt method returns NegativeArticleStockBookings // Article 4329 has a quantity of 1 in the database, and we want to create a delivery-list with 10 of it // That means oldQuantity should be 1, newQuantity should be -9 var deliveryList = this.CreateDeliveryList(); using (var saveSession = new BLSession()) { var user = saveSession.GetBL().GetAppUser(f => f.I3D == 11); var saveResult = saveSession.GetBL().SaveReceipt( deliveryList, user, new SaveReceiptData { IgnoreCallbacks = false, //Allow callbacks, because I want to check the negative-article-booking callback InsertFreightArticle = false }, autoLockIfNewReceipt: false, CreatedThroughApplication.CentronNet, receiptTemplateFolderI3D: null); Assert.Equal(ResultStatus.Error, saveResult.Status); this.Verifier.Verify("NegativeArticleBookings", saveResult.Data.NegativeArticleStockBookings); } } private ReceiptDeliveryListDTO CreateDeliveryList() { const int ArticleI3D = 4329; ReceiptDeliveryListDTO deliveryList; using (var session = new BLSession()) { var user = session.GetBL().GetAppUser(f => f.I3D == 11); // Create delivery-list var result = session.GetBL().CreateNewReceipt( CentronObjectKindNumeric.DeliveryListClass, new LoggedInUser(user), customerI3D: 10022, new CreateReceiptData(), addressI3D: null, contactPersonI3D: null, insertSalutationAndAgreement: true, ignoreDefaultContract: false, insertCustomerDiscount: true); // Create delivery-list-items var receiptItem = session.GetBL().CreateArticleReceiptItems( result.Data.Receipt, isExternalArticle: false, ArticleI3D, externalArticleKind: null, externalArticleId: null, warehouseI3D: -1, new LoggedInUser(user)); // Add items to delivery-list deliveryList = (ReceiptDeliveryListDTO) result.Data.Receipt; deliveryList.Items.AddRange(receiptItem.Data.ReceiptItems.Cast()); // Set quantity to more than available in the database, right now there is only 1 piece available var articlePosition = deliveryList.Items.Single(f => f.ArticleI3D == ArticleI3D); articlePosition.QuantityComplete = 10; } return deliveryList; } } }