using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts.ArticleSearch; using Centron.BusinessLogic.Sales.Receipts.Internal; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket126433; public class Ticket126433Tests : EndToEndTest { public Ticket126433Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { // In this Ticket 126433 the issue was a DivideByZeroException // // There was a contract with a fixed-price-discount // This fixed-price-discount has to be converted to a percentage-discount (because the receipt-items only have a percentage-discount internally) // To do that conversation, we basically do this calculation: discountAsPercentage = (discountAsFixedPrice / basePrice) * 100; // This fails with a DivideByZeroException, if basePrice is 0 this.PrepareDatabase(); using var session = new BLSession(); var contractI3D = 22; var article = session.GetBL().GetSearchedArticle(isExternalArticle: false, articleI3D: 5, calculatePrices: false); var (basePrice, discount) = session.GetBL().GetBasePrice(purchaseBasePrice: 0, article, customer: null, contractI3D); Assert.Equal(0, basePrice); Assert.Equal(0, discount); } private void PrepareDatabase() { this.Sql($"UPDATE dbo.VertragBepreisungArtikel SET Aenderungsart = 1"); } }