using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts.ArticleSearch; using Centron.BusinessLogic.Sales.Receipts.Internal; using Centron.BusinessLogic.Warehousing; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket103420 { public class Ticket103420Test : EndToEndTest { public const int CurrencyFactorArticleI3D = 4363; public const int ControlGroupArticleI3D = 4350; public Ticket103420Test(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { this.PrepareDatabase(); // Alright, in the database is article 4363 with // - currency-factor 1.0 // - currency-factor country 2 (belgium) // - purchase-price and sell-price of 150 // And country 2 (belgium) with currency-factor right now of 1.5 // That means, if we now calculate this articles prices, we should get // CurrentPrice = Price * Article.CurrencyFactor / Country.CurrencyFactor // 100 € = 150 € * 1.0 / 1.5 // The control group article 4350 has the same prices, but still currency-factor country 1 this.ValidatePrices(CurrencyFactorArticleI3D, expectedPrice: 100m); this.ValidatePrices(ControlGroupArticleI3D, expectedPrice: 150m); } private void PrepareDatabase() { this.Sql($"UPDATE dbo.ARTIK SET FremdwaehrungLandI3D = 2, VK_1 = 150, VK_2 = 150, VK_3 = 150, VK_4 = 150, EK = 150 WHERE I3D = {CurrencyFactorArticleI3D}"); this.Sql($"UPDATE dbo.ARTIK SET VK_1 = 150, VK_2 = 150, VK_3 = 150, VK_4 = 150, EK = 150 WHERE I3D = {ControlGroupArticleI3D}"); this.Sql($"UPDATE dbo.Laenkenn SET KursZuEur = 1.5 WHERE I3D = 2"); } private void ValidatePrices(int articleI3D, decimal expectedPrice) { using (var session = new BLSession()) { var article = session.GetBL().GetArticleByI3D(articleI3D); var searchedArticle = session.GetBL().GetSearchedArticle(isExternalArticle: false, articleI3D, calculatePrices: false); var articlePurchasePrice = session.GetBL().GetPurchaseBasePrice(article, warehouseI3D: null, specialAgreement: null); var searchedArticlePurchasePrice = session.GetBL().GetPurchaseBasePrice(searchedArticle, warehouseI3D: null, specialAgreement: null); Assert.Equal(expectedPrice, articlePurchasePrice); Assert.Equal(expectedPrice, searchedArticlePurchasePrice); var (articlePrice, _) = session.GetBL().GetBasePrice(articlePurchasePrice, article); var (searchedArticlePrice, _) = session.GetBL().GetBasePrice(searchedArticlePurchasePrice, searchedArticle); Assert.Equal(expectedPrice, articlePrice); Assert.Equal(expectedPrice, searchedArticlePrice); } } } }