using Centron.BusinessLogic; using Centron.BusinessLogic.WebServices.Mail.Templates; using Centron.Interfaces; 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 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.MailTemplateAttachments { public class MailTemplateAttachmentsTest : EndToEndTest { public MailTemplateAttachmentsTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } private byte[] _file = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; public override void Execute() { this.SaveMailTemplateAttachment(); this.SaveMailTemplateAttachments(); this.GetMailTemplateAttachments(); this.UpdateMailTemplateAttachment(); this.GetGlobalMailTemplateAttachments(); this.DeleteMailTemplateAttachments(); } private void SaveMailTemplateAttachment() { using var session = new BLSession(); var loggedInUser = this.GetLoggedInUser(); var attachment = session.GetBL().SaveMailTemplateAttachment( 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, }, this.GetLoggedInUser()).Data; Assert.NotNull(attachment); } private void SaveMailTemplateAttachments() { using var session = new BLSession(); var loggedInUser = this.GetLoggedInUser(); session.GetBL().SaveAllMailtemplateAttachments( new List { 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, }, }, this.GetLoggedInUser()); } private void GetMailTemplateAttachments() { using var session = new BLSession(); var attachments = session.GetBL().GetMailTemplateAttachments( this.GetLoggedInUser(), objectKind: CentronObjectKindNumeric.PLM, subObjectKind: null, objectI3D: 1, branchI3D: null, accountI3D: null, customerI3D: null, supplierI3D: null, employeeI3D: null).Data; Assert.NotEmpty(attachments); this.Verifier.Verify("GetMailTemplateAttachments", attachments); } private void UpdateMailTemplateAttachment() { using var session = new BLSession(); var attachment = session.GetBL().GetMailTemplateAttachment(1).Data; Assert.NotNull(attachment); attachment.IsGlobal = true; var updatedAttachment = session.GetBL().SaveMailTemplateAttachment(attachment, this.GetLoggedInUser()); Assert.NotNull(updatedAttachment); } private void GetGlobalMailTemplateAttachments() { using var session = new BLSession(); var attachments = session.GetBL().GetGlobalMailTemplateAttachments().Data; Assert.NotEmpty(attachments); } private void DeleteMailTemplateAttachments() { using var session = new BLSession(); var attachment = session.GetBL().GetMailTemplateAttachment(1).Data; Assert.NotNull(attachment); session.GetBL().DeleteMailTemplateAttachments(new List { attachment }); attachment = session.GetBL().GetMailTemplateAttachment(1).Data; Assert.Null(attachment); } } }