Files
Masterarbeit/QuellCode/CentronERP/tests/Centron.Tests.EndToEnd/Tests/RiverDivo/RiverDivoTests.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

179 lines
6.9 KiB
C#

using System.Collections.Generic;
using Centron.BusinessLogic.Administration.FileManagement;
using Centron.BusinessLogic.RiverDivo;
using Centron.BusinessLogic.WebServices.DataExchange.Rmm;
using CentronSoftware.Centron.WebServices.Entities.DataExchange.Rmm;
using Centron.BusinessLogic.WebServices.Administration.FileManagement;
using Centron.BusinessLogic.WebServices.Devices;
using Centron.BusinessLogic.WebServices.Sales.Support;
using Centron.Data.Entities.Administration.FileManagement;
using Centron.Interfaces;
using Centron.Interfaces.BL;
using Centron.Tests.EndToEnd.Infrastructure;
using CentronSoftware.Centron.WebServices.Entities.Devices;
using CentronSoftware.Centron.WebServices.Entities.RiverDivo;
using Xunit;
using Xunit.Abstractions;
namespace Centron.Tests.EndToEnd.Tests.RiverDivo;
public class RiverDivoTests : EndToEndTest
{
private const int _centronCustomerNumber = 10006;
private const int _riverbirdCustomerReference = 123;
private const string _helpdeskAttachmentFileName = "RiverDivoAttachment.txt";
private static readonly byte[] _helpdeskAttachmentFileContent = { 1, 2, 3, 4, 5 };
public RiverDivoTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}
public override void Execute()
{
this.PrepareDataBase();
this.TestCreateHelpdesk();
this.TestCreateHelpdeskWithDeviceLink();
this.TestValidateRmmAccessKey();
}
private void PrepareDataBase()
{
this.Sql($"UPDATE dbo.Kunden SET RiverbirdCustomerReference = {_riverbirdCustomerReference} WHERE I3D = {_centronCustomerNumber}");
}
private void TestCreateHelpdesk()
{
var data = new CentronConnectionCreateHelpdeskRequestDTO
{
ShortDescription = "Test-Short-Description",
Description = "Test-Description",
PriorityI3D = 5, // Sehr wichtig
StateI3D = 1, // offen
HelpdeskTypeI3D = 3, // Garantiefall
MainCategoryI3D = 5, // Notebook
SubCategory1I3D = 20, // Hardware
SubCategory2I3D = 23, // Tastatur
CustomerI3D = _riverbirdCustomerReference,
Adviser1 = true,
Adviser2 = true,
Adviser3 = true,
Adviser4 = true,
Adviser5 = true,
Adviser6 = true,
AssignDefaultDepartment = true,
AddToGeneralAgreementContract = true,
EditorI3Ds = new List<int> { 34 },
DefaultState = false,
Files = new List<HelpdeskFileDTO>
{
new()
{
FileName = _helpdeskAttachmentFileName,
FileContent = _helpdeskAttachmentFileContent,
},
},
};
var ticketI3D = this.WithSession(s => s.GetBL<RiverDivoBL>().CreateHelpdeskRequest(data, true));
var ticket = this.WithSession(s => s.GetBL<HelpdeskWebServiceBL>().GetHelpdeskByI3D(ticketI3D, this.GetLoggedInUser())).ThrowIfError();
var rootDirectory = this.WithSession(s => s.GetBL<DirectoryReferenceBL>().GetDirectoryReference(ticketI3D,
CentronObjectKindNumeric.HelpdeskClass, DirectoryReferenceKind.RootDirI3D));
Assert.NotNull(rootDirectory);
var documents = this.WithSession(s => s.GetBL<DocumentWebServiceBL>()
.GetDocumentsByDirectory(rootDirectory.DirectoryI3D)).ThrowIfError();
var attachment = Assert.Single(documents, document => document.Name == _helpdeskAttachmentFileName);
Assert.Equal(CentronObjectKindNumeric.HelpdeskClass, attachment.DocumentReferenceObjectKind);
var savedAttachment = this.WithSession(s => s.GetBL<DocumentWebServiceBL>()
.GetDocument(this.GetLoggedInUser(), attachment.I3D)).ThrowIfError();
Assert.Equal(_helpdeskAttachmentFileContent, savedAttachment.FileData);
this.Verifier.Verify("CreatedTicket", ticket);
}
private void TestCreateHelpdeskWithDeviceLink()
{
var ownDevice = this.WithSession(s => s.GetBL<AccountDeviceWebServiceBL>()
.SaveAccountDevice(this.GetLoggedInUser(), new AccountDeviceDTO
{
AccountI3D = 5,
ShortName = "Own-Device",
DeviceId = "OWN-DEVICE-001"
})).ThrowIfError();
var foreignDevice = this.WithSession(s => s.GetBL<AccountDeviceWebServiceBL>()
.SaveAccountDevice(this.GetLoggedInUser(), new AccountDeviceDTO
{
AccountI3D = 99999,
ShortName = "Foreign-Device",
DeviceId = "FOREIGN-DEVICE-001"
})).ThrowIfError();
var data = new CentronConnectionCreateHelpdeskRequestDTO
{
ShortDescription = "Test-Short-Description",
Description = "Test-Description",
PriorityI3D = 5,
StateI3D = 1,
HelpdeskTypeI3D = 3,
MainCategoryI3D = 5,
SubCategory1I3D = 20,
SubCategory2I3D = 23,
CustomerI3D = _riverbirdCustomerReference,
AssignDefaultDepartment = true,
AddToGeneralAgreementContract = true,
EditorI3Ds = new List<int> { 34 },
DefaultState = false,
AccountDeviceIDs = new List<string> { "OWN-DEVICE-001", "FOREIGN-DEVICE-001" },
};
var ticketI3D = this.WithSession(s => s.GetBL<RiverDivoBL>().CreateHelpdeskRequest(data, true));
var linkedDevices = this.WithSession(s => s.GetBL<AccountDeviceWebServiceBL>().SearchAccountDevices(new GetAccountDeviceFilter { TicketI3D = ticketI3D })).ThrowIfError();
Assert.Contains(linkedDevices, d => d.I3D == ownDevice.I3D);
Assert.DoesNotContain(linkedDevices, d => d.I3D == foreignDevice.I3D);
}
private void TestValidateRmmAccessKey()
{
// Without configured settings every access key is invalid.
Assert.False(this.WithSession(s => s.GetBL<RiverDivoBL>().ValidateRmmAccessKey("test-access-key")));
// Activate the RMM interface and configure an access key.
this.WithSession(s => s.GetBL<RmmConnectionSettingsWebServiceBL>().UpdateRmmConnectionSettings(new RmmConnectionSettingsDTO
{
IsEnabled = true,
AccessKey = "test-access-key"
}, this.GetLoggedInUser())).ThrowIfError();
Assert.True(this.WithSession(s => s.GetBL<RiverDivoBL>().ValidateRmmAccessKey("test-access-key")));
Assert.False(this.WithSession(s => s.GetBL<RiverDivoBL>().ValidateRmmAccessKey("wrong-access-key")));
Assert.False(this.WithSession(s => s.GetBL<RiverDivoBL>().ValidateRmmAccessKey(null)));
// The combined check of the legacy RiverDivo endpoints accepts a valid RMM access key.
Assert.True(this.WithSession(s => s.GetBL<RiverDivoBL>().ValidateRiverTicketOrRmmAccessKey("test-access-key")));
// Deactivated RMM interface: access key is no longer accepted.
this.WithSession(s => s.GetBL<RmmConnectionSettingsWebServiceBL>().UpdateRmmConnectionSettings(new RmmConnectionSettingsDTO
{
IsEnabled = false,
AccessKey = "test-access-key"
}, this.GetLoggedInUser())).ThrowIfError();
Assert.False(this.WithSession(s => s.GetBL<RiverDivoBL>().ValidateRmmAccessKey("test-access-key")));
}
}