|
| 1 | +using System; |
| 2 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 3 | +using Winterdom.BizTalk.PipelineTesting; |
| 4 | +using BizTalkComponents.PipelineComponents.ConcatContextProperties; |
| 5 | + |
| 6 | +namespace TestConcatContextProperties |
| 7 | +{ |
| 8 | + [TestClass] |
| 9 | + public class UnitTest1 |
| 10 | + { |
| 11 | + [TestMethod] |
| 12 | + public void TestConcatProperties() |
| 13 | + { |
| 14 | + var pipeline = PipelineFactory.CreateEmptySendPipeline(); |
| 15 | + pipeline.AddComponent(new ConcatContextProperties |
| 16 | + { |
| 17 | + PropertyPath="https://schemas.company.com/propertyschema#concatenatedValue", |
| 18 | + PromoteProperty=true, |
| 19 | + Parameters= "\"Abc\",{https://schemas.company.com/propertyschema#property1},{https://schemas.company.com/propertyschema#property2},\"jkl\"", |
| 20 | + |
| 21 | + }, PipelineStage.PreAssemble); |
| 22 | + var msg = MessageHelper.CreateFromString(""); |
| 23 | + msg.Context.Promote("property1", "https://schemas.company.com/propertyschema", "def"); |
| 24 | + msg.Context.Promote("property2", "https://schemas.company.com/propertyschema", "ghi"); |
| 25 | + var output = pipeline.Execute(msg); |
| 26 | + string concatenatedValue = (string)output.Context.Read("concatenatedValue", "https://schemas.company.com/propertyschema"); |
| 27 | + Assert.AreEqual(concatenatedValue, "Abcdefghijkl"); |
| 28 | + } |
| 29 | + |
| 30 | + [TestMethod] |
| 31 | + public void TestPropertyNotExisted() |
| 32 | + { |
| 33 | + var pipeline = PipelineFactory.CreateEmptySendPipeline(); |
| 34 | + pipeline.AddComponent(new ConcatContextProperties |
| 35 | + { |
| 36 | + PropertyPath = "https://schemas.company.com/propertyschema#concatenatedValue", |
| 37 | + PromoteProperty = true, |
| 38 | + Parameters = "\"Abc\",{https://schemas.company.com/propertyschema#property1},{https://schemas.company.com/propertyschema#property2},\"123\"", |
| 39 | + }, PipelineStage.PreAssemble); |
| 40 | + var msg = MessageHelper.CreateFromString(""); |
| 41 | + msg.Context.Promote("property1", "https://schemas.company.com/propertyschema", "def"); |
| 42 | + var output = pipeline.Execute(msg); |
| 43 | + string concatenatedValue = (string)output.Context.Read("concatenatedValue", "https://schemas.company.com/propertyschema"); |
| 44 | + Assert.AreEqual(concatenatedValue, "Abcdef123"); |
| 45 | + } |
| 46 | + [TestMethod, ExpectedException(typeof(ArgumentException))] |
| 47 | + public void TestPropertyNotExistedThrowException() |
| 48 | + { |
| 49 | + var pipeline = PipelineFactory.CreateEmptySendPipeline(); |
| 50 | + pipeline.AddComponent(new ConcatContextProperties |
| 51 | + { |
| 52 | + PropertyPath = "https://schemas.company.com/propertyschema#concatenatedValue", |
| 53 | + PromoteProperty = true, |
| 54 | + Parameters = "\"Abc\",{https://schemas.company.com/propertyschema#property1},{https://schemas.company.com/propertyschema#property2},\"123\"", |
| 55 | + ThrowException=true |
| 56 | + }, PipelineStage.PreAssemble); |
| 57 | + var msg = MessageHelper.CreateFromString(""); |
| 58 | + msg.Context.Promote("property1", "https://schemas.company.com/propertyschema", "def"); |
| 59 | + var output = pipeline.Execute(msg); |
| 60 | + string concatenatedValue = (string)output.Context.Read("concatenatedValue", "https://schemas.company.com/propertyschema"); |
| 61 | + Assert.AreEqual(concatenatedValue, "Abcdef123"); |
| 62 | + } |
| 63 | + |
| 64 | + [TestMethod, ExpectedException(typeof(ArgumentException))] |
| 65 | + public void TestConcatPropertiesWrongParameters() |
| 66 | + { |
| 67 | + var pipeline = PipelineFactory.CreateEmptySendPipeline(); |
| 68 | + pipeline.AddComponent(new ConcatContextProperties |
| 69 | + { |
| 70 | + PropertyPath = "https://schemas.company.com/propertyschema#concatenatedValue", |
| 71 | + PromoteProperty = true, |
| 72 | + Parameters = "\"Abc,{https://schemas.company.com/propertyschema#property1},{https://schemas.company.com/propertyschema#property2},\"jkl\"", |
| 73 | + |
| 74 | + }, PipelineStage.PreAssemble); |
| 75 | + var msg = MessageHelper.CreateFromString(""); |
| 76 | + msg.Context.Promote("property1", "https://schemas.company.com/propertyschema", "def"); |
| 77 | + msg.Context.Promote("property2", "https://schemas.company.com/propertyschema", "ghi"); |
| 78 | + var output = pipeline.Execute(msg); |
| 79 | + string concatenatedValue = (string)output.Context.Read("concatenatedValue", "https://schemas.company.com/propertyschema"); |
| 80 | + Assert.AreEqual(concatenatedValue, "Abcdefghijkl"); |
| 81 | + } |
| 82 | + |
| 83 | + [TestMethod] |
| 84 | + public void TestSpecialCharacters() |
| 85 | + { |
| 86 | + var pipeline = PipelineFactory.CreateEmptySendPipeline(); |
| 87 | + pipeline.AddComponent(new ConcatContextProperties |
| 88 | + { |
| 89 | + PropertyPath = "https://schemas.company.com/propertyschema#concatenatedValue", |
| 90 | + PromoteProperty = true, |
| 91 | + Parameters = "{https://schemas.company.com/propertyschema#property1},\"he{LF}l{CR}lo{CRLF}Wor{TAB}ld\"", |
| 92 | + |
| 93 | + }, PipelineStage.PreAssemble); |
| 94 | + var msg = MessageHelper.CreateFromString(""); |
| 95 | + msg.Context.Promote("property1", "https://schemas.company.com/propertyschema", "def"); |
| 96 | + msg.Context.Promote("property2", "https://schemas.company.com/propertyschema", "ghi"); |
| 97 | + var output = pipeline.Execute(msg); |
| 98 | + string concatenatedValue = (string)output.Context.Read("concatenatedValue", "https://schemas.company.com/propertyschema"); |
| 99 | + Assert.AreEqual(concatenatedValue, "defhe\nl\rlo\r\nWor\tld"); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments