Search code examples
c#unit-testingvisual-studio-2019biztalkbiztalk-2020

Unit test BizTalk 2020 artefacts using Visual Studio 2019 leads to Intellisense issue


I encounter an issue when trying to use unit testing for BizTalk 2020 artefacts in Visual Studio 2019.

Here are the steps I have followed :

  • I create new empty BizTalk project "Testing" and configure it for unit testing in project properties.
  • I create a folder in the project named "Pipelines"
  • In this folder I create a receive pipeline "ppr_Testing.btp" with a single "XML disassembler" component.
  • I create new unit testing project "_Test"
  • In "_Test" project, I add a project reference to "Testing"
  • In the unit testing project, I create a unit test and try to write code to instanciate "ppr_Testing" pipeline
using Testing.Pipelines;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace _Test
{
    
    /// <summary>
    ///This is a test class for Test_ppr_Testing and is intended
    ///to contain all Test_ppr_Testing Unit Tests
    ///</summary>
    [TestClass()]
    public class Test_ppr_Testing
    {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        ///A test for ppr_Testing Constructor
        ///</summary>
        [TestMethod()]
        public void Test_ppr_TestingConstructor()
        {
            ppr_Testing target = new ppr_Testing();

            var lDocuments = new System.Collections.Specialized.StringCollection();
            lDocuments.Add(@"C:\MyTestDirectory\SomeFile.xml");

            var lParts = new System.Collections.Specialized.StringCollection();
            var lSchemas = new System.Collections.Generic.Dictionary<string, string>();

            try
            {
                target.TestPipeline(lDocuments, lParts, lSchemas);
                var lTmp = this.TestContext;
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
    }
}

Result :

  • The code is underlined in error because the object is not recognized by Intellisense
  • If I manage to write the testing code without Intellisense, it compiles and runs successfuly

Intellisense error 1

Intellisense error 2

Am I doing something wrong, or is my Visual Studio 2019 installation corrupted ?

I'm in the process of migrating from BizTalk 2010 to BizTalk 2020, and with BizTalk 2010 and Visual Studio 2010 things were easier :

  • I just go to "Test" menu, "New Test...", then "Unit Test Wizard", and follow the wizard, and everything is OK.

Thanks in advance for any help.


Solution

  • When building a BizTalk project with BizTalk artefacts in it (btm/btp/xsd), BizTalk will generate .cs files for those files in the project. The generated .cs files are not automatically added to the project itself, and this causes Intellisense in the unit test project to not being able to "see" the types. If you include the .cs files and rebuild, the issue should go away. However note that adding the generated the cs files to the project and to a code repository can introduce issues when building due to locked files.