using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.Settings; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Sales.Receipts.DataAndResults; using Centron.Data.Entities.Administration.Logins; using Centron.Data.WebServices.Sales.Receipts.DeliveryLists; using Centron.Data.WebServices.Sales.Receipts.Offers; using Centron.Interfaces; using Centron.Interfaces.Administration.Environment; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket116289 { public class Ticket116289Tests : EndToEndTest { public Ticket116289Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { // This test verifies, that the variable-combobox-field in receipts works as expected, and the settings are checked this.ExecuteMatrix( new [] {true, false}, new [] {true, false}, new [] {true, false}, (active, required, withValue) => { this.UpdateSettings(active, required); var deliveryList = this.CreateDeliveryList(); deliveryList.VariableComboBoxFieldI3D = withValue ? 10 : null; var saveResult = this.TrySaveDeliveryList(deliveryList); this.Verifier.Verify($"SaveResult_Active_{active}_Required_{required}_WithValue_{withValue}", saveResult); if (saveResult.Status is ResultStatus.Success) { this.AssertVariableComboBoxField(saveResult.Data.Receipt.I3D, deliveryList.VariableComboBoxFieldI3D); } }); } private void UpdateSettings(bool active, bool required) { using var session = new BLSession(); var settings = session.GetBL().GetSettingsForUpdate( AppSettingsConst.DeliveryListVariableDateField1Mandatory, AppSettingsConst.DeliveryListVariableValuesFieldIsActive); settings.UpdateBool(AppSettingsConst.DeliveryListVariableDateField1Mandatory, required); settings.UpdateBool(AppSettingsConst.DeliveryListVariableValuesFieldIsActive, active); settings.SaveSettings(); } private ReceiptDeliveryListDTO CreateDeliveryList() { using var session = new BLSession(); var user = session.GetBL().GetAppUser(f => f.I3D == 11); var result = session.GetBL().CreateNewReceipt(CentronObjectKindNumeric.DeliveryListClass, new LoggedInUser(user), 10022, new CreateReceiptData(), null, null, true, false, true); var deliveryList = (ReceiptDeliveryListDTO)result.Data.Receipt; deliveryList.VariableComboBoxFieldI3D = null; return deliveryList; } private Result TrySaveDeliveryList(ReceiptDeliveryListDTO deliveryList) { using var session = new BLSession(); var user = session.GetBL().GetAppUser(f => f.I3D == 11); var saveResult = session.GetBL().SaveReceipt(deliveryList, user, new SaveReceiptData { IgnoreCallbacks = false //We wanna validate that the callback for variable-combobox-field is called }, false, CreatedThroughApplication.CentronNet, null); return saveResult; } private void AssertVariableComboBoxField(int receipt3D, int? expectedVariableComboBoxFieldI3D) { using var session = new BLSession(); var deliveryList = (ReceiptDeliveryListDTO)session.GetBL().GetReceiptByI3D(receipt3D, CentronObjectKindNumeric.DeliveryListClass).ThrowIfError(); Assert.Equal(expectedVariableComboBoxFieldI3D, deliveryList.VariableComboBoxFieldI3D); } } }