using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.Rights; using Centron.BusinessLogic.EmployeeArea; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.ReceiptLock { public class ReceiptLockTests : EndToEndTest { public ReceiptLockTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } private const int OfferI3D = 123; private const int AppUserI3D = 21; public override void Execute() { var isOfferLockedInput = new[] { false, true }; var lockedByDifferentUserInput = new[] { false, true }; var hasUserRightInput = new[] { false, true }; this.ExecuteMatrix(isOfferLockedInput, lockedByDifferentUserInput, hasUserRightInput, (isOfferLocked, lockedByDifferentUser, hasUserRight) => { this.SetupDatabase(isOfferLocked, lockedByDifferentUser, hasUserRight); bool expectSuccess = isOfferLocked == false || lockedByDifferentUser == false || hasUserRight; this.TryRemoveLock($"IsOfferLocked_{isOfferLocked}_LockedByDifferentUser_{lockedByDifferentUser}_HasUserRight_{hasUserRight}", expectSuccess); }); } private void SetupDatabase(bool isOfferLocked, bool useDifferentUser, bool hasUserRight) { string employeeShortSign = useDifferentUser ? "bla" : this.Sql($"SELECT P.KurzZeich " + $"FROM dbo.Sichbenu S " + $"INNER JOIN dbo.Personal P ON P.I3D = S.Personal " + $"WHERE S.I3D = {AppUserI3D}"); this.Sql(isOfferLocked ? $"UPDATE dbo.AngKopf SET LockUser = '{employeeShortSign}' WHERE I3D = {OfferI3D}" : $"UPDATE dbo.AngKopf SET LockUser = NULL WHERE I3D = {OfferI3D}"); this.Sql(hasUserRight ? $"INSERT INTO dbo.Sichtrus (Gruppe, Recht) VALUES (40, {(int)UserRightsConst.Sales.Customer.CustomerCommon.UNLOCK_CUSTOMER_ATTACHMENTS})" : $"DELETE FROM dbo.Sichtrus WHERE Recht = {UserRightsConst.Sales.Customer.CustomerCommon.UNLOCK_CUSTOMER_ATTACHMENTS}"); } private void TryRemoveLock(string name, bool expectSuccess) { using var session = new BLSession(); var currentUser = session.GetBL().GetAppUser(f => f.I3D == AppUserI3D); var removeLockResult = session.GetBL().RemoveLock(CentronObjectKindNumeric.OfferClass, OfferI3D, onlyIfLockedByCurrentUser:false, currentUser); Assert.Equal(expectSuccess ? ResultStatus.Success : ResultStatus.Error, removeLockResult.Status); this.Verifier.Verify(name, removeLockResult); } } }