using System.Collections.Generic; using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Accounts; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Data.Entities.Sales.Receipts.Offers.OfferImport; using Centron.Data.WebServices.Sales.Receipts.Offers; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.CustomerArea.CustomerToArticle; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket133940; public class Ticket133940Tests : EndToEndTest { public Ticket133940Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.CleanupProperty(f => f.ManufacturerCode, RegexHelper.Guid, "Guid"); } public const int CustomerI3D = 10006; public const string OwnArticleManufacturerCode = "CF-30CTQAFBG"; public const string ExternalArticleManufacturerCode = "Q7830A#BAP"; public const string UnknownArticleManufacturerCode = "2444666668888888"; public const string CustomerArticleCode = "blabla-kunden-artikelcode-hehe"; public override void Execute() { this.PrepareDatabase(); var offer = this.CreateNewOffer(); this.ImportReceiptItems(offer); } private void PrepareDatabase() { // The HerstellerArtik are kinda broken - they all reference some invalid Hersteller (I3D column) // So fix one article up, so it can be found and used in CreateReceiptItemsFromImport this.Sql("UPDATE dbo.HerstellerArtik SET I3D = 49 WHERE I3D0 = 4771711"); // Create a customer article-code row this.WithSession(session => { session.GetBL().SaveCustomerArticle(new CustomerArticleDTO { CustomerI3D = CustomerI3D, ArticleI3D = 4359, CustomerArticleCode = CustomerArticleCode, }); }); } private ReceiptOfferDTO CreateNewOffer() { using var session = new BLSession(); var newReceiptData = session.GetBL().CreateNewReceipt( CentronObjectKindNumeric.OfferClass, this.GetLoggedInUser(), CustomerI3D, new CreateReceiptData { IgnoreCallbacks = true, }, addressI3D: null, contactPersonI3D: null, insertSalutationAndAgreement: false, ignoreDefaultContract: true, insertCustomerDiscount: false).ThrowIfError(); return (ReceiptOfferDTO)newReceiptData.Receipt; } private void ImportReceiptItems(ReceiptOfferDTO offer) { using var session = new BLSession(); var parsedData = new ParsedData { Positions = new List { // Case 1: We have a article with that manufacturer code new ParsedPositionData { VendorCode = OwnArticleManufacturerCode, Description = "Eigener Artikel", PurchasePrice = 50, SellPrice = 100, }, // Case 2: We know this manufacturer-code as a external article new ParsedPositionData { VendorCode = ExternalArticleManufacturerCode, Description = "Externer Artikel", PurchasePrice = 50, SellPrice = 100, }, // Case 3: A unknown manufacturer-code new ParsedPositionData { VendorCode = UnknownArticleManufacturerCode, Description = "Unbekannter Artikel", PurchasePrice = 50, SellPrice = 100, }, // Case 4: A customer article-code new ParsedPositionData { VendorCode = CustomerArticleCode, Description = "Kunden Artikelcode", PurchasePrice = 50, SellPrice = 100, }, // Case 5: No manufacturer-code at all new ParsedPositionData { VendorCode = null, Description = "Kein Herstellercode", PurchasePrice = 50, SellPrice = 100 }, }, DescriptionKind = DescriptionKind.Source, }; var importedItems = session.GetBL().CreateReceiptItemsFromImport( offer, this.GetLoggedInUser(), parsedData).ThrowIfError(); this.Verifier.Verify("ImportedItems", importedItems); } }