using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.Settings; using Centron.BusinessLogic.WebServices.Administration.Settings.SettingGroups; using Centron.BusinessLogic.WebServices.Sales.Support; using Centron.Data.Entities.Administration.Settings.SettingGroups; using Centron.Data.WebServices.Mail; using Centron.Tests.EndToEnd.Infrastructure; using System.Collections.Generic; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Helpdesk { public class HelpdeskSettingsTests : EndToEndTest { private readonly int _referenceHelpdeskI3D = 10491; public HelpdeskSettingsTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.CleanupProperty(f => f.Text, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskClosingExternalEmailBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskClosingInternalEmailBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskEMailForCustomerBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskEMailForEditorBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskEMailForOthersBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskForwardingExternalEmailBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.HelpdeskForwardingInternalEmailBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.NewTicketMailBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); this.Verifier.Settings.CleanupProperty(f => f.OperationReportBodyRTF, RegexHelper.RtfInfo, "{\\info{\\author John Doe}"); } public override void Execute() { this.GetUnchangedSettings(); this.GetSettingsWithEmailContent("MailSettings", "ForwardSettings", "CloseSettings"); this.ResetFormattingSettings(); this.GetSettingsWithEmailContent("UnformattedMailSettings", "UnformattedForwardSettings", "UnformattedCloseSettings"); this.UpdatePrefixSettings("", ""); this.GetSettingsWithEmailContent("NoPrefixUnformattedMailSettings", "NoPrefixUnformattedForwardSettings", "NoPrefixUnformattedCloseSettings"); this.UpdatePrefixSettings("emailPrefix", "globalPrefix"); this.GetSettingsWithEmailContent("BothPrefixesUnformattedMailSettings", "BothPrefixesUnformattedForwardSettings", "BothPrefixesUnformattedCloseSettings"); this.UpdatePrefixSettings("", "globalPrefix"); this.GetSettingsWithEmailContent("GlobalPrefixOnlyUnformattedMailSettings", "GlobalPrefixOnlyUnformattedForwardSettings", "GlobalPrefixOnlyUnformattedCloseSettings"); this.UpdatePrefixSettings("emailPrefix", ""); this.GetSettingsWithEmailContent("EmailPrefixOnlyUnformattedMailSettings", "EmailPrefixOnlyUnformattedForwardSettings", "EmailPrefixOnlyUnformattedCloseSettings"); } private void GetUnchangedSettings() { using (var session = new BLSession()) { var states = session.GetBL().GetHelpdesksStates(); this.Verifier.Verify("HelpdeskStates", states); } using (var session = new BLSession()) { var priorities = session.GetBL().GetActiveHelpdeskPriorities(); this.Verifier.Verify("HelpdeskPriorities", priorities); } using (var session = new BLSession()) { var types = session.GetBL().GetHelpdeskTypes(null); this.Verifier.Verify("HelpdeskTypes", types); } using (var session = new BLSession()) { var categories = session.GetBL().GetActiveHelpdeskCategories(); this.Verifier.Verify("HelpdeskCategories", categories); } using (var session = new BLSession()) { var timerTypes = session.GetBL().GetHelpdeskTimerTypes(); this.Verifier.Verify("HelpdeskTimerTypes", timerTypes); } using (var session = new BLSession()) { var helpdeskSettings = session.GetBL().GetHelpdeskSettings(); this.Verifier.Verify("HelpdeskSettings", helpdeskSettings); } } private void GetSettingsWithEmailContent(string mailSettingsName, string forwardSettingsName, string closeSettingsName) { using (var session = new BLSession()) { var mailSettings = session.GetBL().GetHelpdeskMailSettings(this._referenceHelpdeskI3D, this.GetLoggedInUser()); this.Verifier.Verify(mailSettingsName, mailSettings); } using (var session = new BLSession()) { var forwardSettings = session.GetBL().GetForwardTicketEmailSettings(this._referenceHelpdeskI3D, this.GetLoggedInUser()); this.Verifier.Verify(forwardSettingsName, forwardSettings); } using (var session = new BLSession()) { var closeSettings = session.GetBL().GetCloseHelpdeskEmailSettings(this._referenceHelpdeskI3D, this.GetLoggedInUser()); this.Verifier.Verify(closeSettingsName, closeSettings); } } private void ResetFormattingSettings() { // there are mailtemplates that got converted from the old settings // we simply delete them so we get the default texts for everything again this.Sql("DELETE FROM MailVorlagen WHERE ObjectKind = 10"); } private void UpdatePrefixSettings(string emailSubjectPrefix, string globalPrefx) { using (var session = new BLSession()) { var updateSettings = session.GetBL().GetSettingsForUpdate ( AppSettingsConst.HelpdeskEmailSubjectPrefix, AppSettingsConst.GlobalEmailPrefix ); updateSettings.UpdateString(AppSettingsConst.HelpdeskEmailSubjectPrefix, valueText: emailSubjectPrefix); updateSettings.UpdateString(AppSettingsConst.GlobalEmailPrefix, valueText: globalPrefx); updateSettings.SaveSettings(); } } } }