コード例 #1
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);
                }
            }
        }
コード例 #2
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();
                    }
        }
コード例 #3
0
        public void MessageIsTransformedToEnvelopeViaEnvelopeSpecNameAnnotation()
        {
            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType("urn:ns#root"))
            .Returns(Schema <Any> .DocumentSpec);

            var sut = new EnvelopeBuilder();

            using (var inputStream = ResourceManager.Load("Data.BatchContentWithTransform.xml"))
                using (var transformedStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
                {
                    MessageMock.Object.BodyPart.Data = inputStream;

                    var transformStreamMock = new Mock <ITransformStream>(MockBehavior.Strict);
                    StreamExtensions.StreamTransformerFactory = stream => transformStreamMock.Object;
                    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.VerifyAll();
                }
        }
        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")
                    });
                }
        }
コード例 #5
0
        public void CaptureOfInboundMessagePiggiesBackKernelTransaction()
        {
            using (new TransactionScope())
                using (var stream = new MemoryStream())
                {
                    MessageMock.Object.BodyPart.Data = stream;

                    var transaction = TransactionInterop.GetDtcTransaction(Transaction.Current);
                    PipelineContextMock.As <IPipelineContextEx>()
                    .Setup(pc => pc.GetTransaction())
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    .Returns((IKernelTransaction)transaction);

                    var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                    sut.SetupTracking();

                    ClaimStoreMock.Verify(
                        cs => cs.SetupMessageBodyCapture(
                            It.IsAny <TrackingStream>(),
                            It.IsAny <ActivityTrackingModes>(),
                            // ReSharper disable once SuspiciousTypeConversion.Global
                            It.Is <Func <IKernelTransaction> >(ktf => ReferenceEquals(ktf(), transaction))),
                        Times.Once());
                }
        }
コード例 #6
0
        public void MessageIsProbedForBatchDescriptor()
        {
            var probeStreamMock             = new Mock <IProbeStream>();
            var probeBatchContentStreamMock = probeStreamMock.As <IProbeBatchContentStream>();

            StreamExtensions.StreamProberFactory = stream => probeStreamMock.Object;
            probeStreamMock
            .Setup(ps => ps.MessageType)
            .Returns(Schema <Envelope> .MessageType)
            .Verifiable();
            probeBatchContentStreamMock
            .Setup(ps => ps.BatchDescriptor)
            .Returns(new BatchDescriptor {
                EnvelopeSpecName = new SchemaMetadata <Envelope>().DocumentSpec.DocSpecStrongName
            })
            .Verifiable();

            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Envelope> .DocumentSpec);

            using (var dataStream = ResourceManager.Load("Data.BatchContent.xml"))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                var sut = new EnvelopeBuilder();
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
            }

            probeStreamMock.VerifyAll();
            probeBatchContentStreamMock.VerifyAll();
        }
コード例 #7
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);
                    }
        }
コード例 #8
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();
                    }
        }
コード例 #9
0
        public void CaptureOfOutboundMessageDoesNotPiggyBackKernelTransaction()
        {
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");

            using (new TransactionScope())
                using (var stream = new MemoryStream())
                {
                    MessageMock.Object.BodyPart.Data = stream;

                    var transaction = TransactionInterop.GetDtcTransaction(Transaction.Current);
                    PipelineContextMock.As <IPipelineContextEx>()
                    .Setup(pc => pc.GetTransaction())
                    .Returns((IKernelTransaction)transaction);

                    var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                    sut.SetupTracking();

                    ClaimStoreMock.Verify(
                        cs => cs.SetupMessageBodyCapture(
                            It.IsAny <TrackingStream>(),
                            It.IsAny <ActivityTrackingModes>(),
                            It.Is <Func <IKernelTransaction> >(ktf => ktf == null)),
                        Times.Once());
                }
        }
コード例 #10
0
 public void SetUp()
 {
     PipelineContextMock
     .Setup(pc => pc.GetDocumentSpecByType("urn:ns#root"))
     .Returns(Schema <Any> .DocumentSpec);
     PipelineContextMock
     .Setup(pc => pc.GetDocumentSpecByType("urn-one#letter"))
     .Returns(Schema <Any> .DocumentSpec);
     _schemaMetadataFactory = SchemaBaseExtensions.SchemaMetadataFactory;
 }
        public void ReplaceStreamWhenEnvelopeSchema()
        {
            using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
            {
                PipelineContextMock.Setup(pc => pc.GetDocumentSpecByType("urn:ns#root")).Returns(SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec);
                MessageMock.Object.BodyPart.Data = inputStream;

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

                MessageMock.Object.BodyPart.Data.Should().BeOfType <XmlEnvelopeDecodingStream>();
            }
        }
        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);
            }
        }
コード例 #13
0
        public void PartitionIsPromoted()
        {
            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Batch.Content> .MessageType))
            .Returns(Schema <Batch.Content> .DocumentSpec);
            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Envelope> .DocumentSpec);

            using (var dataStream = ResourceManager.Load("Data.BatchContent.xml"))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                var sut = new EnvelopeBuilder();
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
            }

            MessageMock.Verify(m => m.Promote(BizTalkFactoryProperties.EnvelopePartition, "p-one"));
        }
コード例 #14
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"));
            }
        }
コード例 #15
0
        public void DoesNothingWhenNoSchemaNorPipelineExtractors()
        {
            using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes("<unknown></unknown>")))
            {
                MessageMock.Object.BodyPart.Data = inputStream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.MessageType)).Returns("urn:ns#unknown");

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

                Assert.That(MessageMock.Object.BodyPart.Data, Is.SameAs(inputStream));
                Assert.That(MessageMock.Object.BodyPart.Data, Is.Not.TypeOf <XPathMutatorStream>());
                PipelineContextMock.Verify(pc => pc.ResourceTracker, Times.Once);                 // probing for MessageType calls AsMarkable() which wraps stream

                MessageMock.Verify(m => m.Context.Promote(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>()), Times.Never());
                MessageMock.Verify(m => m.Context.Write(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>()), Times.Never());
            }
        }
コード例 #16
0
        public void OriginalDataStreamIsWrappedInXPathMutatorStreamWhenThereIsXPathExtractors()
        {
            using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
            {
                MessageMock.Object.BodyPart.Data = inputStream;

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

                Assert.That(MessageMock.Object.BodyPart.Data, Is.TypeOf <XPathMutatorStream>());
                // twice: 1st when probing for MessageType calls AsMarkable() which wraps stream, 2nd when wrapping in XPathMutatorStream
                PipelineContextMock.Verify(pc => pc.ResourceTracker, Times.Exactly(2));
            }
        }
        public void OriginalDataStreamIsNotWrappedWhenThereIsNoXPathExtractors()
        {
            using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
            {
                MessageMock.Object.BodyPart.Data = inputStream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.MessageType)).Returns("urn:ns#root");

                var sut = new ContextPropertyExtractor {
                    Extractors = new[] { new ConstantExtractor(BtsProperties.Operation.QName, "operation.name") }
                };
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                MessageMock.Object.BodyPart.Data.Should().BeSameAs(inputStream);
                MessageMock.Object.BodyPart.Data.Should().NotBeOfType <XPathMutatorStream>();

                PipelineContextMock.Verify(pc => pc.ResourceTracker, Times.Once);                 // probing for MessageType calls AsMarkable() which wraps stream
            }
        }
コード例 #18
0
        public void XsltEntailsMessageTypeIsPromoted()
        {
            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>")))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
            }

            MessageMock.Verify(m => m.Promote(BtsProperties.MessageType, SchemaMetadata.For <EdifactServiceSchema.UNB>().MessageType), Times.Once());
            MessageMock.Verify(m => m.Promote(BtsProperties.SchemaStrongName, SchemaMetadata.For <EdifactServiceSchema.UNB>().DocumentSpec.DocSpecStrongName), Times.Once());
        }
コード例 #19
0
        public virtual void XsltEntailsMessageTypeIsPromotedOnlyIfOutputMethodIsXml()
        {
            PipelineContextMock
            .Setup(m => m.GetDocumentSpecByType("urn:ns#root"))
            .Returns(Schema <Batch.Content> .DocumentSpec);

            var sut = CreateXsltRunner();

            sut.Encoding = Encoding.UTF8;
            sut.MapType  = typeof(AnyToText);

            using (var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
            }

            MessageMock.Verify(m => m.Promote(BtsProperties.MessageType, Schema <Batch.Content> .MessageType), Times.Never());
            MessageMock.Verify(m => m.Promote(BtsProperties.SchemaStrongName, new SchemaMetadata <Batch.Content>().DocumentSpec.DocSpecStrongName), Times.Never());
        }
        public void DoesNothingWhenNotBatchContent()
        {
            using (var stream = new StringStream("<root xmlns='ns'></root>"))
            {
                MessageMock.Object.BodyPart.Data = stream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");

                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 BatchContentReleaseActivityTracker();
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                BatchReleaseProcessActivityTrackerMock.Verify(tracker => tracker.TrackActivity(It.IsAny <BatchTrackingContext>()), Times.Never);
            }
        }
コード例 #21
0
        public void XsltEntailsMessageTypeIsPromoted()
        {
            using (var stream = new StringStream("<root xmlns='urn:ns'></root>"))
                using (var transformedStream = stream.Transform().Apply(typeof(IdentityTransform)))
                    using (var probeStreamMockInjectionScope = new ProbeStreamMockInjectionScope())
                        using (var probeBatchContentStreamMockInjectionScope = new ProbeBatchContentStreamMockInjectionScope())
                            using (var transformStreamMockInjectionScope = new TransformStreamMockInjectionScope())
                            {
                                PipelineContextMock
                                .Setup(m => m.GetDocumentSpecByType(SchemaMetadata.For <Envelope>().MessageType))
                                .Returns(SchemaMetadata.For <AddPart>().DocumentSpec);

                                MessageMock.Object.BodyPart.Data = stream;

                                probeStreamMockInjectionScope.Mock
                                .Setup(ps => ps.MessageType)
                                .Returns(SchemaMetadata.For <Envelope>().MessageType);
                                probeBatchContentStreamMockInjectionScope.Mock
                                .Setup(ps => ps.BatchDescriptor)
                                .Returns(new BatchDescriptor {
                                    EnvelopeSpecName = SchemaMetadata.For <Envelope>().DocumentSpec.DocSpecStrongName
                                });

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

                                var sut = new EnvelopeBuilder {
                                    Encoding = Encoding.UTF8, MapType = typeof(IdentityTransform)
                                };
                                sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                                MessageMock.Verify(m => m.Promote(BtsProperties.MessageType, SchemaMetadata.For <AddPart>().MessageType), Times.Once);
                                MessageMock.Verify(m => m.Promote(BtsProperties.MessageType, It.IsAny <string>()), Times.Once);
                                MessageMock.Verify(m => m.Promote(BtsProperties.SchemaStrongName, SchemaMetadata.For <AddPart>().DocumentSpec.DocSpecStrongName), Times.Once);
                                MessageMock.Verify(m => m.Promote(BtsProperties.SchemaStrongName, It.IsAny <string>()), Times.Once);
                            }
        }
コード例 #22
0
        public override void ReplacesMessageOriginalDataStreamWithTransformResult()
        {
            var probeStreamMock             = new Mock <IProbeStream>();
            var probeBatchContentStreamMock = probeStreamMock.As <IProbeBatchContentStream>();

            probeStreamMock
            .Setup(ps => ps.MessageType)
            .Returns(Schema <Envelope> .MessageType);
            probeBatchContentStreamMock
            .Setup(ps => ps.BatchDescriptor)
            .Returns(new BatchDescriptor {
                EnvelopeSpecName = new SchemaMetadata <Envelope>().DocumentSpec.DocSpecStrongName
            });
            StreamExtensions.StreamProberFactory = stream => probeStreamMock.Object;

            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Envelope> .DocumentSpec);

            base.ReplacesMessageOriginalDataStreamWithTransformResult();
        }
コード例 #23
0
        public override void XsltEntailsMessageTypeIsPromoted()
        {
            PipelineContextMock
            .Setup(m => m.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Batch.Content> .DocumentSpec);

            var probeStreamMock             = new Mock <IProbeStream>();
            var probeBatchContentStreamMock = probeStreamMock.As <IProbeBatchContentStream>();

            probeStreamMock
            .Setup(ps => ps.MessageType)
            .Returns(Schema <Envelope> .MessageType);
            probeBatchContentStreamMock
            .Setup(ps => ps.BatchDescriptor)
            .Returns(new BatchDescriptor {
                EnvelopeSpecName = new SchemaMetadata <Envelope>().DocumentSpec.DocSpecStrongName
            });
            StreamExtensions.StreamProberFactory = stream => probeStreamMock.Object;

            base.XsltEntailsMessageTypeIsPromoted();
        }
コード例 #24
0
        public override void XsltFromContextHasPrecedenceOverConfiguredOne()
        {
            var probeStreamMock             = new Mock <IProbeStream>();
            var probeBatchContentStreamMock = probeStreamMock.As <IProbeBatchContentStream>();

            probeStreamMock
            .Setup(ps => ps.MessageType)
            .Returns(Schema <Envelope> .MessageType);
            probeBatchContentStreamMock
            .Setup(ps => ps.BatchDescriptor)
            .Returns(new BatchDescriptor {
                EnvelopeSpecName = new SchemaMetadata <Envelope>().DocumentSpec.DocSpecStrongName
            });
            StreamExtensions.StreamProberFactory = stream => probeStreamMock.Object;

            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Envelope> .DocumentSpec);

            base.XsltFromContextHasPrecedenceOverConfiguredOne();
        }
コード例 #25
0
        public void TrackBatchReleaseProcessActivity()
        {
            BatchReleaseProcessActivityTrackerMock     = new Mock <BatchReleaseProcessActivityTracker>(PipelineContextMock.Object, MessageMock.Object);
            BatchReleaseProcessActivityTracker.Factory = (pipelineContext, message) => BatchReleaseProcessActivityTrackerMock.Object;

            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Batch.Content> .MessageType))
            .Returns(Schema <Batch.Content> .DocumentSpec);
            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Envelope> .DocumentSpec);

            var sut = CreateActivityTracker();

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

            BatchReleaseProcessActivityTrackerMock.Verify(brpat => brpat.TrackActivity(It.IsAny <BatchTrackingContext>()), Times.Once());

            MessageMock.Verify(m => m.SetProperty(TrackingProperties.Value1, new SchemaMetadata <Envelope>().DocumentSpec.DocSpecStrongName));
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.Value2, "environment-tag"));
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.Value3, "p-one"));
        }
        public void ProbeAndPromoteMessageTypeIfKnown()
        {
            PipelineContextMock
            .Setup(m => m.GetDocumentSpecByType("urn:ns:translated#root"))
            .Returns(SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec);

            using (var dataStream = new MemoryStream(Encoding.UTF8.GetBytes("<root xmlns='urn:ns'></root>")))
            {
                var sut = new XmlTranslator {
                    Translations = new() {
                        Items = new[] {
                            new XmlNamespaceTranslation("urn:ns", "urn:ns:translated")
                        }
                    }
                };
                MessageMock.Object.BodyPart.Data = dataStream;
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
            }

            MessageMock.Verify(m => m.Promote(BtsProperties.MessageType, SchemaMetadata.For <soap_envelope_1__2.Envelope>().MessageType), Times.Once());
            MessageMock.Verify(m => m.Promote(BtsProperties.SchemaStrongName, SchemaMetadata.For <soap_envelope_1__2.Envelope>().DocumentSpec.DocSpecStrongName), Times.Once());
        }
コード例 #27
0
        public void XsltFromContextHasPrecedenceOverConfiguredOne()
        {
            using (var stream = new StringStream("<root xmlns='urn:ns'></root>"))
                using (var transformedStream = stream.Transform().Apply(typeof(IdentityTransform)))
                    using (var transformStreamMockInjectionScope = new TransformStreamMockInjectionScope())
                        using (var probeBatchContentStreamMockInjectionScope = new ProbeBatchContentStreamMockInjectionScope())
                        {
                            PipelineContextMock
                            .Setup(pc => pc.GetDocumentSpecByType("urn:ns#root"))
                            .Returns(SchemaMetadata.For <Any>().DocumentSpec);

                            MessageMock.Object.BodyPart.Data = stream;
                            MessageMock
                            .Setup(m => m.GetProperty(BizTalkFactoryProperties.MapTypeName))
                            .Returns(typeof(IdentityTransform).AssemblyQualifiedName);

                            probeBatchContentStreamMockInjectionScope.Mock
                            .Setup(ps => ps.BatchDescriptor)
                            .Returns(new BatchDescriptor {
                                EnvelopeSpecName = SchemaMetadata.For <Envelope>().DocumentSpec.DocSpecStrongName
                            });

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

                            var sut = new EnvelopeBuilder {
                                Encoding = Encoding.UTF8, MapType = typeof(TransformBase)
                            };
                            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                            transformStreamMockInjectionScope.Mock.Verify(ts => ts.Apply(sut.MapType, sut.Encoding), Times.Never);
                            transformStreamMockInjectionScope.Mock.VerifyAll();
                        }
        }
コード例 #28
0
        public void MessageIsProbedForBatchDescriptor()
        {
            using (var stream = MessageBody.Samples.Load("Message.BatchContent.xml"))
                using (var probeBatchContentStreamMockInjectionScope = new ProbeBatchContentStreamMockInjectionScope())
                {
                    MessageMock.Object.BodyPart.Data = stream;
                    PipelineContextMock
                    .Setup(pc => pc.GetDocumentSpecByType(SchemaMetadata.For <Envelope>().MessageType))
                    .Returns(SchemaMetadata.For <Envelope>().DocumentSpec);

                    probeBatchContentStreamMockInjectionScope.Mock
                    .Setup(ps => ps.BatchDescriptor)
                    .Returns(new BatchDescriptor {
                        EnvelopeSpecName = SchemaMetadata.For <Envelope>().DocumentSpec.DocSpecStrongName
                    })
                    .Verifiable();

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

                    probeBatchContentStreamMockInjectionScope.Mock.VerifyAll();
                }
        }
コード例 #29
0
        public void BatchContentIsTransformedToSpecificEnvelope()
        {
            string actualEnvelopeContent;
            string expectedEnvelopeContent;
            var    sut = new EnvelopeBuilder();

            var envelopeStream = new StringStream(MessageFactory.CreateEnvelope <Envelope>().OuterXml);
            var batchStream = new StringStream(MessageFactory.CreateMessage <Batch.Content>(ResourceManager.LoadString("Data.BatchContent.xml")).OuterXml);
            var transformedStream = new Stream[] { envelopeStream, batchStream }.Transform().Apply(sut.MapType, sut.Encoding);

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

            PipelineContextMock
            .Setup(pc => pc.GetDocumentSpecByType(Schema <Envelope> .MessageType))
            .Returns(Schema <Envelope> .DocumentSpec);

            using (var dataStream = ResourceManager.Load("Data.BatchContent.xml"))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
                using (var actualReader = XmlReader.Create(MessageMock.Object.BodyPart.Data, new XmlReaderSettings {
                    CloseInput = true, IgnoreWhitespace = true
                }))
                {
                    actualReader.Read();
                    actualEnvelopeContent = actualReader.ReadOuterXml();
                }
            }

            Assert.That(actualEnvelopeContent, Is.EqualTo(expectedEnvelopeContent));
        }
コード例 #30
0
        public void ReplacesMessageOriginalDataStreamWithTransformResult()
        {
            using (var stream = new StringStream("<root xmlns='urn:ns'></root>"))
                using (var transformedStream = stream.Transform().Apply(typeof(IdentityTransform)))
                    using (var probeBatchContentStreamMockInjectionScope = new ProbeBatchContentStreamMockInjectionScope())
                        using (var transformStreamMockInjectionScope = new TransformStreamMockInjectionScope())
                        {
                            MessageMock.Object.BodyPart.Data = stream;
                            PipelineContextMock
                            .Setup(pc => pc.GetDocumentSpecByType("urn:ns#root"))
                            .Returns(SchemaMetadata.For <Any>().DocumentSpec);

                            probeBatchContentStreamMockInjectionScope.Mock
                            .Setup(ps => ps.BatchDescriptor)
                            .Returns(new BatchDescriptor {
                                EnvelopeSpecName = SchemaMetadata.For <Envelope>().DocumentSpec.DocSpecStrongName
                            });

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

                            var sut = new EnvelopeBuilder {
                                Encoding = Encoding.UTF8, MapType = typeof(IdentityTransform)
                            };
                            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

                            transformStreamMockInjectionScope.Mock.VerifyAll();

                            Reflector.GetField(MessageMock.Object.BodyPart.Data.AsMarkable(), "m_data").Should().BeSameAs(transformedStream);
                            MessageMock.Object.BodyPart.Data.Should().BeOfType <MarkableForwardOnlyEventingReadStream>();
                        }
        }