using System; using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Sales.Support; using Centron.BusinessLogic.ToDoArea; using Centron.BusinessLogic.WebServices.Sales.Support; using Centron.BusinessLogic.WebServices.ToDoArea; using Centron.BusinessLogic.WebServices.Warehousing; using Centron.Data.Entities.Administration; using Centron.Data.Entities.Administration.Logins; using Centron.Data.Entities.Sales.Support; using Centron.Data.Entities.Ticketing; using Centron.Data.Entities.ToDoArea; using Centron.Data.WebServices.Sales.Support; using Centron.Interfaces; using Centron.Interfaces.Sales.Helpdesks; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.ToDoArea; using CentronSoftware.Centron.WebServices.Entities.Warehousing; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Helpdesk { public class HelpdeskTests : EndToEndTest { private readonly int _referenceCustomerI3D = 10000; private readonly int _referenceHelpdeskI3D = 10491; private int _referenceArticleWorkItemI3D; public HelpdeskTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Verifier.Settings.IgnoreProperties(f => f.ChangedVersion, f => f.CreatedVersion); } public override void Execute() { this.PrepareDatabase(); this.GetHelpdesksThroughPaging(); this.GetHelpdesk(); this.GetHelpdeskHistory(); this.NewTicket(); this.UpdateHelpdesk(); this.ClosedTicket(); this.SaveAction(); this.ShowOnlyOwn(); this.GetConnectionNumberGroups(); this.GetNextConnectionNumber(); this.UpdateHelpdeskConectionNumbers(); this.NewTicketWithChangedTicketDefaultContact(); } private void PrepareDatabase() { using (var session = new BLSession()) { this._referenceArticleWorkItemI3D = session.GetBL().SaveArticleWorkItem(new ArticleWorkItemDTO { Caption = "Charlotte de Witte ‘New Form’ III: Rave On Time" }, this.GetLoggedInUser()).Data.I3D; } this.Sql($"UPDATE hlpdsk_requests SET ArticleWorkItemI3D = {this._referenceArticleWorkItemI3D} WHERE I3D = {this._referenceHelpdeskI3D}"); } private void GetConnectionNumberGroups() { using (var session = new BLSession()) { var groups = session.GetBL().GetHelpdeskConnectionNumberGroups(new HelpdeskConnectionNumberGroupFilter()); this.Verifier.Verify("HelpdeskConnectionNumberGroups", groups); } } private void GetNextConnectionNumber() { using (var session = new BLSession()) { var number = session.GetBL().GetNextHelpdeskConnectionNumber(); this.Verifier.Verify("NextHelpdeskConnectionNumber", number); } } private void UpdateHelpdeskConectionNumbers() { HelpdeskDTO helpdesk = null; using (var session = new BLSession()) { helpdesk = (session.GetBL().GetHelpdeskByI3D(this._referenceHelpdeskI3D, this.GetLoggedInUser())).Data; session.GetBL().UpdateConnectionNumberForHelpdesks(new List() { this._referenceHelpdeskI3D }, 2, this.GetLoggedInUser()); } using (var session = new BLSession()) { var helpdeskAfterUpdate = session.GetBL().GetHelpdeskByI3D(this._referenceHelpdeskI3D, this.GetLoggedInUser()); Assert.True(helpdesk.ConnectionNumber != helpdeskAfterUpdate.Data.ConnectionNumber); } } private void GetHelpdesksThroughPaging() { using (var session = new BLSession()) { VerifyGetHelpdesksThroughPaging("Helpdesks", new HelpdeskFilter()); VerifyGetHelpdesksThroughPaging("HelpdesksByCustomer", new HelpdeskFilter { CustomerI3D = this._referenceCustomerI3D }); VerifyGetHelpdesksThroughPaging("HelpdesksByCreatedBy", new HelpdeskFilter { CreatedDateStart = new DateTime(2017, 10, 22), CreatedDateEnd = new DateTime(2017, 10, 23) }); VerifyGetHelpdesksThroughPaging("HelpdesksByDueDate", new HelpdeskFilter { DueDateStart = new DateTime(2017, 10, 20), DueDateEnd = new DateTime(2017, 10, 23) }); VerifyGetHelpdesksThroughPaging("HelpdesksByOnlyOwn", new HelpdeskFilter { OnlyOwn = true }); VerifyGetHelpdesksThroughPaging("HelpdesksByOnlyActive", new HelpdeskFilter { OnlyActive = true }); VerifyGetHelpdesksThroughPaging("AllEditors", new HelpdeskFilter { AllEditorI3Ds = [22, 23], }); void VerifyGetHelpdesksThroughPaging(string name, HelpdeskFilter filter) { var result = session.GetBL().GetHelpdesksThroughPaging( filter, HelpdeskSort.Number, false, 1, int.MaxValue, this.GetLoggedInUser()); this.Verifier.Verify(name, result); } } } private void GetHelpdesk() { using (var session = new BLSession()) { var ticket = session.GetBL().GetTicket(this.GetLoggedInUser(), this._referenceHelpdeskI3D); this.Verifier.Verify("Helpdesk", ticket); } } private void GetHelpdeskHistory() { using (var session = new BLSession()) { var helpdeskHistory = session.GetBL().GetHelpdeskHistory(this._referenceHelpdeskI3D, this.GetLoggedInUser()); this.Verifier.Verify("HelpdeskHistory", helpdeskHistory); } } private void NewTicket() { using (var session = new BLSession()) { var newHelpdesk = session.GetBL().GetNewTicketFromCustomer(this.GetLoggedInUser().User, this._referenceCustomerI3D); this.Verifier.Verify("NewHelpdesk", newHelpdesk); } } private void NewTicketWithChangedTicketDefaultContact() { //make Markus Fischer the default contact person for tickets this.Sql("UPDATE AccountAddressContacts SET DefaultTicket = 1 WHERE I3D = 3"); var newHelpdesk = this.WithSession(f => f.GetBL().GetNewTicketFromCustomer(this.GetLoggedInUser().User, this._referenceCustomerI3D)); this.Verifier.Verify("NewHelpdesk_with_TicketDefault_Contact", newHelpdesk); } private void ClosedTicket() { using (var session = new BLSession()) { var newHelpdesk = session.GetBL().CloseHelpdesk(this.GetLoggedInUser().User, this._referenceHelpdeskI3D); this.Verifier.Verify("ClosedHelpdesk", newHelpdesk); var todoEntries = session.GetBL().SearchTodoList( base.GetLoggedInUser().User, ToDoSort.Number, false, new ToDoFilter() { ObjectKinds = new List { (int)CentronObjectKindNumeric.HelpdeskClass }, ObjectI3Ds = new List() { this._referenceHelpdeskI3D } }); this.Verifier.Verify("ClosedHelpdesk_CheckTodoEntries", todoEntries.OrderBy(o => o.I3D).ToList()); } } private void UpdateHelpdesk() { using (var session = new BLSession()) { var todoEntries = session.GetBL().SearchTodoList( base.GetLoggedInUser().User, ToDoSort.Number, false, new ToDoFilter() { ObjectKinds = new List { (int)CentronObjectKindNumeric.HelpdeskClass }, ObjectI3Ds = new List() { this._referenceHelpdeskI3D } }); this.Verifier.Verify("UpdatedHelpdesk_CheckTodoEntriesBeforeUpdate", todoEntries.OrderBy(o => o.I3D).ToList()); } var oldHelpdesk = this.GetHelpdeskInternal(); oldHelpdesk.ShortDescription = "new short description"; oldHelpdesk.Description = "new description"; oldHelpdesk.InternalNote = "new internal note"; oldHelpdesk.CustomerI3D = this._referenceCustomerI3D; oldHelpdesk.ArticleWorkItemI3D = this._referenceArticleWorkItemI3D; using (var session = new BLSession()) session.GetBL().SaveHelpdesk(oldHelpdesk, this.GetLoggedInUser()); var newHelpdesk = this.GetHelpdeskInternal(); this.Verifier.Verify("UpdatedHelpdesk", newHelpdesk); using (var session = new BLSession()) { var todoEntries = session.GetBL().SearchTodoList( base.GetLoggedInUser().User, ToDoSort.Number, false, new ToDoFilter() { ObjectKinds = new List { (int)CentronObjectKindNumeric.HelpdeskClass }, ObjectI3Ds = new List() { newHelpdesk.I3D } }); this.Verifier.Verify("UpdatedHelpdesk_CheckTodoEntries", todoEntries.OrderBy(o => o.I3D).ToList()); } } private HelpdeskDTO GetHelpdeskInternal() { using (var session = new BLSession()) return session.GetBL().GetHelpdeskByI3D(this._referenceHelpdeskI3D, this.GetLoggedInUser()).Data; } private void SaveAction() { int actionI3D; using (var session = new BLSession()) { var result = session.GetBL().SaveHelpdeskAction(this.GetLoggedInUser(), "I am the caption", "I am the description", this._referenceHelpdeskI3D); actionI3D = result.Data; } using (var session = new BLSession()) { var helpdeskHistory = session.GetBL().GetHelpdeskHistory(this._referenceHelpdeskI3D, this.GetLoggedInUser()); this.Verifier.Verify("HistoryEntry", helpdeskHistory.First(f => f.I3D == actionI3D)); } } private void ShowOnlyOwn() { using (var session = new BLSession()) { var helpdeskBL = session.GetBL(); var result = helpdeskBL.GetLoggedInUserShowHelpdeskRight(this.GetLoggedInUser()); Assert.Equal(ShowHelpdeskRight.All, result); var user2 = new LoggedInUser(new AppUser(), new Ticket { WebAccount = new WebAccount { I3D = 1 }, WebAccountI3D = 1 }); var resultWebAccount = helpdeskBL.GetLoggedInUserShowHelpdeskRight(user2); Assert.Equal(ShowHelpdeskRight.All, resultWebAccount); } } } }