コード例 #1
0
        public void ConjunctionIsDistributedOverDisjunctionOfFiltersAndDistributionIsCommutative()
        {
            const string senderNameToken = "BizTalkFactory.Batching";
            const int    retryCountToken = 3;
            var          filter          = new Filter(
                () => BtsProperties.MessageType == SchemaMetadata.For <Any>().MessageType &&
                (BizTalkFactoryProperties.MapTypeName == senderNameToken || BtsProperties.ActualRetryCount > retryCountToken)
                );

            filter.ToString().Should().Be(
                string.Format(
                    "<Filter>"
                    + "<Group><Statement Property=\"{0}\" Operator=\"{1}\" Value=\"{2}\" /><Statement Property=\"{3}\" Operator=\"{4}\" Value=\"{5}\" /></Group>"
                    + "<Group><Statement Property=\"{0}\" Operator=\"{1}\" Value=\"{2}\" /><Statement Property=\"{6}\" Operator=\"{7}\" Value=\"{8}\" /></Group>"
                    + "</Filter>",
                    BtsProperties.MessageType.Type.FullName,
                    (int)FilterOperator.Equals,
                    SchemaMetadata.For <Any>().MessageType,
                    BizTalkFactoryProperties.MapTypeName.Type.FullName,
                    (int)FilterOperator.Equals,
                    senderNameToken,
                    BtsProperties.ActualRetryCount.Type.FullName,
                    (int)FilterOperator.GreaterThan,
                    retryCountToken));
        }
コード例 #2
0
        public void BatchContentIsTransformedToSpecificEnvelope()
        {
            string expectedEnvelopeContent;
            var    envelopeStream = new StringStream(EnvelopeFactory.Create <Envelope>().OuterXml);
            var    batchContentStream = MessageBodyFactory.Create <Batch.Content>(MessageBody.Samples.LoadString("Message.BatchContent.xml")).AsStream();
            var    transformedStream = new[] { envelopeStream, batchContentStream }.Transform().Apply(typeof(BatchContentToAnyEnvelope), new UTF8Encoding(false));

            using (var expectedReader = XmlReader.Create(transformedStream, new XmlReaderSettings {
                CloseInput = true
            }))
            {
                expectedReader.Read();
                expectedEnvelopeContent = expectedReader.ReadOuterXml();
            }

            using (var stream = MessageBody.Samples.Load("Message.BatchContent.xml"))
            {
                MessageMock.Object.BodyPart.Data = stream;
                PipelineContextMock
                .Setup(pc => pc.GetDocumentSpecByType(SchemaMetadata.For <Envelope>().MessageType))
                .Returns(SchemaMetadata.For <Envelope>().DocumentSpec);

                var sut = new EnvelopeBuilder();
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
                using (var actualReader = XmlReader.Create(MessageMock.Object.BodyPart.Data, new XmlReaderSettings {
                    CloseInput = true, IgnoreWhitespace = true
                }))
                {
                    actualReader.Read();
                    var actualEnvelopeContent = actualReader.ReadOuterXml();
                    actualEnvelopeContent.Should().Be(expectedEnvelopeContent);
                }
            }
        }
        public void SetupResponseExpectationAgainstSpecificMessageType()
        {
            _soapStub.As <ISolicitResponse>()
            .Setup(s => s.Request(SchemaMetadata.For <btf2_services_header>().DocumentSpec))
            .Returns(new StringStream("<response />"));

            var client = SoapClient <IMessageService> .For(_soapStubHost.Endpoint);

            try
            {
                var response = client.Invoke(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:request",
                        XmlReader.Create(new StringReader(MessageBodyFactory.Create <btf2_services_header>().OuterXml))));

                var reader = response !.GetReaderAtBodyContents();
                reader.MoveToContent();
                var outerXml = reader.ReadOuterXml();
                outerXml.Should().Be("<response />");

                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
コード例 #4
0
        public void MessageIsTransformedToEnvelopeViaEnvelopeSpecNameAnnotation()
        {
            using (var stream = MessageBody.Samples.Load("Message.BatchContentWithEnvelopeSpecName.xml"))
                using (var transformedStream = new StringStream("<root xmlns='urn:ns'></root>"))
                    using (var transformStreamMockInjectionScope = new TransformStreamMockInjectionScope())
                    {
                        MessageMock.Object.BodyPart.Data = stream;
                        PipelineContextMock
                        .Setup(pc => pc.GetDocumentSpecByType("urn:ns#root"))
                        .Returns(SchemaMetadata.For <Any>().DocumentSpec);

                        transformStreamMockInjectionScope.Mock
                        .Setup(ts => ts.ExtendWith(MessageMock.Object.Context))
                        .Returns(transformStreamMockInjectionScope.Mock.Object);
                        transformStreamMockInjectionScope.Mock
                        .Setup(ts => ts.Apply(typeof(IdentityTransform), new UTF8Encoding(false)))
                        .Returns(transformedStream)
                        .Verifiable();

                        var sut = new EnvelopeBuilder();
                        sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                        transformStreamMockInjectionScope.Mock.VerifyAll();
                    }
        }
        public void GetAnnotationsByName()
        {
            var annotations = SchemaMetadata.For <RootedSchema>().GetAnnotations();

            annotations.Should().NotBeEmpty();
            annotations.SingleOrDefault(e => e.Name.LocalName == "Properties").Should().NotBeNull();
        }
コード例 #6
0
		public override IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message)
		{
			var markableForwardOnlyEventingReadStream = message.BodyPart.WrapOriginalDataStream(
				originalStream => originalStream.AsMarkable(),
				pipelineContext.ResourceTracker);

			var batchDescriptor = markableForwardOnlyEventingReadStream.ProbeBatchContent().BatchDescriptor;
			if (batchDescriptor == null || batchDescriptor.EnvelopeSpecName.IsNullOrEmpty())
				throw new InvalidOperationException($"No EnvelopeSpecName has been found in {nameof(Batch.Content)} message and no envelope can be applied.");
			var envelopeSchema = Type.GetType(batchDescriptor.EnvelopeSpecName, true);
			message.Promote(BatchProperties.EnvelopePartition, batchDescriptor.Partition);

			markableForwardOnlyEventingReadStream.StopMarking();

			if (_logger.IsInfoEnabled) _logger.DebugFormat("Applying '{0}' envelope to message.", envelopeSchema.AssemblyQualifiedName);
			var envelope = EnvelopeFactory.Create(envelopeSchema);
			// can't use .AsStream() that relies on StringStream, which is Unicode/UTF-16, over envelope.OuterXml as CompositeXmlStream assumes UTF-8
			var envelopeStream = new MemoryStream(Encoding.UTF8.GetBytes(envelope.OuterXml));
			message.BodyPart.WrapOriginalDataStream(
				originalStream => new CompositeXmlStream(new[] { envelopeStream, originalStream }),
				pipelineContext.ResourceTracker);

			SchemaMetadata.For(envelopeSchema).Annotations.Find<EnvelopeMapAnnotation>().EnvelopeMapType.IfNotNull(m => MapType = m);
			return base.Execute(pipelineContext, message);
		}
        public void BuildPropertyExtractorCollectionGivesPrecedenceToSchemaExtractorsOverPipelineExtractors()
        {
            // has to be called before ContextPropertyAnnotationMockInjectionScope overrides SchemaMetadata.For<>() factory method
            var schemaMetadata = SchemaMetadata.For <Any>();

            using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
                using (var contextPropertyAnnotationMockInjectionScope = new PropertyExtractorAnnotationMockInjectionScope())
                {
                    contextPropertyAnnotationMockInjectionScope.Extractors = new(
                        new XPathExtractor(BizTalkFactoryProperties.OutboundTransportLocation.QName, "/letter/*/to", ExtractionMode.Demote),
                        new XPathExtractor(BtsProperties.Operation.QName, "/letter/*/salutations"));

                    PipelineContextMock.Setup(pc => pc.GetDocumentSpecByType("urn:ns#root")).Returns(schemaMetadata.DocumentSpec);
                    MessageMock.Object.BodyPart.Data = inputStream;
                    MessageMock.Setup(m => m.GetProperty(BtsProperties.MessageType)).Returns("urn:ns#root");

                    var sut = new ContextPropertyExtractor {
                        Extractors = new[] {
                            new XPathExtractor(BizTalkFactoryProperties.OutboundTransportLocation.QName, "/letter/*/from", ExtractionMode.Promote),
                            new XPathExtractor(BtsProperties.OutboundTransportLocation.QName, "/letter/*/paragraph")
                        }
                    };
                    var extractors = sut.BuildPropertyExtractorCollection(PipelineContextMock.Object, MessageMock.Object);

                    extractors.Should().BeEquivalentTo(
                        new[] {
                        new XPathExtractor(BizTalkFactoryProperties.OutboundTransportLocation.QName, "/letter/*/to", ExtractionMode.Demote),
                        new XPathExtractor(BtsProperties.Operation.QName, "/letter/*/salutations"),
                        new XPathExtractor(BtsProperties.OutboundTransportLocation.QName, "/letter/*/paragraph")
                    });
                }
        }
     public ReleaseSendPort()
     {
         Name         = SendPortName.Towards("Batch").About("Release").FormattedAs.Xml;
         State        = ServiceState.Started;
         SendPipeline = new SendPipeline <XmlTransmit>(
             pipeline => {
             pipeline.Encoder <MicroPipelineComponent>(
                 pc => {
                 pc.Components = new IMicroComponent[] {
                     new ContextBuilder {
                         BuilderType = typeof(ReleaseProcessResolver)
                     },
                     new ActivityTracker(),
                     new XsltRunner {
                         MapType = typeof(ReleaseToQueueControlledRelease)
                     }
                 };
             });
         });
         Transport.Adapter = new WcfSqlAdapter.Outbound(
             a => {
             a.Address = new() {
                 InitialCatalog = "BizTalkFactoryTransientStateDb",
                 Server         = Platform.Settings.ProcessingDatabaseServer,
                 InstanceName   = Platform.Settings.ProcessingDatabaseInstance
             };
             a.IsolationLevel = IsolationLevel.ReadCommitted;
             a.StaticAction   = "TypedProcedure/dbo/usp_batch_QueueControlledRelease";
         });
         Transport.Host        = Platform.Settings.HostResolutionPolicy;
         Transport.RetryPolicy = RetryPolicy.ShortRunning;
         Filter = new(() => BtsProperties.MessageType == SchemaMetadata.For <Batch.Release>().MessageType);
     }
 }
コード例 #9
0
        public void TransformBatchContentWithEnvironmentTagAndPartition()
        {
            var setup = Given(
                input => input
                .Message(EnvelopeFactory.Create <Envelope>().AsStream())
                .Message(MessageBodyFactory.Create <Batch.Content>(MessageBody.Samples.LoadString("Message.BatchContentWithEnvironmentTagAndPartition.xml")).AsStream()))
                        .Transform
                        .OutputsXml(
                output => output
                .ConformingTo <Envelope>()
                .ConformingTo <Batch.Release>()
                .WithStrictConformanceLevel());
            var result = setup.Validate();

            result.NamespaceManager.AddNamespace("env", SchemaMetadata.For <Envelope>().TargetNamespace);
            result.NamespaceManager.AddNamespace("tns", SchemaMetadata.For <Batch.Release>().TargetNamespace);

            result.SelectSingleNode("/*") !.LocalName.Should().Be("Envelope");
            result.Select("/env:Envelope/tns:ReleaseBatch").Cast <object>().Should().HaveCount(3);
            result.Select("/env:Envelope/*").Cast <object>().Should().HaveCount(3);

            var part = result.SelectSingleNode("/env:Envelope/tns:ReleaseBatch[3]");

            part !.SelectSingleNode("tns:EnvelopeSpecName") !.Value.Should().Be(SchemaMetadata.For <Batch.Release>().DocumentSpec.DocSpecName);
            part !.SelectSingleNode("tns:EnvironmentTag") !.Value.Should().Be("graffiti");
            part !.SelectSingleNode("tns:Partition") !.Value.Should().Be("A");
        }
コード例 #10
0
        public void ReplacesMessageOriginalDataStreamWithTransformResult()
        {
            PipelineContextMock
            .Setup(m => m.GetDocumentSpecByType("http://schemas.microsoft.com/Edi/EdifactServiceSchema#UNB"))
            .Returns(SchemaMetadata.For <EdifactServiceSchema.UNB>().DocumentSpec);

            var sut = new XsltRunner {
                Encoding = Encoding.UTF8,
                MapType  = typeof(IdentityTransform)
            };

            using (var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("<UNB xmlns='http://schemas.microsoft.com/Edi/EdifactServiceSchema'></UNB>")))
                using (var transformedStream = dataStream.Transform().Apply(sut.MapType))
                    using (var transformStreamMockInjectionScope = new TransformStreamMockInjectionScope())
                    {
                        MessageMock.Object.BodyPart.Data = dataStream;

                        transformStreamMockInjectionScope.Mock
                        .Setup(ts => ts.ExtendWith(MessageMock.Object.Context))
                        .Returns(transformStreamMockInjectionScope.Mock.Object);
                        transformStreamMockInjectionScope.Mock
                        .Setup(ts => ts.Apply(sut.MapType, sut.Encoding))
                        .Returns(transformedStream)
                        .Verifiable();

                        sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                        transformStreamMockInjectionScope.Mock.VerifyAll();

                        MessageMock.Object.BodyPart.Data.Should().BeOfType <MarkableForwardOnlyEventingReadStream>();
                        Reflector.GetField((MarkableForwardOnlyEventingReadStream)MessageMock.Object.BodyPart.Data, "m_data").Should().BeSameAs(transformedStream);
                    }
        }
コード例 #11
0
        public void XsltFromContextHasPrecedenceOverConfiguredOne()
        {
            PipelineContextMock
            .Setup(m => m.GetDocumentSpecByType("http://schemas.microsoft.com/Edi/EdifactServiceSchema#UNB"))
            .Returns(SchemaMetadata.For <EdifactServiceSchema.UNB>().DocumentSpec);

            var sut = new XsltRunner {
                Encoding = Encoding.UTF8,
                MapType  = typeof(TransformBase)
            };

            using (var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("<UNB xmlns='http://schemas.microsoft.com/Edi/EdifactServiceSchema'></UNB>")))
                using (var transformedStream = dataStream.Transform().Apply(typeof(IdentityTransform)))
                    using (var transformStreamMockInjectionScope = new TransformStreamMockInjectionScope())
                    {
                        MessageMock.Object.BodyPart.Data = dataStream;
                        MessageMock
                        .Setup(m => m.GetProperty(BizTalkFactoryProperties.MapTypeName))
                        .Returns(typeof(IdentityTransform).AssemblyQualifiedName);

                        var transformStreamMock = transformStreamMockInjectionScope.Mock;
                        transformStreamMock
                        .Setup(ts => ts.ExtendWith(MessageMock.Object.Context))
                        .Returns(transformStreamMock.Object);
                        transformStreamMock
                        .Setup(ts => ts.Apply(typeof(IdentityTransform), sut.Encoding))
                        .Returns(transformedStream)
                        .Verifiable();

                        sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                        transformStreamMock.Verify(ts => ts.Apply(sut.MapType, sut.Encoding), Times.Never());
                        transformStreamMock.VerifyAll();
                    }
        }
コード例 #12
0
            /// <summary>
            /// Provides the <see cref="XmlSchema"/> to the <paramref name="schemaSet"/> and the <see cref="XmlSchemaType"/> that
            /// controls the serialization of the type.
            /// </summary>
            /// <param name="schemaSet">
            /// The <see cref="XmlSchemaSet"/> that will be populated with the <see cref="XmlSchema"/>.
            /// </param>
            /// <returns>
            /// The <see cref="XmlSchemaType"/> that defines its data type.
            /// </returns>
            /// <remarks>
            /// This is a scaffolding method that is meant to be called from within the derived classes' static method identified
            /// by the <see cref="XmlSchemaProviderAttribute"/>.
            /// </remarks>
            XmlSchemaType IXmlSchemaProvider.ProvideSchema(XmlSchemaSet schemaSet)
            {
                schemaSet.Merge(((IXmlSchemaProvider)this).Schema);
                schemaSet.Compile();
                var schemaMetadata = SchemaMetadata.For <TSchemaBase>();
                var element        = (XmlSchemaElement)schemaSet.GlobalElements[new XmlQualifiedName(schemaMetadata.RootElementName, schemaMetadata.TargetNamespace)];

                return(element.ElementSchemaType);
            }
コード例 #13
0
        public void MessageTypeBasedFilter()
        {
            var filter = new Filter(() => BtsProperties.MessageType == SchemaMetadata.For <Any>().MessageType);

            filter.ToString().Should().Be(
                "<Filter><Group>"
                + $"<Statement Property=\"{BtsProperties.MessageType.Type.FullName}\" Operator=\"{(int) FilterOperator.Equals}\" Value=\"{SchemaMetadata.For<Any>().MessageType}\" />"
                + "</Group></Filter>");
        }
 public void BatchDescriptor()
 {
     using (var stream = MessageBody.Samples.Load("Message.BatchContent.xml").AsMarkable())
     {
         var batchDescriptor = stream.ProbeBatchContent().BatchDescriptor;
         batchDescriptor.EnvelopeSpecName.Should().Be(SchemaMetadata.For <Envelope>().DocumentSpec.DocSpecStrongName);
         batchDescriptor.Partition.Should().BeNull();
     }
 }
 public BankSendPort()
 {
     Name                  = SendPortName.Towards(Party.Bank).About(Subject.CreditNote).FormattedAs.Edi;
     SendPipeline          = new SendPipeline <XmlTransmit>();
     Transport.Adapter     = new FileAdapter.Outbound(a => { a.DestinationFolder = @"c:\file\drops"; });
     Transport.Host        = Host.SENDING_HOST;
     Transport.RetryPolicy = RetryPolicy.LongRunning;
     Filter                = new(() => BtsProperties.MessageType == SchemaMetadata.For <Any>().MessageType);
 }
コード例 #16
0
 public static XmlDocument CreateMessage(Type schema)
 {
     if (!schema.IsSchema())
     {
         throw new ArgumentException(
                   $"{schema.FullName} does not derive from {typeof(SchemaBase).FullName}.",
                   nameof(schema));
     }
     return(CreateMessage(SchemaMetadata.For(schema).DocumentSpec));
 }
コード例 #17
0
        /// <summary>
        /// Returns the <see cref="ISchemaMetadata"/> associated to the XML schema of messages of a given <see
        /// cref="DocumentSpec"/> type.
        /// </summary>
        /// <param name="pipelineContext">
        /// The pipeline context from which the <see cref="DocumentSpec"/> can be queried.
        /// </param>
        /// <param name="docType">
        /// The <see cref="DocumentSpec"/> type of the messages for which the <see cref="ISchemaMetadata"/> are to be returned.
        /// </param>
        /// <returns>
        /// The <see cref="ISchemaMetadata"/> associated to the XML Schema.
        /// </returns>
        public static ISchemaMetadata GetSchemaMetadataByType(this IPipelineContext pipelineContext, string docType)
        {
            if (pipelineContext == null)
            {
                throw new ArgumentNullException(nameof(pipelineContext));
            }
            var docSpec    = pipelineContext.GetDocumentSpecByType(docType);
            var schemaType = Type.GetType(docSpec.DocSpecStrongName, true);

            return(SchemaMetadata.For(schemaType));
        }
コード例 #18
0
        public void NAryConjunction()
        {
            var filter = new Filter(
                () => BtsProperties.ActualRetryCount > 3 &&
                BtsProperties.MessageType == SchemaMetadata.For <Any>().MessageType &&
                BtsProperties.SendPortName == "Dummy port name" &&
                BtsProperties.IsRequestResponse != true
                );

            Invoking(() => filter.ToString()).Should().NotThrow();
        }
コード例 #19
0
        public void InvokeSucceeds()
        {
            _soapStub.As <ISolicitResponse>()
            .Setup(s => s.Request(SchemaMetadata.For <btf2_services_header>().DocumentSpec))
            .Returns(new StringStream("<response />"));

            using (var response = SoapClient.Invoke(_soapStubHost.Endpoint, new StringStream(MessageBodyFactory.Create <btf2_services_header>().OuterXml)))
            {
                new StreamReader(response).ReadToEnd().Should().Be("<response />");
            }
        }
コード例 #20
0
        /// <summary>
        /// Returns the <see cref="ISchemaMetadata"/> associated to the XML schema of messages of a given <see
        /// cref="DocumentSpec"/> type.
        /// </summary>
        /// <param name="pipelineContext">
        /// The pipeline context from which the <see cref="DocumentSpec"/> can be queried.
        /// </param>
        /// <param name="docType">
        /// The <see cref="DocumentSpec"/> type of the messages for which the <see cref="ISchemaMetadata"/> are to be returned.
        /// </param>
        /// <param name="throwOnError">
        /// <c>false</c> to swallow <see cref="COMException"/> and return a <see cref="SchemaMetadata.Unknown"/> should the
        /// document specification not to be found; it will however be logged as a warning. <c>true</c> to let any exception
        /// through.
        /// </param>
        /// <returns>
        /// The <see cref="ISchemaMetadata"/> associated to the XML Schema.
        /// </returns>
        public static ISchemaMetadata GetSchemaMetadataByType(this IPipelineContext pipelineContext, string docType, bool throwOnError)
        {
            if (throwOnError)
            {
                return(pipelineContext.GetSchemaMetadataByType(docType));
            }
            var schemaType = !docType.IsNullOrEmpty() && pipelineContext.TryGetDocumentSpecByType(docType, out var documentSpec)
                                ? Type.GetType(documentSpec.DocSpecStrongName, false)
                                : null;

            return(SchemaMetadata.For(schemaType));
        }
        public void ReceivePipelineDslGrammarVariant5()
        {
            Skip.IfNot(BizTalkServerGroup.IsConfigured);

            // not fluent-DSL
            var pipeline = new ReceivePipeline <XmlReceive>();

            pipeline.Stages.Decode.Component <FailedMessageRoutingEnablerComponent>().Enabled = false;
            pipeline.Stages.Decode.Component <MicroPipelineComponent>().Components            = new IMicroComponent[] { new XsltRunner {
                                                                                                                            MapType = typeof(IdentityTransform)
                                                                                                                        } };
            pipeline.Stages.Disassemble.Component <XmlDasmComp>().DocumentSpecNames = new() {
                new SchemaWithNone(SchemaMetadata.For <Any>().DocumentSpec.DocSpecStrongName),
                new SchemaWithNone(SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec.DocSpecStrongName)
            };
            pipeline.Stages.Disassemble.Component <XmlDasmComp>().RecoverableInterchangeProcessing = true;
            pipeline.Stages.Validate.Component <MicroPipelineComponent>().Components = new IMicroComponent[] { new XsltRunner {
                                                                                                                   MapType = typeof(IdentityTransform)
                                                                                                               } };
            var binding = pipeline.GetPipelineBindingInfoSerializer().Serialize();

            // fluent-DSL fifth variant
            var pipeline5 = ReceivePipeline <XmlReceive> .Configure(
                pl => {
                pl.Stages.Decode
                .ComponentAt <FailedMessageRoutingEnablerComponent>(0).Configure(c => { c.Enabled = false; })
                .ComponentAt <MicroPipelineComponent>(1)
                .Configure(mpc => { mpc.Components = new IMicroComponent[] { new XsltRunner {
                                                                                 MapType = typeof(IdentityTransform)
                                                                             } }; });
                pl.Stages.Disassemble.ComponentAt <XmlDasmComp>(0).Configure(
                    c => {
                    c.DocumentSpecNames = new() {
                        new SchemaWithNone(SchemaMetadata.For <Any>().DocumentSpec.DocSpecStrongName),
                        new SchemaWithNone(SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec.DocSpecStrongName)
                    };
                    c.RecoverableInterchangeProcessing = true;
                });
                pl.Stages.Validate.ComponentAt <MicroPipelineComponent>(0)
                .Configure(mpc => { mpc.Components = new IMicroComponent[] { new XsltRunner {
                                                                                 MapType = typeof(IdentityTransform)
                                                                             } }; });
            });

            var binding5 = pipeline5.GetPipelineBindingInfoSerializer().Serialize();

            binding5.Should().Be(binding);
        }

        [SkippableFact]
        public void StringJoinAssertion()
        {
            using (var stream = _document.AsStream())
            {
                var setup = Given(input => input.Message(stream))
                            .Transform
                            .OutputsXml(output => output.ConformingTo <btf2_services_header>().WithStrictConformanceLevel());

                var result = setup.Validate();

                result.NamespaceManager.AddNamespace("tns", SchemaMetadata.For <btf2_services_header>().TargetNamespace);
                result.StringJoin("//tns:sendBy").Should().Be("2012-04-12T12:13:14#2012-04-12T23:22:21");
            }
        }
        public void XPathAssertion()
        {
            using (var stream = _document.AsStream())
            {
                var setup = Given(input => input.Message(stream))
                            .Transform
                            .OutputsXml(output => output.ConformingTo <btf2_services_header>().WithStrictConformanceLevel());

                var result = setup.Validate();

                result.NamespaceManager.AddNamespace("tns", SchemaMetadata.For <btf2_services_header>().TargetNamespace);
                result.Select("//tns:sendBy").Should().HaveCount(2);
            }
        }
        public void XPathNodeIteratorResultingOfSelectIsEmptyWhenNodeIsNotFound()
        {
            using (var stream = _document.AsStream())
            {
                var setup = Given(input => input.Message(stream))
                            .Transform
                            .OutputsXml(output => output.ConformingTo <btf2_services_header>().WithStrictConformanceLevel());

                var result = setup.Validate();

                result.NamespaceManager.AddNamespace("tns", SchemaMetadata.For <btf2_services_header>().TargetNamespace);
                result.Select("//*[1]/tns:unknown").Should().BeEmpty();
            }
        }
        public void SendPipelineDslGrammarVariant4()
        {
            Skip.IfNot(BizTalkServerGroup.IsConfigured);

            // not fluent-DSL
            var pipeline = new SendPipeline <XmlTransmit>();

            pipeline.Stages.PreAssemble.Component <FailedMessageRoutingEnablerComponent>().Enabled = false;
            pipeline.Stages.PreAssemble.Component <MicroPipelineComponent>().Components            = new IMicroComponent[] { new XsltRunner {
                                                                                                                                 MapType = typeof(IdentityTransform)
                                                                                                                             } };
            pipeline.Stages.Assemble.Component <XmlAsmComp>().DocumentSpecNames = new() {
                new SchemaWithNone(SchemaMetadata.For <Any>().DocumentSpec.DocSpecStrongName),
                new SchemaWithNone(SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec.DocSpecStrongName)
            };
            pipeline.Stages.Assemble.Component <XmlAsmComp>().AddXMLDeclaration    = true;
            pipeline.Stages.Encode.Component <MicroPipelineComponent>().Components = new IMicroComponent[] { new XsltRunner {
                                                                                                                 MapType = typeof(IdentityTransform)
                                                                                                             } };
            var binding = pipeline.GetPipelineBindingInfoSerializer().Serialize();

            // fluent-DSL fourth variant
            var pipeline4 = new SendPipeline <XmlTransmit>(
                pl => {
                pl.Stages.PreAssemble.Components
                .ComponentAt <FailedMessageRoutingEnablerComponent>(0).Configure(c => { c.Enabled = false; })
                .ComponentAt <MicroPipelineComponent>(1)
                .Configure(mpc => { mpc.Components = new IMicroComponent[] { new XsltRunner {
                                                                                 MapType = typeof(IdentityTransform)
                                                                             } }; });
                pl.Stages.Assemble.Components.ComponentAt <XmlAsmComp>(0).Configure(
                    c => {
                    c.DocumentSpecNames = new() {
                        new SchemaWithNone(SchemaMetadata.For <Any>().DocumentSpec.DocSpecStrongName),
                        new SchemaWithNone(SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec.DocSpecStrongName)
                    };
                    c.AddXMLDeclaration = true;
                });
                pl.Stages.Encode.Components.ComponentAt <MicroPipelineComponent>(0)
                .Configure(mpc => { mpc.Components = new IMicroComponent[] { new XsltRunner {
                                                                                 MapType = typeof(IdentityTransform)
                                                                             } }; });
            });
            var binding4 = pipeline4.GetPipelineBindingInfoSerializer().Serialize();

            binding4.Should().Be(binding);
        }

        [SkippableFact]
        public void WritesMessageTypeInContextForKnownSchema()
        {
            var schemaMetadata = SchemaMetadata.For <Any>();

            using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
            {
                PipelineContextMock.Setup(pc => pc.GetDocumentSpecByType("urn:ns#root")).Returns(schemaMetadata.DocumentSpec);
                MessageMock.Object.BodyPart.Data = inputStream;

                var sut = new MessageTypeExtractor();
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                MessageMock.Verify(m => m.SetProperty(BizTalkFactoryProperties.MessageType, schemaMetadata.DocumentSpec.DocType), Times.Once);
            }
        }
コード例 #27
0
        public void DisjunctionOfConjunctionsOfFilters()
        {
            const string token1 = "BizTalkFactory.Batching";
            const int    token2 = 3;

            var filter = new Filter(
                () => BizTalkFactoryProperties.MapTypeName == token1 || BtsProperties.ActualRetryCount > token2 &&
                BtsProperties.MessageType == SchemaMetadata.For <Any>().MessageType
                );

            filter.ToString().Should().Be(
                "<Filter>"
                + $"<Group><Statement Property=\"{BizTalkFactoryProperties.MapTypeName.Type.FullName}\" Operator=\"{(int) FilterOperator.Equals}\" Value=\"{token1}\" /></Group>"
                + $"<Group><Statement Property=\"{BtsProperties.ActualRetryCount.Type.FullName}\" Operator=\"{(int) FilterOperator.GreaterThan}\" Value=\"{token2}\" />"
                + $"<Statement Property=\"{BtsProperties.MessageType.Type.FullName}\" Operator=\"{(int) FilterOperator.Equals}\" Value=\"{SchemaMetadata.For<Any>().MessageType}\" /></Group>"
                + "</Filter>");
        }
        public void SetupFailureExpectationAgainstMessageType()
        {
            _soapStub.As <ISolicitResponse>()
            .Setup(s => s.Request(SchemaMetadata.For <btf2_services_header>().DocumentSpec))
            .Aborts();

            var client = SoapClient <IMessageService> .For(_soapStubHost.Endpoint);

            Invoking(
                () => client.Invoke(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:request",
                        XmlReader.Create(new StringReader(MessageBodyFactory.Create <btf2_services_header>().OuterXml)))))
            .Should().Throw <CommunicationException>();
            client.Abort();
        }
コード例 #29
0
        public void PartitionIsPromoted()
        {
            using (var stream = MessageBody.Samples.Load("Message.BatchContentWithPartition.xml"))
            {
                MessageMock.Object.BodyPart.Data = stream;
                PipelineContextMock
                .Setup(pc => pc.GetDocumentSpecByType(SchemaMetadata.For <Batch.Content>().MessageType))
                .Returns(SchemaMetadata.For <Batch.Content>().DocumentSpec);
                PipelineContextMock
                .Setup(pc => pc.GetDocumentSpecByType(SchemaMetadata.For <Envelope>().MessageType))
                .Returns(SchemaMetadata.For <Envelope>().DocumentSpec);

                var sut = new EnvelopeBuilder();
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                MessageMock.Verify(m => m.Promote(BatchProperties.EnvelopePartition, "p-one"));
            }
        }
コード例 #30
0
        private static MessageBodyCaptureDescriptor AsMessageBodyCaptureDescriptor(this XmlReader reader)
        {
            var document = new XmlDocument();

            document.Load(reader);
            // Claim.Check, Claim.CheckIn, and Claim.CheckOut are all in the same XML Schema: any one can be used to
            // reference the XML Schema TargetNamespace, whatever its specific type
            var nsm = document.GetNamespaceManager();

            nsm.AddNamespace("s0", SchemaMetadata.For <Claim.CheckOut>().TargetNamespace);
            // extract url from claim token
            var urlNode = document.SelectSingleNode("/*/s0:Url", nsm);

            if (urlNode == null)
            {
                throw new ArgumentException($"{document.DocumentElement.IfNotNull(de => de.Name)} token message has no Url element.");
            }
            return(new MessageBodyCaptureDescriptor(urlNode.InnerText, MessageBodyCaptureMode.Claimed));
        }