public void MessageContextManipulationsAreDelegatedToPropertyExtractors() { const string content = "<s1:letter xmlns:s1=\"urn-one\">" + "<s1:headers><s1:subject>inquiry</s1:subject></s1:headers>" + "<s1:body>" + "<s1:paragraph>paragraph-one</s1:paragraph>" + "<s1:footer>trail</s1:footer>" + "</s1:body>" + "</s1:letter>"; using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(content))) { var propertyExtractorMock = new Mock <PropertyExtractor>(BizTalkFactoryProperties.SenderName.QName, ExtractionMode.Clear) { CallBase = true }; var constantExtractorMock = new Mock <ConstantExtractor>(TrackingProperties.Value2.QName, "value2", ExtractionMode.Write) { CallBase = true }; var xpathExtractorMock = new Mock <XPathExtractor>(TrackingProperties.Value1.QName, "/*[local-name()='letter']/*/*[local-name()='paragraph']", ExtractionMode.Write) { CallBase = true }; var annotationsMock = new Mock <ISchemaAnnotations>(); annotationsMock.Setup(am => am.Extractors).Returns( new PropertyExtractorCollection( propertyExtractorMock.Object, constantExtractorMock.Object )); SchemaMetadataMock = new Mock <ISchemaMetadata>(); SchemaMetadataMock.Setup(sm => sm.Annotations).Returns(annotationsMock.Object); SchemaBaseExtensions.SchemaMetadataFactory = type => SchemaMetadataMock.Object; MessageMock.Object.BodyPart.Data = inputStream; MessageMock.Setup(m => m.GetProperty(BtsProperties.MessageType)).Returns("urn-one#letter"); var sut = new ContextPropertyExtractor { Extractors = new[] { new XPathExtractor(TrackingProperties.ProcessName.QName, "/*[local-name()='letter']/*/*[local-name()='subject']", ExtractionMode.Promote), xpathExtractorMock.Object, new XPathExtractor(TrackingProperties.Value3.QName, "/*[local-name()='letter']/*/*[local-name()='footer']") } }; sut.Execute(PipelineContextMock.Object, MessageMock.Object); MessageMock.Object.BodyPart.Data.Drain(); propertyExtractorMock.Verify(pe => pe.Execute(MessageMock.Object.Context)); constantExtractorMock.Verify(pe => pe.Execute(MessageMock.Object.Context)); //var newValue = "paragraph-one"; // TODO not supported by moq xpathExtractorMock.Verify(pe => pe.Execute(MessageMock.Object.Context, "paragraph-one", ref newValue)); MessageMock.Verify(m => m.SetProperty(BizTalkFactoryProperties.SenderName, null)); MessageMock.Verify(m => m.SetProperty(TrackingProperties.Value1, "paragraph-one")); MessageMock.Verify(m => m.SetProperty(TrackingProperties.Value2, "value2")); MessageMock.Verify(m => m.SetProperty(TrackingProperties.Value3, "trail")); MessageMock.Verify(m => m.Promote(TrackingProperties.ProcessName, "inquiry")); } }
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 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()); } }
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(TrackingProperties.ProcessName.QName, "process.name") } }; 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 } }