using System; using Centron.BusinessLogic; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Data.Entities.Administration.Logins; using Centron.Data.WebServices.Sales.Receipts.Offers; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.ReceiptDunningBlock { public class ReceiptDunningBlockTests : EndToEndTest { public ReceiptDunningBlockTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } // We use customer 10009 for this test, and invoice 1369, and currently "block orders dunning-level" of -1 (never) // So it is a very clean and nice playground to test all the possible combinations private const int CustomerI3D = 10009; private const int InvoiceI3D = 1369; public override void Execute() { var customerBlockOrderDunningLevels = new[] {0, 1, 2, 3}; var invoiceDunningLevels = new[] {0, 1, 2, 3}; this.ExecuteMatrix( customerBlockOrderDunningLevels, invoiceDunningLevels, (customerBlockOrderDunningLevel, invoiceDunningLevel) => { // Arrange this.Sql($"UPDATE dbo.Kunden SET AuftragsperreNachMahnung = {customerBlockOrderDunningLevel} WHERE I3D = {CustomerI3D}"); this.Sql($"UPDATE dbo.RechKopf SET Mahnstufe = {invoiceDunningLevel} WHERE I3D = {InvoiceI3D}"); // Act var result = this.CreateOrderBlockedFromDunningLevel(); // Assert this.Verifier.Verify($"CustomerBlockOrderDunningLevel{customerBlockOrderDunningLevel}_InvoiceDunningLevel{invoiceDunningLevel}_IsBlocked", result); }); } private bool CreateOrderBlockedFromDunningLevel() { using (var session = new BLSession()) { var user = session.GetBL().GetAppUser(f => f.I3D == 11); var result = session.GetBL().CreateNewReceipt( CentronObjectKindNumeric.OrderClass, new LoggedInUser(user), CustomerI3D, new CreateReceiptData(), null, null, true, false, true); return result.Status == ResultStatus.Error && result.Message == "Aufgrund der Mahnstufe darf kein neuer Beleg vom Typ \"Auftrag\" angelegt werden."; } } } }