using System; using System.Diagnostics.Contracts; using Centron.BusinessLogic; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.Sales.Receipts.ContractLists; using Centron.BusinessLogic.Sales.Receipts.DataAndResults; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Data.Entities.Administration.Logins; using Centron.Data.WebServices.Sales.CustomerAssets.Contracts; using Centron.Interfaces; using Centron.Interfaces.Administration.Environment; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.BillingCenter.Contracts; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.Sales.Receipts.ContractLists; using Newtonsoft.Json; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Contracts { public class ContractTests : EndToEndTest { public ContractTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { var contract = this.GetNewContract(); this.SaveNewContract(contract); } private ReceiptContractDTO GetNewContract() { using (var session = new BLSession()) { var user = session.GetBL().GetAppUser(f => f.I3D == 11); var result = session.GetBL().CreateNewReceipt(CentronObjectKindNumeric.ContractClass, new LoggedInUser(user), 10022, new CreateReceiptData(), null, null, true, false, true); var contract = (ReceiptContractDTO)result.Data.Receipt; contract.BillingIntervalDuration = 0; contract.CounterBillingKind = 0; contract.CalcNeedKind = 0; contract.BillingKind = 0; contract.ContractKindI3D = 12; //we need these 2 so todo gets created contract.FirstPaidDate = new DateTime(2020, 1, 1); contract.CalculationKind = ContractCalculationKind.Auto; //before this would create a null ref contract.ContractBillingToDoOffset = null; return contract; } } private void SaveNewContract(ReceiptContractDTO receipt) { using (var session = new BLSession()) { var user = session.GetBL().GetAppUser(f => f.I3D == 11); var result = session.GetBL().SaveReceipt(receipt, user, new SaveReceiptData { IgnoreCallbacks = true }, false, CreatedThroughApplication.CentronNet, null); Assert.Equal(ResultStatus.Success, result.Status); this.Verifier.VerifySql("ContractTodoExists", $"SELECT Termin, Bereich, ObjektArt, ObjectI3D FROM ToDoListe WHERE ObjektArt = 22 AND ObjectI3D = {result.Data.Receipt.I3D}"); } } } }