using System; using System.IO; using Centron.BusinessLogic.WebServices.Administration.FileManagement; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.MailDocuments; public class MailDocumentTests : EndToEndTest { public MailDocumentTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public const int DirectoryI3D = 61; [SkipOnLinuxFact] public override void Execute() { RunTest("msg"); RunTest("eml"); } private void RunTest(string format) { var documentI3D = this.CreateTestMailDocument(format); var emailResult = this.WithSession(s => s.GetBL().GetMailDocument(this.GetLoggedInUser(), documentI3D)); Assert.Equal(ResultStatus.Success, emailResult.Status); var email = emailResult.Data; this.Verifier.Verify($"Email-{format}", email); var attachment = this.WithSession(s => s.GetBL().GetMailDocumentAttachment(documentI3D, email.Attachments[0].FileName)); Assert.NotNull(attachment); Assert.NotEmpty(attachment); Assert.Equal(email.Attachments[0].FileSize, attachment.Length); } private int CreateTestMailDocument(string format) { var testFileName = $"Mail.{format}"; var testFileData = this.GetTestEmail(format); var document = this.WithSession(s => s.GetBL().AddDocumentToDirectory( this.GetLoggedInUser(), DirectoryI3D, testFileData, testFileName)); return document.I3D; } private byte[] GetTestEmail(string format) { using var stream = this.GetType().Assembly.GetManifestResourceStream(this.GetType(), $"Test-Mail.{format}"); using var memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return memoryStream.ToArray(); } }