Files
Masterarbeit/QuellCode/CentronERP/tests/Centron.Tests.EndToEnd/Tests/System/Indexing/Documents/DocumentFulltextIndexingTests.cs
T
Christoph Schwörer f045b99a25 Codebasis als Dateien ins Arbeitsrepo statt als Gitlink
QuellCode/CentronERP war nur als Gitlink (Submodul-Referenz auf 79c1142)
getrackt, ohne .gitmodules und ohne erreichbares Remote. Der
Untersuchungsgegenstand der Versuchsreihe war damit nicht reproduzierbar
gesichert: Ein Klon haette ein leeres Verzeichnis erhalten, und die Belege
der 3.287 Anforderungen waeren nicht ueberpruefbar gewesen.

Umstellung:
- Historie nach c:\DEV\CentronERP_git_snapshot_79c1142 ausgelagert
  (vollstaendig lesbar, enthaelt 79c1142 und Vorgaenger 89ccfd6)
- Gitlink aus dem Index entfernt
- Dateiinhalt aufgenommen: 24.557 Dateien, rund 333 MB

Die verschachtelte .gitignore der Codebasis gilt weiter, Build-Artefakte
bleiben ausgeschlossen. Details in Versuche/Versuch_01/_Codebasis-Nachweis.md
2026-08-26 07:43:51 +02:00

116 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Centron.BusinessLogic;
using Centron.BusinessLogic.Administration.FileManagement;
using Centron.BusinessLogic.WebServices.Administration.FileManagement;
using Centron.Interfaces.BL;
using Centron.Tests.EndToEnd.Infrastructure;
using CentronSoftware.Centron.WebServices.Entities.Administration.FileManagement;
using Xunit.Abstractions;
namespace Centron.Tests.EndToEnd.Tests.System.Indexing.Documents;
public class DocumentFulltextIndexingTests : EndToEndTest
{
public DocumentFulltextIndexingTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
}
public override void Execute()
{
using var session = new BLSession();
var newDocs = InsertExampleDocumentsIntoDatabase(session);
// Check if we have the index stats for the documents
string sql = @$"SELECT DocumentI3D, IsUpdateRequested
FROM DocumentFulltextIndexStats
WHERE DocumentI3D IN ({string.Join(",", newDocs)})
ORDER BY DocumentI3D";
Verifier.VerifySql("DocumentFulltextIndexingTests_NewDoc_Stats", sql);
// Verify the created indexes
sql = @$"SELECT DocumentI3D, TextValue
FROM DocumentFulltextIndex
WHERE DocumentI3D IN ({string.Join(",", newDocs)})
ORDER BY DocumentI3D, TextValue";
Verifier.VerifySql("DocumentFulltextIndexingTests_NewDoc_Indexes", sql);
// Search after the new documents
var searchResult = session.GetBL<DocumentWebServiceBL>().SearchDocumentsThroughPaging(
base.GetLoggedInUser(), new DocumentFilter()
{
SearchText = "DE10034252384"
}, 1, int.MaxValue).ThrowIfError();
var foundDocumentNames = searchResult.Result.Select(s => s.Name).ToList();
Verifier.Verify("DocumentFulltextIndexingTests_DocSearch", foundDocumentNames);
// Test the service
session.DAOSession.GetSession().Clear();
base.Sql("TRUNCATE TABLE DocumentFulltextIndexStats");
base.Sql("TRUNCATE TABLE DocumentFulltextIndex");
session.GetBL<DocumentBL>().CreateMissingIndexes(isUnitTest:true);
// Check if we have the index stats for the documents
sql = @$"SELECT DocumentI3D, IsUpdateRequested
FROM DocumentFulltextIndexStats
WHERE DocumentI3D IN ({string.Join(",", newDocs)})
ORDER BY DocumentI3D";
Verifier.VerifySql("DocumentFulltextIndexingTests_NewDoc_Stats_after_truncate", sql);
// Check if we have our indexes again
sql = @$"SELECT DocumentI3D, TextValue
FROM DocumentFulltextIndex
WHERE DocumentI3D IN ({string.Join(",", newDocs)})
ORDER BY DocumentI3D, TextValue";
Verifier.VerifySql("DocumentFulltextIndexingTests_NewDoc_Indexes_after_truncate", sql);
}
private List<int> InsertExampleDocumentsIntoDatabase(BLSession session)
{
var fileList = GetExampleDocumentsFromResource();
var documentBL = session.GetBL<DocumentBL>();
var newDocI3Ds = new List<int>();
foreach (var file in fileList)
{
// Directory I3D "3265" is from the folder "Rechnung 40171". Just picked one randomly. We want to test the indexing.
var newDoc = documentBL.AddFileToDirectory(base.GetLoggedInUser(), 3265, file.Value, file.Key, file.Value.Length, true);
if (newDoc == null || newDoc.I3D <= 0)
throw new Exception("Could create the example document!");
newDocI3Ds.Add(newDoc.I3D);
}
return newDocI3Ds;
}
private List<KeyValuePair<string,byte[]>> GetExampleDocumentsFromResource()
{
var exampleFileList = new List<string>
{
"ExampleFile_PDF_RE936953.pdf",
"ExampleFile_RTF_RE936953.rtf",
"ExampleFile_WORD_RE936953.docx",
"ExampleFile_XLSX_RE936953.xlsx",
"ExampleFile_MSG.msg"
};
var fileList = new List<KeyValuePair<string, byte[]>>();
foreach (var file in exampleFileList)
{
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"Centron.Tests.EndToEnd.Tests.System.Indexing.Documents.{file}");
if (stream == null)
throw new Exception($"No resource file '{file}' available!");
using var memStream = new MemoryStream();
stream.CopyTo(memStream);
fileList.Add(new KeyValuePair<string, byte[]>(file, memStream.ToArray()));
}
return fileList;
}
}