public async Task HandlingDeleteFieldValueAttachmentCommand_ShouldSetActivePeriodReadyToNeedsUserInput()
        {
            // Arrange
            _requirement.RecordAttachment(new FieldValueAttachment(TestPlant, Guid.Empty, "F"), _command.FieldId, _requirementDefinition.Object);
            Assert.AreEqual(1, _requirement.ActivePeriod.FieldValues.Count);
            Assert.AreEqual(PreservationPeriodStatus.ReadyToBePreserved, _requirement.ActivePeriod.Status);

            // Act
            await _dut.Handle(_command, default);

            // Assert
            Assert.AreEqual(0, _requirement.ActivePeriod.FieldValues.Count);
            Assert.AreEqual(PreservationPeriodStatus.NeedsUserInput, _requirement.ActivePeriod.Status);
        }
        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 async Task HandlingUploadFieldValueAttachmentCommand_ShouldBothDeleteAndUploadToBlobStorage_WhenAttachmentExistsInAdvance()
        {
            // Arrange
            _requirement.RecordAttachment(new FieldValueAttachment(TestPlant, Guid.Empty, "F"), _command.FieldId, _requirementDefinition.Object);
            var attachmentValue = (AttachmentValue)_requirement.ActivePeriod.FieldValues.Single();
            var p = attachmentValue.FieldValueAttachment.GetFullBlobPath(_blobContainer);

            // Act
            await _dut.Handle(_command, default);

            // Assert
            _blobStorageMock.Verify(b => b.DeleteAsync(p, default), Times.Once);
            _blobStorageMock.Verify(b => b.UploadAsync(It.IsAny <string>(), It.IsAny <Stream>(), true, default), Times.Once);
        }