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
301 lines
12 KiB
C#
301 lines
12 KiB
C#
using Centron.BusinessLogic;
|
|
using Centron.BusinessLogic.Accounts;
|
|
using Centron.BusinessLogic.Administration.Company;
|
|
using Centron.BusinessLogic.EmployeeArea;
|
|
using Centron.BusinessLogic.WebServices.Administration.Company;
|
|
using Centron.BusinessLogic.WebServices.Mail.Templates;
|
|
using Centron.Data.Entities.Administration.Logins;
|
|
using Centron.Data.WebServices.BranchArea;
|
|
using Centron.Data.WebServices.Mail.Templates;
|
|
using Centron.Interfaces;
|
|
using Centron.Interfaces.BL;
|
|
using Centron.Interfaces.Mail.Templates;
|
|
using Centron.Tests.EndToEnd.Infrastructure;
|
|
using CentronSoftware.Centron.WebServices.Entities.Administration.FileManagement;
|
|
using CentronSoftware.Centron.WebServices.Entities.Mail.Templates;
|
|
using DevExpress.XtraRichEdit;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Centron.Tests.EndToEnd.Tests.MailTemplates
|
|
{
|
|
public class MailTemplatesTest : EndToEndTest
|
|
{
|
|
private LoggedInUser GetUser(BLSession session) => new LoggedInUser(session.GetBL<AppUserBL>().GetAppUser(f => f.I3D == 11));
|
|
|
|
public MailTemplatesTest(ITestOutputHelper testOutputHelper)
|
|
: base(testOutputHelper)
|
|
{
|
|
}
|
|
|
|
public override void Execute()
|
|
{
|
|
var user = this.GetLoggeInUser();
|
|
var branches = this.GetBranches();
|
|
var branchI3D = branches.FirstOrDefault().I3D;
|
|
var accountI3D = 1;
|
|
|
|
var mailTemplateReference = this.GetMailTemplateReference();
|
|
|
|
this.GetMailTemplate("Default", mailTemplateReference, branchI3D, accountI3D, user);
|
|
this.AddInactiveMailTemplate(mailTemplateReference);
|
|
this.GetMailTemplate("Inactive", mailTemplateReference, branchI3D, accountI3D, user);
|
|
this.AddGlobalMailTemplate(mailTemplateReference);
|
|
this.GetMailTemplate("Global", mailTemplateReference, branchI3D, accountI3D, user);
|
|
this.AddBranchMailTemplate(mailTemplateReference, branchI3D);
|
|
this.GetMailTemplate("Branch", mailTemplateReference, branchI3D, accountI3D, user);
|
|
this.AddPersonalMailTemplate(mailTemplateReference, user);
|
|
this.GetMailTemplate("Personal", mailTemplateReference, branchI3D, accountI3D, user);
|
|
this.AddCustomerMailTemplate(mailTemplateReference, accountI3D);
|
|
this.GetMailTemplate("Account", mailTemplateReference, branchI3D, accountI3D, user);
|
|
|
|
this.SaveMailTemplateAttachments();
|
|
this.GetMailTemplateWithAttachments();
|
|
}
|
|
|
|
private void GetMailTemplate(string testName, MailTemplateReference mailTemplateReference, int? branchI3D, int? accountI3D, LoggedInUser user)
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var mailTemplate = session.GetBL<MailTemplateWebServiceBL>().GetMailTemplate(
|
|
user,
|
|
mailTemplateReference.ObjectKind,
|
|
mailTemplateReference.SubObjectKind,
|
|
mailTemplateReference.ObjectI3D,
|
|
branchI3D,
|
|
accountI3D,
|
|
null,
|
|
null);
|
|
|
|
this.Verifier.Verify($"{testName}_MailTemplate", mailTemplate);
|
|
}
|
|
}
|
|
|
|
private LoggedInUser GetLoggeInUser()
|
|
{
|
|
using(var session = new BLSession())
|
|
{
|
|
return this.GetUser(session);
|
|
}
|
|
}
|
|
|
|
private List<BranchPreviewDTO> GetBranches()
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var user = this.GetUser(session);
|
|
|
|
var branches = session.GetBL<BranchWebServiceBL>().GetBranchList(new BranchFilter
|
|
{
|
|
Status = 1,
|
|
IncludeHeadquarter = false
|
|
}, user)
|
|
.ThrowIfError()
|
|
.ToList();
|
|
|
|
return branches;
|
|
}
|
|
}
|
|
|
|
private MailTemplateReference GetMailTemplateReference()
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
return MailTemplateReferences.TryFindMailTemplateReference(CentronObjectKindNumeric.DocumentSigning, 31, null);
|
|
}
|
|
}
|
|
|
|
private void AddGlobalMailTemplate(MailTemplateReference mailTemplateReference)
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var user = this.GetUser(session);
|
|
|
|
session.GetBL<MailTemplateWebServiceBL>().SaveOrUpdateMailTemplate(user, new MailTemplateDTO
|
|
{
|
|
IsActive = true,
|
|
Body = this.GetRichText(mailTemplateReference.DefaultBody),
|
|
Subject = $"GLOBAL TEMPLATE",
|
|
ObjectKind = (int)mailTemplateReference.ObjectKind,
|
|
SubObjectKind = mailTemplateReference.SubObjectKind,
|
|
ObjectI3D = mailTemplateReference.ObjectI3D,
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddBranchMailTemplate(MailTemplateReference mailTemplateReference, int branchI3D)
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var user = this.GetUser(session);
|
|
|
|
session.GetBL<MailTemplateWebServiceBL>().SaveOrUpdateMailTemplate(user, new MailTemplateDTO
|
|
{
|
|
IsActive = true,
|
|
Body = this.GetRichText(mailTemplateReference.DefaultBody),
|
|
Subject = $"BRANCH TEMPLATE",
|
|
ObjectKind = (int)mailTemplateReference.ObjectKind,
|
|
SubObjectKind = mailTemplateReference.SubObjectKind,
|
|
ObjectI3D = mailTemplateReference.ObjectI3D,
|
|
BranchI3D = branchI3D
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddPersonalMailTemplate(MailTemplateReference mailTemplateReference, LoggedInUser user)
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
session.GetBL<MailTemplateWebServiceBL>().SaveOrUpdateMailTemplate(user, new MailTemplateDTO
|
|
{
|
|
IsActive = true,
|
|
Body = this.GetRichText(mailTemplateReference.DefaultBody),
|
|
Subject = $"PERSONAL TEMPLATE",
|
|
ObjectKind = (int)mailTemplateReference.ObjectKind,
|
|
SubObjectKind = mailTemplateReference.SubObjectKind,
|
|
ObjectI3D = mailTemplateReference.ObjectI3D,
|
|
IsPersonalMailTemplate = true
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddCustomerMailTemplate(MailTemplateReference mailTemplateReference, int accountI3D)
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var user = this.GetUser(session);
|
|
|
|
session.GetBL<MailTemplateWebServiceBL>().SaveOrUpdateMailTemplate(user, new MailTemplateDTO
|
|
{
|
|
IsActive = true,
|
|
Body = this.GetRichText(mailTemplateReference.DefaultBody),
|
|
Subject = $"ACCOUNT TEMPLATE",
|
|
ObjectKind = (int)mailTemplateReference.ObjectKind,
|
|
SubObjectKind = mailTemplateReference.SubObjectKind,
|
|
ObjectI3D = mailTemplateReference.ObjectI3D,
|
|
AccountI3D = accountI3D
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AddInactiveMailTemplate(MailTemplateReference mailTemplateReference)
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var user = this.GetUser(session);
|
|
|
|
session.GetBL<MailTemplateWebServiceBL>().SaveOrUpdateMailTemplate(user, new MailTemplateDTO
|
|
{
|
|
IsActive = false,
|
|
Body = this.GetRichText(mailTemplateReference.DefaultBody),
|
|
Subject = $"INACTIVE GLOBAL TEMPLATE",
|
|
ObjectKind = (int)mailTemplateReference.ObjectKind,
|
|
SubObjectKind = mailTemplateReference.SubObjectKind,
|
|
ObjectI3D = mailTemplateReference.ObjectI3D,
|
|
});
|
|
}
|
|
}
|
|
|
|
private string GetRichText(string text)
|
|
{
|
|
if (text == null)
|
|
return null;
|
|
|
|
if (text.TrimStart().StartsWith(@"{\rtf1", StringComparison.Ordinal) == false)
|
|
{
|
|
using (var richEditServer = new RichEditDocumentServer())
|
|
{
|
|
richEditServer.Options.Export.Rtf.ExportTheme = false;
|
|
richEditServer.Text = text;
|
|
return richEditServer.RtfText;
|
|
}
|
|
}
|
|
return text;
|
|
}
|
|
|
|
private void SaveMailTemplateAttachments()
|
|
{
|
|
using var session = new BLSession();
|
|
|
|
var loggedInUser = this.GetLoggedInUser();
|
|
var file = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
|
|
|
|
session.GetBL<MailTemplateWebServiceBL>().SaveAllMailtemplateAttachments(
|
|
new List<MailTemplateAttachmentDTO>
|
|
{
|
|
new MailTemplateAttachmentDTO
|
|
{
|
|
ObjectKind = CentronObjectKindNumeric.PLM,
|
|
SubObjectKind = null,
|
|
ObjectI3D = 1,
|
|
Name = "Test.png",
|
|
FileType = DocumentType.PDF,
|
|
FileData = file,
|
|
FileSize = file.Length,
|
|
BranchI3D = null,
|
|
AccountI3D = null,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedByI3D = loggedInUser.User.Employee.I3D,
|
|
},
|
|
new MailTemplateAttachmentDTO
|
|
{
|
|
ObjectKind = CentronObjectKindNumeric.PLM,
|
|
SubObjectKind = null,
|
|
ObjectI3D = 2,
|
|
Name = "Test1.png",
|
|
FileType = DocumentType.PDF,
|
|
FileData = file,
|
|
FileSize = file.Length,
|
|
BranchI3D = null,
|
|
AccountI3D = null,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedByI3D = loggedInUser.User.Employee.I3D,
|
|
},
|
|
new MailTemplateAttachmentDTO
|
|
{
|
|
ObjectKind = CentronObjectKindNumeric.PLM,
|
|
SubObjectKind = null,
|
|
ObjectI3D = 1,
|
|
Name = "Test2.png",
|
|
FileType = DocumentType.PDF,
|
|
FileData = file,
|
|
FileSize = file.Length,
|
|
BranchI3D = null,
|
|
AccountI3D = null,
|
|
CreatedAt = DateTime.Now,
|
|
CreatedByI3D = loggedInUser.User.Employee.I3D,
|
|
IsGlobal = true
|
|
},
|
|
},
|
|
this.GetLoggedInUser());
|
|
}
|
|
|
|
private void GetMailTemplateWithAttachments()
|
|
{
|
|
using (var session = new BLSession())
|
|
{
|
|
var result = session.GetBL<MailTemplateWebServiceBL>().GetMailTemplateWithAttachments(
|
|
this.GetLoggedInUser(),
|
|
objectKind: CentronObjectKindNumeric.PLM,
|
|
subObjectKind: null,
|
|
objectI3D: 1,
|
|
branchI3D: null,
|
|
accountI3D: null,
|
|
customerI3D: null,
|
|
supplierI3D: null,
|
|
employeeI3D: null,
|
|
includeGlobal: true);
|
|
|
|
Assert.NotNull(result);
|
|
|
|
this.Verifier.Verify("MailTemplateWithAttachments", result);
|
|
}
|
|
}
|
|
}
|
|
}
|