Esempio n. 1
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());
            }
        }
Esempio n. 2
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
            }
        }