using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.FileManagement; using Centron.BusinessLogic.WebServices.Administration.FileManagement; using Centron.DAO.AdoNETDataAccess; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.TicketTests.Ticket127512; public class Ticket127512Tests : EndToEndTest { public Ticket127512Tests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } private const int DirectoryI3D = 77; //Directory "Kunde 10001" public override void Execute() { // DocumentBL // .GetDocumentsByDirectory // .GetDocumentsFromDirectory // // These methods had a little performance-problem, because they would always load the file-contents from the database // even if they were not needed this.PrepareDatabase(); var getDocumentsByDirectorySqlCommands = SqlDiagnosticObserver.Start(() => { using var session = new BLSession(); session.GetBL().GetDocumentsByDirectory(DirectoryI3D); }); var loggedInUser = this.GetLoggedInUser(); var getDocumentsFromDirectorySqlCommands = SqlDiagnosticObserver.Start(() => { using var session = new BLSession(); session.GetBL().GetDocumentsFromDirectory(loggedInUser, DirectoryI3D); }); this.Verifier.Verify("SqlCommands_GetDocumentsByDirectory", getDocumentsByDirectorySqlCommands.Select(f => f.CommandText)); this.Verifier.Verify("SqlCommands_GetDocumentsFromDirectory", getDocumentsFromDirectorySqlCommands.Select(f => f.CommandText)); } private void PrepareDatabase() { for (int i = 0; i < 50; i++) { var testData = Encoding.UTF8.GetBytes("Testdata"); using var session = new BLSession(); session.GetBL().AddDocumentToDirectory(this.GetLoggedInUser(), DirectoryI3D, testData, $"Test {i}.txt"); } this.Verifier.VerifySql("DocumentsTable", $"SELECT DocCount = COUNT(*) FROM dbo.Documents WHERE OwnerDirI3D = {DirectoryI3D}"); } }