using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Receipts; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Sales.Receipts.ReceiptSearch; using Centron.Data.WebServices.Sales.Receipts.ReceiptSearch; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.Receipts.ReceiptSearch; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.ReceiptPrices { public class ReceiptPricesTests : EndToEndTest { public ReceiptPricesTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { // It seems a bit excessive to test all the receipts in the database // But it only takes 20 seconds, sooooo that's kinda easy // And I hope that we catch every edge case like that (okay, not with swiss-rounding, but still) var allReceipts = this.GetAllReceiptsInDatabase() .Where(f => f.ObjectKind != (int)CentronObjectKindNumeric.SupplierOffer) //Gotta skip supplier-offers, we don't really support them anymore .OrderBy(f => f.ObjectKind) .ThenBy(f => f.Number); foreach (var receipt in allReceipts) { this.CalculatePrices((CentronObjectKindNumeric)receipt.ObjectKind, receipt.I3D); } } private IList GetAllReceiptsInDatabase() { using var session = new BLSession(); var allReceipts = session.GetBL().SearchReceipts( this.GetLoggedInUser(), new ReceiptSearchFilter { IncludeClosedReceipts = true, }, page: 1, int.MaxValue); return allReceipts.ThrowIfError().Result; } private void CalculatePrices(CentronObjectKindNumeric receiptKind, int receiptI3D) { using var session = new BLSession(); var receipt = session.GetBL().GetReceiptByI3D(receiptKind, receiptI3D); var prices = session.GetBL().CalculateReceiptPrices(receipt); var pricesForVerifier = new { prices.NetPrice, prices.TaxPrice, prices.NetPriceFC, prices.TaxPriceFC, prices.NotDiscountableNetPriceFC, prices.NotDiscountableTaxPriceFC, }; this.Verifier.Verify($"PricesFor_{receiptKind.GetReceiptShortName()}_{receiptI3D}", pricesForVerifier); } } }