none
Bug in BizTalk Logical AND functoid (External Assembly version only) RRS feed

  • General discussion

  • Since BizTalk 2006 (or possibly r2) the logical and functoid has contained a bug in the external assembly method.  Normally you would use the inline C#, but if you prioritise the external assembly script type, you will run into this.  The code is simply incorrect and the functoid will almost always return false.

    It's easy enough to demonstrate, you can build a trivial map with a logical and in it and test it, then change the script type preference and re-test it.

    I've checked the IL for the method and it's clearly incorrect.

    The code for BizTalk 2004 appears to have been correct, but it looks like it was refactored in 2006 to make use of the Boolean.TryParse method and avoid a try..catch block.

    I honestly don't know why anyone would want to prioritise external assemblies over inline code. I only found this problem because I was trying to be thorough with my unit testing.


    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Microsoft.BizTalk.BaseFunctoids;
    
    namespace UnitTests
    {
        [TestClass]
        public class MSLogicalAnd
        {
            [TestMethod]
            public void TrueTrue()
            {
                Assert.IsTrue(new FunctoidScripts().LogicalAnd("true", "true")); // Test Fails
            }
    
            [TestMethod]
            public void TrueFalse()
            {
                Assert.IsFalse(new FunctoidScripts().LogicalAnd("true", "false"));
            }
            [TestMethod]
            public void FalseFalse()
            {
                Assert.IsFalse(new FunctoidScripts().LogicalAnd("false", "false"));
            }
    
            [TestMethod]
            public void FalseTrue()
            {
                Assert.IsFalse(new FunctoidScripts().LogicalAnd("false", "true"));
            }
    
            [TestMethod]
            public void OneOne()
            {
                Assert.IsTrue(new FunctoidScripts().LogicalAnd("1", "1")); // Test Fails
            }
            [TestMethod]
            public void OneZero()
            {
                Assert.IsFalse(new FunctoidScripts().LogicalAnd("1", "0"));
            }
            [TestMethod]
            public void ZeroOne()
            {
                Assert.IsFalse(new FunctoidScripts().LogicalAnd("0", "1"));
            }
            [TestMethod]
            public void ZeroZero()
            {
                Assert.IsFalse(new FunctoidScripts().LogicalAnd("0", "0"));
            }
    
            [TestMethod]
            public void TrueOne()
            {
                Assert.IsTrue(new FunctoidScripts().LogicalAnd("true", "1")); // Test Fails
            }
    
            [TestMethod]
            public void OneTrue()
            {
                Assert.IsTrue(new FunctoidScripts().LogicalAnd("1", "true")); // Test Fails
            }
        }
    }
    

    • Edited by carbon14 Friday, June 16, 2017 10:59 AM Added some unit test code
    Friday, June 16, 2017 9:17 AM