public void Constructor_ShouldSetActionAttachmentSpecificProperties() { var dut = new ActionAttachment(TestPlant, BlobStorageId, "FileA"); Assert.AreEqual($"PlantA/Action/{BlobStorageId.ToString()}", dut.BlobPath); // Other properties are tested in base class }
private static void SeedActionAttachment(PreservationContext dbContext, Action action) { var attachment = new ActionAttachment(action.Plant, KnownTestData.ActionAttachmentBlobStorageId, "Fil2.txt"); action.AddAttachment(attachment); dbContext.SaveChangesAsync().Wait(); }
public async Task <Result <int> > Handle(UploadActionAttachmentCommand request, CancellationToken cancellationToken) { var tag = await _projectRepository.GetTagByTagIdAsync(request.TagId); var action = tag.Actions.Single(a => a.Id == request.ActionId); var attachment = action.GetAttachmentByFileName(request.FileName); if (!request.OverwriteIfExists && attachment != null) { throw new Exception($"Tag {tag.Id} already has an attachment with filename {request.FileName}"); } if (attachment == null) { attachment = new ActionAttachment( _plantProvider.Plant, Guid.NewGuid(), request.FileName); action.AddAttachment(attachment); } var fullBlobPath = attachment.GetFullBlobPath(_attachmentOptions.CurrentValue.BlobContainer); await _blobStorage.UploadAsync(fullBlobPath, request.Content, request.OverwriteIfExists, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new SuccessResult <int>(attachment.Id)); }
private (Project, Action) CreateAction(PreservationContext context, string projectName, bool closeProject) { var plantId = _plantProvider.Plant; var mode = new Mode(plantId, "M1", false); context.Modes.Add(mode); var responsible = new Responsible(plantId, "Resp1", "Resp1-Desc"); context.Responsibles.Add(responsible); context.SaveChangesAsync().Wait(); var journey = new Journey(plantId, "J1"); var step = new Step(plantId, "S1", mode, responsible); journey.AddStep(step); context.Journeys.Add(journey); context.SaveChangesAsync().Wait(); var requirementType = new RequirementType(plantId, "RT", "RT title", RequirementTypeIcon.Other, 1); context.RequirementTypes.Add(requirementType); var requirementDefinition = new RequirementDefinition(plantId, "RD", 2, RequirementUsage.ForAll, 1); requirementType.AddRequirementDefinition(requirementDefinition); context.SaveChangesAsync().Wait(); var project = new Project(plantId, projectName, $"{projectName} Desc") { IsClosed = closeProject }; context.Projects.Add(project); var tag = new Tag( plantId, TagType.Standard, "Tag A", "Tag desc", step, new List <TagRequirement> { new TagRequirement(plantId, 2, requirementDefinition) }); project.AddTag(tag); context.SaveChangesAsync().Wait(); var action = new Action(plantId, "A", "D", null); tag.AddAction(action); var attachment = new ActionAttachment(plantId, Guid.Empty, "fil.txt"); action.AddAttachment(attachment); context.SaveChangesAsync().Wait(); return(project, action); }
public void AddAttachment_ShouldAddAttachment() { var attachment = new ActionAttachment(TestPlant, Guid.Empty, "A.txt"); _dut.AddAttachment(attachment); Assert.AreEqual(attachment, _dut.Attachments.First()); }
public void RemoveAttachment_ShouldRemoveAttachment() { var attachment = new ActionAttachment(TestPlant, Guid.Empty, "A.txt"); _dut.AddAttachment(attachment); Assert.AreEqual(1, _dut.Attachments.Count); // Act _dut.RemoveAttachment(attachment); Assert.AreEqual(0, _dut.Attachments.Count); }
public void GetAttachmentByFileName_ShouldGetAttachmentWhenExists_RegardlessOfCasing() { // Arrange var fileName = "FileA"; var attachment = new ActionAttachment(TestPlant, Guid.Empty, fileName); _dut.AddAttachment(attachment); // Act var result = _dut.GetAttachmentByFileName(fileName.ToUpper()); // Arrange Assert.AreEqual(attachment, result); }
protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { _testDataSet = AddTestDataSet(context); var tag = _testDataSet.Project1.Tags.First(); var attachment = new ActionAttachment(TestPlant, Guid.NewGuid(), "FileA"); _openAction = new Action(TestPlant, "Open", "Desc1", _utcNow); tag.AddAction(_openAction); _closedAction = new Action(TestPlant, "Closed", "Desc2", _utcNow); _closedAction.Close(_utcNow, _testDataSet.CurrentUser); tag.AddAction(_closedAction); var tag2 = _testDataSet.Project1.Tags.Last(); var personMock = new Mock <Person>(); personMock.SetupGet(p => p.Id).Returns(7); _openActionWithEarliestDueTime = new Action(TestPlant, "OpenWithEarliestDueTime", "D2", _dueTimeUtc); _openActionWithDueTime = new Action(TestPlant, "OpenWithDueTime", "D1", _dueTimeUtc); _openActionWithoutDueTime = new Action(TestPlant, "OpenWithoutDueTime", "D3", _dueTimeUtc); _openActionWithoutDueTime.SetDueTime(null); _openAction.AddAttachment(attachment); _closedActionWithEarliestDueTime = new Action(TestPlant, "ClosedWithEarliestDueTime", "D5", _dueTimeUtc); _closedActionWithEarliestDueTime.Close(_utcNow, personMock.Object); _closedActionWithDueTime = new Action(TestPlant, "ClosedWithDueTime", "D4", _dueTimeUtc); _closedActionWithDueTime.Close(_utcNow, personMock.Object); _closedActionWithoutDueTime = new Action(TestPlant, "ClosedWithoutDueTime", "D6", _dueTimeUtc); _closedActionWithoutDueTime.SetDueTime(null); _closedActionWithoutDueTime.Close(_utcNow, personMock.Object); tag2.AddAction(_openActionWithoutDueTime); tag2.AddAction(_closedActionWithoutDueTime); tag2.AddAction(_openActionWithDueTime); tag2.AddAction(_closedActionWithDueTime); tag2.AddAction(_openActionWithEarliestDueTime); tag2.AddAction(_closedActionWithEarliestDueTime); context.SaveChangesAsync().Wait(); _tagId = tag.Id; _tag2Id = tag2.Id; _openActionId = _openAction.Id; _closedActionId = _closedAction.Id; } }
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); }
protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { _testDataSet = AddTestDataSet(context); var tag = _testDataSet.Project1.Tags.First(); var action = new Action(TestPlant, "Open", "Desc1", _utcNow); tag.AddAction(action); _attachment = new ActionAttachment(TestPlant, new Guid("{C3412890-1EF8-4E34-B96C-5488200A5AF5}"), "FileA"); action.AddAttachment(_attachment); context.SaveChangesAsync().Wait(); _tagId = tag.Id; _actionId = action.Id; } }
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(); var action = new Action(TestPlant, "Open", "Desc1", _utcNow); tag.AddAction(action); _attachment = new ActionAttachment(TestPlant, Guid.NewGuid(), "FileA"); action.AddAttachment(_attachment); context.SaveChangesAsync().Wait(); _tagId = tag.Id; _actionId = action.Id; _attachmentId = _attachment.Id; var fullBlobPath = _attachment.GetFullBlobPath(BlobContainer); _blobStorageMock .Setup(b => b.GetDownloadSasUri(fullBlobPath, It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns(_uri); }
protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { _testDataSet = AddTestDataSet(context); var tag = _testDataSet.Project1.Tags.First(); var attachment = new ActionAttachment(TestPlant, Guid.NewGuid(), "FileA"); _openAction = new Action(TestPlant, "Open", "Desc1", _dueUtc); _openAction.AddAttachment(attachment); tag.AddAction(_openAction); _closedAction = new Action(TestPlant, "Closed", "Desc2", _dueUtc); _closedAction.Close(_utcNow, _testDataSet.CurrentUser); tag.AddAction(_closedAction); context.SaveChangesAsync().Wait(); _tagId = tag.Id; _openActionId = _openAction.Id; _closedActionId = _closedAction.Id; } }
protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions) { using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider)) { var project = AddProject(context, "P", "Project description"); var journey = AddJourneyWithStep(context, "J", "S1", AddMode(context, "M1", false), AddResponsible(context, "R1")); var rd = AddRequirementTypeWith1DefWithoutField(context, "Rot", "D", _reqIconOther).RequirementDefinitions.First(); var tag = AddTag(context, project, TagType.Standard, "TagNo", "Tag description", journey.Steps.First(), new List <TagRequirement> { new TagRequirement(TestPlant, 2, rd) }); var action = new Action(TestPlant, "A", "D", null); tag.AddAction(action); var attachment = new ActionAttachment(TestPlant, Guid.Empty, _filename); action.AddAttachment(attachment); context.SaveChangesAsync().Wait(); _actionId = action.Id; } }