using System.Collections.Generic; using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.FileManagement; using Centron.BusinessLogic.WebServices.Administration.FileManagement; using Centron.Data.WebServices.Administration.FileManagement; using Centron.Interfaces; using Centron.Interfaces.Administration.Documents; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Documents; public class DocumentsCleanupTests : EndToEndTest { private int _referenceDirectoryI3D => 2093; public DocumentsCleanupTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { int docI3D = 0; for (int i = 0; i < 10; i++) { var resultI3D = AddDocumentToDirectory(); if (i == 4) docI3D = resultI3D; } using var session = new BLSession(); var result = base.Sql("SELECT COUNT(*) FROM Documents"); Assert.True(result == 10, $"Expected 10 document (currently existing:{result})"); result = session.GetBL().CleanupDocuments(6).ThrowIfError(); Assert.True(result == 0, $"Expected 0 deletes from 'CleanupDocuments' (got:{result})"); base.Sql($"UPDATE Documents SET OwnerDirI3D = NULL WHERE I3D <> {docI3D}"); result = session.GetBL().CleanupDocuments(6).ThrowIfError(); Assert.True(result == 6, $"Expected 6 deletes from 'CleanupDocuments' (got:{result})"); result = session.GetBL().CleanupDocuments(3).ThrowIfError(); Assert.True(result == 3, $"Expected 3 deletes from 'CleanupDocuments' (got:{result})"); result = base.Sql("SELECT COUNT(*) FROM Documents"); Assert.True(result == 1, $"Expected 1 remaining document (got:{result})"); } private int AddDocumentToDirectory() { using (var session = new BLSession()) { var result = session.GetBL().AddDocumentToDirectory(this.GetLoggedInUser(), this._referenceDirectoryI3D, new byte[] { 1,2,3,4,5,6,7,8,10,11,12,13,14,15 }, "ibims1bildchen", new List { new DocumentMetaInformationDTO { Type = DocumentMetaInformationType.ReceiptNumber, TypeName = "ibims1receiptnumber", Value = "123" }, new DocumentMetaInformationDTO { Type = DocumentMetaInformationType.SupplierI3D, TypeName = "ibims1supplieri3d", Value = "123" } }, fileObjectKind:CentronObjectKindNumeric.Chat); return result.I3D; } } }