protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { _blobStorageMock = new Mock <IBlobStorage>(); _uri = new Uri("http://whatever/file.txt"); _attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { BlobContainer = BlobContainer }; _attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); using var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); _testDataSet = AddTestDataSet(context); var tag = _testDataSet.Project1.Tags.First(); _attachment = new TagAttachment(TestPlant, Guid.NewGuid(), "FileA"); tag.AddAttachment(_attachment); context.SaveChangesAsync().Wait(); _tagId = tag.Id; _attachmentId = _attachment.Id; var fullBlobPath = _attachment.GetFullBlobPath(BlobContainer); _blobStorageMock .Setup(b => b.GetDownloadSasUri(fullBlobPath, It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns(_uri); }
public ISendEmailCommand AddAttachments(Action <IAttachmentOption> option) { if (AttachmentOptions == null) { AttachmentOptions = new List <AttachmentOption>(); } AttachmentOptions.Add(OptionProcessor.Process <IAttachmentOption, AttachmentOption>(option)); return(this); }
protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { using var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider); _uri = new Uri("http://whatever/file.txt"); _attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { BlobContainer = BlobContainer }; _attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); var journey = AddJourneyWithStep(context, "J1", "S", AddMode(context, "M1", false), AddResponsible(context, "R1")); var reqDef = AddRequirementTypeWith1DefWithoutField(context, "T1", "D1", RequirementTypeIcon.Other).RequirementDefinitions.Single(); var attachmentField = new Field(TestPlant, "Label", FieldType.Attachment, 0); reqDef.AddField(attachmentField); context.SaveChangesAsync().Wait(); var requirement = new TagRequirement(TestPlant, 2, reqDef); var tag = new Tag(TestPlant, TagType.Standard, "TagNo", "Description", journey.Steps.ElementAt(0), new List <TagRequirement> { requirement }); context.Tags.Add(tag); tag.StartPreservation(); context.SaveChangesAsync().Wait(); _tagId = tag.Id; _requirementId = requirement.Id; _attachmentFieldId = attachmentField.Id; var fieldValueAttachment = new FieldValueAttachment(TestPlant, Guid.Empty, "FilA.txt"); requirement.RecordAttachment(fieldValueAttachment, _attachmentFieldId, reqDef); context.SaveChangesAsync().Wait(); var fullBlobPath = fieldValueAttachment.GetFullBlobPath(BlobContainer); _blobStorageMock = new Mock <IBlobStorage>(); _blobStorageMock .Setup(b => b.GetDownloadSasUri(fullBlobPath, It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns(_uri); }
public void Setup() { var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); _options = new AttachmentOptions { MaxSizeMb = 2, BlobContainer = "bc", ValidFileSuffixes = new[] { ".gif", ".jpg" } }; attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(_options); _dut = new UploadAttachmentForceOverwriteDtoValidator(attachmentOptionsMock.Object); }
public void Setup() { _command = new DeleteTagAttachmentCommand(1, 3, _rowVersion); _projectRepositoryMock = new Mock <IProjectRepository>(); _blobStorageMock = new Mock <IBlobStorage>(); var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { MaxSizeMb = 2, BlobContainer = BlobContainer, ValidFileSuffixes = new[] { ".gif", ".jpg" } }; attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); var stepMock = new Mock <Step>(); stepMock.SetupGet(s => s.Plant).Returns(TestPlant); var reqMock = new Mock <TagRequirement>(); reqMock.SetupGet(s => s.Plant).Returns(TestPlant); _tag = new Tag(TestPlant, TagType.Standard, "", "", stepMock.Object, new List <TagRequirement> { reqMock.Object }); var attachment = new TagAttachment(TestPlant, Guid.Empty, "Fil.txt"); attachment.SetProtectedIdForTesting(_command.AttachmentId); _tag.AddAttachment(attachment); _projectRepositoryMock .Setup(r => r.GetTagByTagIdAsync(_command.TagId)) .Returns(Task.FromResult(_tag)); _dut = new DeleteTagAttachmentCommandHandler( _projectRepositoryMock.Object, UnitOfWorkMock.Object, _blobStorageMock.Object, attachmentOptionsMock.Object); }
public void Setup() { _command = new DeleteActionAttachmentCommand(1, 2, 3, _rowVersion); _projectRepositoryMock = new Mock <IProjectRepository>(); _blobStorageMock = new Mock <IBlobStorage>(); var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { MaxSizeMb = 2, BlobContainer = BlobContainer, ValidFileSuffixes = new[] { ".gif", ".jpg" } }; attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); var tagMock = new Mock <Tag>(); tagMock.SetupGet(t => t.Plant).Returns(TestPlant); _action = new Action(TestPlant, "T", "D", null); _action.SetProtectedIdForTesting(_command.ActionId); tagMock.Object.AddAction(_action); var attachment = new ActionAttachment(TestPlant, Guid.Empty, "Fil.txt"); attachment.SetProtectedIdForTesting(_command.AttachmentId); _action.AddAttachment(attachment); _projectRepositoryMock .Setup(r => r.GetTagByTagIdAsync(_command.TagId)) .Returns(Task.FromResult(tagMock.Object)); _dut = new DeleteActionAttachmentCommandHandler( _projectRepositoryMock.Object, UnitOfWorkMock.Object, _blobStorageMock.Object, attachmentOptionsMock.Object); }
public void Setup() { _commandWithoutOverwrite = new UploadTagAttachmentCommand(_tagId, _fileName, false, new MemoryStream()); _projectRepositoryMock = new Mock <IProjectRepository>(); _blobStorageMock = new Mock <IBlobStorage>(); var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { MaxSizeMb = 2, BlobContainer = _blobContainer, ValidFileSuffixes = new[] { ".gif", ".jpg" } }; attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); var stepMock = new Mock <Step>(); stepMock.SetupGet(s => s.Plant).Returns(TestPlant); var reqMock = new Mock <TagRequirement>(); reqMock.SetupGet(s => s.Plant).Returns(TestPlant); _tag = new Tag(TestPlant, TagType.Standard, "", "", stepMock.Object, new List <TagRequirement> { reqMock.Object }); _projectRepositoryMock .Setup(r => r.GetTagByTagIdAsync(_commandWithoutOverwrite.TagId)) .Returns(Task.FromResult(_tag)); _dut = new UploadTagAttachmentCommandHandler( _projectRepositoryMock.Object, UnitOfWorkMock.Object, PlantProviderMock.Object, _blobStorageMock.Object, attachmentOptionsMock.Object); }
public void Setup() { _commandWithoutOverwrite = new UploadActionAttachmentCommand(_tagId, _actionId, _fileName, false, new MemoryStream()); _projectRepositoryMock = new Mock <IProjectRepository>(); _blobStorageMock = new Mock <IBlobStorage>(); var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { MaxSizeMb = 2, BlobContainer = _blobContainer, ValidFileSuffixes = new[] { ".gif", ".jpg" } }; attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); var tagMock = new Mock <Tag>(); tagMock.SetupGet(t => t.Plant).Returns(TestPlant); _action = new Action(TestPlant, "T", "D", null); _action.SetProtectedIdForTesting(_commandWithoutOverwrite.ActionId); tagMock.Object.AddAction(_action); _projectRepositoryMock .Setup(r => r.GetTagByTagIdAsync(_tagId)) .Returns(Task.FromResult(tagMock.Object)); _dut = new UploadActionAttachmentCommandHandler( _projectRepositoryMock.Object, UnitOfWorkMock.Object, PlantProviderMock.Object, _blobStorageMock.Object, attachmentOptionsMock.Object); }
public void Setup() { var _tagId = 1; var _attachmentFieldId = 12; var _reqId = 21; _command = new UploadFieldValueAttachmentCommand( _tagId, _reqId, _attachmentFieldId, _fileName, new MemoryStream()); _requirementDefinition = new Mock <RequirementDefinition>(); _requirementDefinition.SetupGet(r => r.Id).Returns(_reqId); _requirementDefinition.SetupGet(r => r.Plant).Returns(TestPlant); var attachmentFieldMock = new Mock <Field>(TestPlant, "", FieldType.Attachment, 0, "", false); attachmentFieldMock.SetupGet(f => f.Id).Returns(_attachmentFieldId); attachmentFieldMock.SetupGet(f => f.Plant).Returns(TestPlant); _requirementDefinition.Object.AddField(attachmentFieldMock.Object); var requirementMock = new Mock <TagRequirement>(TestPlant, 2, _requirementDefinition.Object); requirementMock.SetupGet(r => r.Id).Returns(_reqId); requirementMock.SetupGet(r => r.Plant).Returns(TestPlant); _requirement = requirementMock.Object; var stepMock = new Mock <Step>(); stepMock.SetupGet(s => s.Plant).Returns(TestPlant); var tag = new Tag(TestPlant, TagType.Standard, "", "", stepMock.Object, new List <TagRequirement> { _requirement }); tag.StartPreservation(); Assert.AreEqual(PreservationStatus.Active, tag.Status); Assert.IsTrue(_requirement.HasActivePeriod); var _projectRepositoryMock = new Mock <IProjectRepository>(); _projectRepositoryMock .Setup(r => r.GetTagByTagIdAsync(_tagId)) .Returns(Task.FromResult(tag)); var _rtRepositoryMock = new Mock <IRequirementTypeRepository>(); _rtRepositoryMock .Setup(r => r.GetRequirementDefinitionByIdAsync(_reqId)) .Returns(Task.FromResult(_requirementDefinition.Object)); _blobStorageMock = new Mock <IBlobStorage>(); var attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >(); var options = new AttachmentOptions { MaxSizeMb = 2, BlobContainer = _blobContainer, ValidFileSuffixes = new[] { ".gif", ".jpg" } }; attachmentOptionsMock .Setup(x => x.CurrentValue) .Returns(options); _dut = new UploadFieldValueAttachmentCommandHandler( _projectRepositoryMock.Object, _rtRepositoryMock.Object, UnitOfWorkMock.Object, PlantProviderMock.Object, _blobStorageMock.Object, attachmentOptionsMock.Object); }
private static async Task <File> PostFile(string account, string uploadSessionId, string fileName, String mimeType, string visibility, AttachmentOptions options) { string fileContent = Utils.CreateFileContent(fileName, mimeType); string json = Utils.CreatePostFilePayload(fileName, fileContent); string url = Constants.REST_MULTIDIALOGO_STAGE_HOST + "/users/" + account + "/upload-sessions/" + uploadSessionId + "/uploaded-files"; HttpResponseMessage response = await SendRequest(url, json, "Post"); if (response == null || response.Content == null) { throw new ApiDialogException("Impossibile ottenere fileId"); } string fileId = Utils.GetResponseId(await response.Content.ReadAsStringAsync()); Console.WriteLine("PostFile Id = " + fileId); return(new File(fileId, visibility, options)); }
// Esempio con errore: file globale associato a un destinatario private static async Task Scenario_3() { try { string account = Utils.GetAccount(); string uploadSessionId = await GetUploadSessionId(account); File personale1 = await PostFile(account, uploadSessionId, "personale1", "application/pdf", "private", null); File personale2 = await PostFile(account, uploadSessionId, "personale2", "application/pdf", "private", null); File globale1 = await PostFile(account, uploadSessionId, "globale1", "application/pdf", "global", AttachmentOptions.CreateAttachmentOptions(true, "bw", "A4", 80, true, false)); Attachments attachments = Attachments.CreateAttachments(uploadSessionId, new List <File> { personale1, personale2, globale1 }); Recipient recipient1 = Recipient.CreateRecipient("Via Emilia Ovest 129/2", "43126", "Parma", "PR", "it", "pt", "RACCOMANDATA1", "person", "Winton", "Marsalis", "Multidialogo Srl", "*****@*****.**", null, new List <string> { personale1.Id }, "sendposta", null, null); Recipient recipient2 = Recipient.CreateRecipient("Via Zarotto 63", "43123", "Collecchio", "PR", "it", "pt", "RACCOMANDATA1AR", "person", "Clara", "Schumann", "ASA Srl", "*****@*****.**", null, new List <string> { globale1.Id, personale2.Id }, "sendposta", null, null); PostQueueDto postQueueDto = PostQueue.CreatePostQueue(Sender.CreateSender(), attachments, new List <Recipient> { recipient1, recipient2 }, "Convocazione assemblea", "Caro sei convocato per l'assemblea. Visualizza l'allegato. Grazie.", false, false, false, false, "Test scenario 1", null); await SendPostQueueRequest(account, postQueueDto); } catch (ApiDialogException e) { Console.WriteLine("Errore: " + e.Message); } }