using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Customers; using Centron.Interfaces.Sales.Receipts; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.FlatRate { public class FlatRateTests : EndToEndTest { public FlatRateTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { this.CreateAFakeFlatrateOrder(); this.TestCustomerSearch("CustomersWithBlanketOrders_AllOrders_1", onlyWithOpenOrders: false); this.TestCustomerSearch("CustomersWithBlanketOrders_OnlyWithOpenOrders_1", onlyWithOpenOrders: true); this.CloseTheFakeFlatrateOrder(); this.TestCustomerSearch("CustomersWithBlanketOrders_AllOrders_2", onlyWithOpenOrders: false); this.TestCustomerSearch("CustomersWithBlanketOrders_OnlyWithOpenOrders_2", onlyWithOpenOrders: true); } private const int FlatRateArticleI3D = 178; private const int AufPosI3D = 824; private void CreateAFakeFlatrateOrder() { // Changing the AufPos to be a flatrate-item this.Sql($"UPDATE dbo.AufPos SET ArtikelI3D = {FlatRateArticleI3D} WHERE I3D = {AufPosI3D}"); } private void CloseTheFakeFlatrateOrder() { this.Sql($"UPDATE dbo.AufKopf SET Status = {(int)ReceiptState.Completed} WHERE I3D = (SELECT AP.AufKopfI3D FROM dbo.AufPos AP WHERE AP.I3D = {AufPosI3D})"); } private void TestCustomerSearch(string name, bool onlyWithOpenOrders) { using (var session = new BLSession()) { var customers = session.GetBL().SearchCustomersWithBlanketOrdersBySearchText(string.Empty, onlyWithOpenOrders) .Select(f => new {f.I3D, f.Name}) .ToList(); this.Verifier.Verify(name, customers); } } } }