Esempio n. 1
0
 // Default contructor that set entity to field
 public AttachmentModel(Attachment attachment)
 {
     this._attachment          = attachment;
     this._id                  = attachment.Id;
     this._file_attachments_id = attachment.FileAttachmentsId;
     this._originalAttachment  = attachment.DeepClone();
 }
Esempio n. 2
0
        public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedByNotSameAsCreatedByAndLogItAsync()
        {
            // given
            int            randomNegativeMinutes = GetNegativeRandomNumber();
            Guid           differentId           = Guid.NewGuid();
            Guid           invalidCreatedBy      = differentId;
            DateTimeOffset randomDate            = GetRandomDateTime();
            Attachment     randomAttachment      = CreateRandomAttachment(randomDate);
            Attachment     invalidAttachment     = randomAttachment;

            invalidAttachment.CreatedDate = randomDate.AddMinutes(randomNegativeMinutes);
            Attachment storageAttachment = randomAttachment.DeepClone();
            Guid       attachmentId      = invalidAttachment.Id;

            invalidAttachment.CreatedBy = invalidCreatedBy;

            var invalidAttachmentInputException = new InvalidAttachmentException(
                parameterName: nameof(Attachment.CreatedBy),
                parameterValue: invalidAttachment.CreatedBy);

            var expectedAttachmentValidationException =
                new AttachmentValidationException(invalidAttachmentInputException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAttachmentByIdAsync(attachmentId))
            .ReturnsAsync(storageAttachment);

            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(randomDate);

            // when
            ValueTask <Attachment> modifyAttachmentTask =
                this.attachmentService.ModifyAttachmentAsync(invalidAttachment);

            // then
            await Assert.ThrowsAsync <AttachmentValidationException>(() =>
                                                                     modifyAttachmentTask.AsTask());

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectAttachmentByIdAsync(invalidAttachment.Id),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedAttachmentValidationException))),
                                          Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 3
0
        public async Task ShouldModifyAttachmentAsync()
        {
            // given
            int            randomNumber    = GetRandomNumber();
            int            randomDays      = randomNumber;
            DateTimeOffset randomDate      = GetRandomDateTime();
            DateTimeOffset randomInputDate = GetRandomDateTime();

            Attachment randomAttachment =
                CreateRandomAttachment(randomInputDate);

            Attachment inputAttachment = randomAttachment;
            Attachment afterUpdateStorageAttachment = inputAttachment;
            Attachment expectedAttachment           = afterUpdateStorageAttachment;

            Attachment beforeUpdateStorageAttachment =
                randomAttachment.DeepClone();

            inputAttachment.UpdatedDate = randomDate;
            Guid attachmentId = inputAttachment.Id;

            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(randomDate);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAttachmentByIdAsync(attachmentId))
            .ReturnsAsync(beforeUpdateStorageAttachment);

            this.storageBrokerMock.Setup(broker =>
                                         broker.UpdateAttachmentAsync(inputAttachment))
            .ReturnsAsync(afterUpdateStorageAttachment);

            // when
            Attachment actualAttachment =
                await this.attachmentService.ModifyAttachmentAsync(inputAttachment);

            // then
            actualAttachment.Should().BeEquivalentTo(expectedAttachment);

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectAttachmentByIdAsync(attachmentId),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.UpdateAttachmentAsync(inputAttachment),
                                          Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }