Esempio n. 1
0
        public async Task HttpSubmitItemPipelineElement_Validates_ItemSubmissionInputModel_With_BinariesSubmittedProp()
        {
            ItemSubmissionInputModel inputModelBuiltOnSubmit = null;

            _mockClient
            .Setup(x =>
                   x.ApiItemsPostWithHttpMessagesAsync(
                       It.IsAny <ItemSubmissionInputModel>(),
                       It.IsAny <string>(),
                       It.IsAny <Dictionary <string, List <string> > >(),
                       CancellationToken.None))
            .Callback <ItemSubmissionInputModel, string, Dictionary <string, List <string> >, CancellationToken>(
                (model, lan, headers, ct) => inputModelBuiltOnSubmit = model)
            .ReturnsAsync(() => new HttpOperationResponse <object> {
                Body = new { text = "test ok" }, Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.OK)
            });

            _mockClientFactory.Setup(x => x.CreateApiClient(It.IsAny <ApiClientFactorySettings>())).Returns(_mockClient.Object);

            _itemPipelineElement = new HttpSubmitItemPipelineElement(_mockSubmission.Object)
            {
                ApiClientFactory = _mockClientFactory.Object
            };

            var submitContext = new ItemSubmitContext
            {
                BinariesSubmitted = new List <DirectBinarySubmissionInputModel>
                {
                    new DirectBinarySubmissionInputModel
                    {
                        BinaryExternalId = "binary-external-id-1",
                        ItemExternalId   = "item-external-id-1"
                    },
                    new DirectBinarySubmissionInputModel
                    {
                        BinaryExternalId = "binary-external-id-2",
                        ItemExternalId   = "item-external-id-1"
                    },
                    new DirectBinarySubmissionInputModel
                    {
                        BinaryExternalId = "binary-external-id-3",
                        ItemExternalId   = "item-external-id-1"
                    },
                }
            };

            await _itemPipelineElement.Submit(submitContext);

            _mockSubmission.Verify(x => x.Submit(It.IsAny <SubmitContext>()));

            inputModelBuiltOnSubmit.BinariesSubmitted.Should().HaveCount(3);
            inputModelBuiltOnSubmit.BinariesSubmitted.Select(x => x.ItemExternalId).Distinct().Should().BeEquivalentTo("item-external-id-1");
        }
Esempio n. 2
0
        /// <summary>
        /// Create the Submit Pipeline. The submit pipeline can be customized
        /// with custom submit pipeline elements to control the submission
        /// behaviour. The submit pipeline is stateless, so there is only one
        /// instance of each pipeline that is shared across all submissions.
        /// </summary>
        private void CreateSubmitPipeline()
        {
            var apiClientFactory = new ApiClientFactory();

            var httpSubmitItemElement = new HttpSubmitItemPipelineElement(null);

            httpSubmitItemElement.ApiClientFactory = apiClientFactory;

            // Create a Filter pipeline element for items. This implements the logic
            // to apply the user-defined filtering on item submission.
            // Pass the httpSubmitItemElement into the FilterPipelineElement to create a chain of pipeline elements.
            // The filter is called first, followed by the submission element.
            var itemFilterPipelineElement = new FilterPipelineElement(httpSubmitItemElement);

            _itemSubmitPipeline = itemFilterPipelineElement;

            var httpSubmitAggregationElement = new HttpSubmitAggregationPipelineElement(null);

            httpSubmitAggregationElement.ApiClientFactory = apiClientFactory;

            var aggregationFilterPipelineElement = new FilterPipelineElement(httpSubmitAggregationElement);

            _aggregationSubmitPipeline = aggregationFilterPipelineElement;

            var circuitBreakerOpts      = new CircuitBreakerOptions();
            var httpSubmitBinaryElement = new DirectSubmitBinaryPipelineElement(null)
            {
                ApiClientFactory = apiClientFactory,
                CircuitProvider  = new AzureBlobRetryProviderWithCircuitBreaker(circuitBreakerOpts, true),
                RetryProvider    = new AzureBlobRetryProviderWithCircuitBreaker(circuitBreakerOpts, true),
                // Log = optional logger
            };

            var binaryFilterPipelineElement = new FilterPipelineElement(httpSubmitBinaryElement);

            _binarySubmitPipeline = binaryFilterPipelineElement;

            var httpSubmitAuditEventElement = new HttpSubmitAuditEventPipelineElement(null);

            httpSubmitAuditEventElement.ApiClientFactory = apiClientFactory;
            _auditEventSubmitPipeline = httpSubmitAuditEventElement;
        }