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 { 34 }, DefaultState = false, Files = new List { new() { FileName = _helpdeskAttachmentFileName, FileContent = _helpdeskAttachmentFileContent, }, }, }; var ticketI3D = this.WithSession(s => s.GetBL().CreateHelpdeskRequest(data, true)); var ticket = this.WithSession(s => s.GetBL().GetHelpdeskByI3D(ticketI3D, this.GetLoggedInUser())).ThrowIfError(); var rootDirectory = this.WithSession(s => s.GetBL().GetDirectoryReference(ticketI3D, CentronObjectKindNumeric.HelpdeskClass, DirectoryReferenceKind.RootDirI3D)); Assert.NotNull(rootDirectory); var documents = this.WithSession(s => s.GetBL() .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() .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() .SaveAccountDevice(this.GetLoggedInUser(), new AccountDeviceDTO { AccountI3D = 5, ShortName = "Own-Device", DeviceId = "OWN-DEVICE-001" })).ThrowIfError(); var foreignDevice = this.WithSession(s => s.GetBL() .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 { 34 }, DefaultState = false, AccountDeviceIDs = new List { "OWN-DEVICE-001", "FOREIGN-DEVICE-001" }, }; var ticketI3D = this.WithSession(s => s.GetBL().CreateHelpdeskRequest(data, true)); var linkedDevices = this.WithSession(s => s.GetBL().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().ValidateRmmAccessKey("test-access-key"))); // Activate the RMM interface and configure an access key. this.WithSession(s => s.GetBL().UpdateRmmConnectionSettings(new RmmConnectionSettingsDTO { IsEnabled = true, AccessKey = "test-access-key" }, this.GetLoggedInUser())).ThrowIfError(); Assert.True(this.WithSession(s => s.GetBL().ValidateRmmAccessKey("test-access-key"))); Assert.False(this.WithSession(s => s.GetBL().ValidateRmmAccessKey("wrong-access-key"))); Assert.False(this.WithSession(s => s.GetBL().ValidateRmmAccessKey(null))); // The combined check of the legacy RiverDivo endpoints accepts a valid RMM access key. Assert.True(this.WithSession(s => s.GetBL().ValidateRiverTicketOrRmmAccessKey("test-access-key"))); // Deactivated RMM interface: access key is no longer accepted. this.WithSession(s => s.GetBL().UpdateRmmConnectionSettings(new RmmConnectionSettingsDTO { IsEnabled = false, AccessKey = "test-access-key" }, this.GetLoggedInUser())).ThrowIfError(); Assert.False(this.WithSession(s => s.GetBL().ValidateRmmAccessKey("test-access-key"))); } }