public async Task Dispatch_Stream_Success()
        {
            using (MemoryStream payloadValue = new MemoryStream())
                using (StreamWriter writer = new StreamWriter(payloadValue))
                {
                    // arrange
                    ObjectAttachment attachment    = null;
                    AttachmentId     correlationId = AttachmentId.NewId();
                    string           payloadName   = "Name-919";

                    await writer.WriteAsync("Value-919");

                    await writer.FlushAsync();

                    // act
                    Action verify = () => attachment = AttachmentFactory
                                                       .Create <ObjectAttachment>(correlationId, payloadName, payloadValue);

                    // assert
                    Assert.Null(Record.Exception(verify));
                    Assert.NotNull(attachment);
                    Assert.IsType <ObjectAttachment>(attachment);
                    Assert.Equal("\"Value-919\"", Encoding.UTF8.GetString(attachment.Value));
                }
        }
Beispiel #2
0
        public void OnResolverError(
            string message,
            HotChocolateRequest request,
            IEnumerable <HotChocolateError> errors)
        {
            if (IsEnabled())
            {
                AttachmentId attachmentId = AttachmentId.NewId();

                IAttachment requestAttachment = AttachmentFactory
                                                .Create <HotChocolateRequestAttachment, HotChocolateRequest>(
                    attachmentId, nameof(request), request);

                HotChocolateErrorsAttachment errorAttachments = AttachmentFactory
                                                                .Create <HotChocolateErrorsAttachment, IEnumerable <HotChocolateError> >(
                    attachmentId, nameof(errors), errors);

                AttachmentDispatcher.Instance.Dispatch(
                    errorAttachments, requestAttachment);

                OnResolverError(
                    Application.Id, ActivityStack.Id,
                    attachmentId, message);
            }
        }
Beispiel #3
0
        public async Task OneInitialAttachment_TwoAdded_ThreeAttachmentsInDraft()
        {
            //Arrange
            var initialAttachment = new List <Attachment> {
                AttachmentFactory.Create()
            };
            var addedAttachment = new List <FileData> {
                FileDataFactory.Create(), FileDataFactory.Create()
            };
            var initialSuspiciousEmployees = new List <EmployeeId> {
                this._suspiciousEmployee
            };

            var useCase =
                await this._testFixture.PrepareUseCaseWithTestData(this._applicant, initialSuspiciousEmployees,
                                                                   addedAttachment, null, initialAttachment);

            //Act
            var useCaseOutput =
                (UpdateDraftApplicationUseCaseOutputPort)await this._module.ExecuteUseCase(useCase);

            //Assert
            var draftApplicationFromContext = await this._testFixture.GetDraftFromContext(useCase.DraftApplicationId);

            Assert.AreEqual(OutputPortInvokedMethod.Standard, useCaseOutput.InvokedOutputMethod);
            Assert.AreEqual(3, draftApplicationFromContext.Attachments.Count);
        }
Beispiel #4
0
 /// <summary>
 /// 转换为附件实体
 /// </summary>
 /// <param name="dto">附件数据传输对象</param>
 public static Attachment ToEntity3(this AttachmentDto dto)
 {
     if (dto == null)
     {
         return(new Attachment());
     }
     return(AttachmentFactory.Create(
                attachmentId: dto.Id.ToGuid(),
                fileName: dto.FileName,
                fileType: dto.FileType,
                size: dto.Size,
                remoteUrl: dto.RemoteUrl,
                localUrl: dto.LocalUrl,
                width: dto.Width,
                height: dto.Height,
                merchantId: dto.MerchantId,
                module: dto.Module,
                creationTime: dto.CreationTime,
                creatorId: dto.CreatorId,
                lastModificationTime: dto.LastModificationTime,
                lastModifierId: dto.LastModifierId,
                isDeleted: dto.IsDeleted,
                version: dto.Version
                ));
 }
        public void InternalServerErrorOccurred(Exception exception)
        {
            if (IsEnabled())
            {
                AttachmentId        attachmentId = AttachmentId.NewId();
                ExceptionAttachment attachment   = AttachmentFactory.Create(attachmentId,
                                                                            nameof(exception), exception);

                AttachmentDispatcher.Instance.Dispatch(attachment);
                InternalServerErrorOccurred(Application.Id, ActivityStack.Id, attachmentId);
            }
        }
        public void RetrieveObjectInfo(int id, RequestInformation info)
        {
            if (IsEnabled())
            {
                var attachmentId = AttachmentId.NewId();

                RetrieveObjectInfo(Application.Id, ActivityStack.Id, attachmentId, id);

                AttachmentDispatcher.Instance.Dispatch(
                    AttachmentFactory.Create(attachmentId, "info", info)
                    );
            }
        }
Beispiel #7
0
        public void Start(Guid activityId, HotChocolateRequest request)
        {
            if (IsEnabled())
            {
                AttachmentId attachmentId = AttachmentId.NewId();
                IAttachment  attachment   = AttachmentFactory
                                            .Create <HotChocolateRequestAttachment, HotChocolateRequest>(
                    attachmentId, nameof(request), request);

                AttachmentDispatcher.Instance.Dispatch(attachment);
                Start(Application.Id, activityId, attachmentId);
            }
        }
        public void Dispatch_Stream_PayloadValueNull()
        {
            // arrange
            ObjectAttachment attachment    = null;
            AttachmentId     correlationId = AttachmentId.NewId();
            string           payloadName   = "Name-881";
            Stream           payloadValue  = null;

            // act
            Action verify = () => attachment = AttachmentFactory
                                               .Create <ObjectAttachment>(correlationId, payloadName, payloadValue);

            // assert
            Assert.Null(Record.Exception(verify));
            Assert.Null(attachment);
        }
Beispiel #9
0
        public void OnQueryError(Exception exception)
        {
            if (IsEnabled())
            {
                AttachmentId attachmentId = AttachmentId.NewId();

                ExceptionAttachment attachment = AttachmentFactory
                                                 .Create(attachmentId, nameof(exception), exception);

                AttachmentDispatcher.Instance.Dispatch(attachment);

                OnQueryError(
                    Application.Id, ActivityStack.Id,
                    attachmentId, exception.Message);
            }
        }
        public void Dispatch_Exception_PayloadValueNull()
        {
            // arrange
            ExceptionAttachment attachment    = null;
            AttachmentId        correlationId = AttachmentId.NewId();
            string    payloadName             = "Name-567";
            Exception payloadValue            = null;

            // act
            Action verify = () => attachment = AttachmentFactory
                                               .Create(correlationId, payloadName, payloadValue);

            // assert
            Assert.Null(Record.Exception(verify));
            Assert.Null(attachment);
        }
        public void Create_Object_CorrelationIdNull()
        {
            // arrange
            ObjectAttachment attachment    = null;
            AttachmentId     correlationId = AttachmentId.Empty;
            string           payloadName   = "Name-627";
            object           payloadValue  = "Value-627";

            // act
            Action verify = () => attachment = AttachmentFactory
                                               .Create(correlationId, payloadName, payloadValue);

            // assert
            Assert.Null(Record.Exception(verify));
            Assert.Null(attachment);
        }
        public void Create_Exception_PayloadNameNull()
        {
            // arrange
            ExceptionAttachment attachment    = null;
            AttachmentId        correlationId = AttachmentId.NewId();
            string    payloadName             = null;
            Exception payloadValue            = new ArgumentNullException("Value-426");

            // act
            Action verify = () => attachment = AttachmentFactory
                                               .Create(correlationId, payloadName, payloadValue);

            // assert
            Assert.Null(Record.Exception(verify));
            Assert.Null(attachment);
        }
        public void Dispatch_Exception_Success()
        {
            // arrange
            ExceptionAttachment attachment    = null;
            AttachmentId        correlationId = AttachmentId.NewId();
            string    payloadName             = "Name-848";
            Exception payloadValue            = new ArgumentNullException("Value-848");

            // act
            Action verify = () => attachment = AttachmentFactory
                                               .Create(correlationId, payloadName, payloadValue);

            // assert
            Assert.Null(Record.Exception(verify));
            Assert.NotNull(attachment);
            Assert.IsType <ExceptionAttachment>(attachment);
        }
        public void Dispatch_Object_Success()
        {
            // arrange
            ObjectAttachment attachment    = null;
            AttachmentId     correlationId = AttachmentId.NewId();
            string           payloadName   = "Name-123";
            object           payloadValue  = "Value-123";

            // act
            Action verify = () => attachment = AttachmentFactory
                                               .Create(correlationId, payloadName, payloadValue);

            // assert
            Assert.Null(Record.Exception(verify));
            Assert.NotNull(attachment);
            Assert.IsType <ObjectAttachment>(attachment);
        }
        /// <summary>
        /// Dispatches an <see cref="HttpRequest"/>.
        /// </summary>
        /// <param name="dispatcher">A dispatcher instance.</param>
        /// <param name="id">A correlation id.</param>
        /// <param name="payloadName">A payload name.</param>
        /// <param name="payloadValue">A HTTP request.</param>
        /// <remarks>This method may not break because it is called from EventSources.</remarks>
        public static void Dispatch(this AttachmentDispatcher dispatcher, AttachmentId id,
                                    string payloadName, HttpRequest payloadValue)
        {
            if (dispatcher != null && id != AttachmentId.Empty &&
                !string.IsNullOrWhiteSpace(payloadName) && payloadValue != null)
            {
                HttpRequestAttachment request = AttachmentFactory
                                                .Create <HttpRequestAttachment, HttpRequest>(id, payloadName, payloadValue);

                dispatcher.Dispatch(request);

                if (payloadValue.Body != null && payloadValue.Body.Length > 0)
                {
                    HttpRequestBodyAttachment requestBody = AttachmentFactory
                                                            .Create <HttpRequestBodyAttachment>(id, payloadName,
                                                                                                payloadValue.Body);

                    dispatcher.Dispatch(requestBody);
                }
            }
        }
        /// <summary>
        /// Dispatches an <see cref="HttpResponse"/>.
        /// </summary>
        /// <param name="dispatcher">A dispatcher instance.</param>
        /// <param name="id">A correlation id.</param>
        /// <param name="payloadName">A payload name.</param>
        /// <param name="payloadValue">A HTTP response.</param>
        /// <remarks>This method may not break because it is called from EventSources.</remarks>
        public static void Dispatch(this AttachmentDispatcher dispatcher, AttachmentId id,
                                    string payloadName, HttpResponse payloadValue)
        {
            if (dispatcher != null && id != AttachmentId.Empty &&
                !string.IsNullOrWhiteSpace(payloadName) && payloadValue != null)
            {
                HttpResponseAttachment response = AttachmentFactory
                                                  .Create <HttpResponseAttachment, HttpResponse>(id, payloadName, payloadValue);

                dispatcher.Dispatch(response);

#pragma warning disable S125 // Sections of code should not be "commented out"
                //if (payloadValue.Body != null && payloadValue.Body.Length > 0)
                //{
                //    HttpResponseBodyAttachment responseBody = AttachmentFactory
                //        .Create<HttpResponseBodyAttachment>(id, payloadName,
                //            payloadValue.Body);
                //
                //    dispatcher.Dispatch(responseBody);
                //}
#pragma warning disable S125 // Sections of code should not be "commented out"
            }
        }
        public async Task Create_Stream_PayloadNameNull()
        {
            using (MemoryStream payloadValue = new MemoryStream())
                using (StreamWriter writer = new StreamWriter(payloadValue))
                {
                    // arrange
                    ObjectAttachment attachment    = null;
                    AttachmentId     correlationId = AttachmentId.NewId();
                    string           payloadName   = null;

                    await writer.WriteAsync("Value-444");

                    await writer.FlushAsync();

                    // act
                    Action verify = () => attachment = AttachmentFactory
                                                       .Create <ObjectAttachment>(correlationId, payloadName, payloadValue);

                    // assert
                    Assert.Null(Record.Exception(verify));
                    Assert.Null(attachment);
                }
        }