1

尝试在 Visual Studio 2019 中对 BizTalk 2020 工件进行单元测试时遇到问题。

以下是我遵循的步骤:

  • 我创建新的空 BizTalk 项目“测试”并将其配置为在项目属性中进行单元测试。
  • 我在名为“管道”的项目中创建了一个文件夹
  • 在这个文件夹中,我创建了一个带有单个“XML 反汇编器”组件的接收管道“ppr_Testing.btp”。
  • 我创建了新的单元测试项目“_Test”
  • 在“_Test”项目中,我添加了对“Testing”的项目引用
  • 在单元测试项目中,我创建了一个单元测试并尝试编写代码来实例化“ppr_Testing”管道
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());
            }
        }
    }
}

结果 :

  • 代码有错误下划线,因为 Intellisense 无法识别该对象
  • 如果我设法在没有 Intellisense 的情况下编写测试代码,它将成功编译并运行

智能感知错误 1

智能感知错误 2

我做错了什么,还是我的 Visual Studio 2019 安装已损坏?

我正在从 BizTalk 2010 迁移到 BizTalk 2020,并且使用 BizTalk 2010 和 Visual Studio 2010 事情变得更容易:

  • 我只是转到“测试”菜单,“新建测试...”,然后是“单元测试向导”,然后按照向导进行操作,一切正常。

提前感谢您的帮助。

4

1 回答 1

0

在构建包含 BizTalk 工件 (btm/btp/xsd) 的 BizTalk 项目时,BizTalk 将为项目中的这些文件生成 .cs 文件。生成的 .cs 文件不会自动添加到项目本身,这会导致单元测试项目中的 Intellisense 无法“看到”类型。如果您包含 .cs 文件并重新构建,该问题应该会消失。但是请注意,将生成的 cs 文件添加到项目和代码存储库中可能会在构建时由于文件锁定而引入问题。

于 2021-12-07T10:13:25.353 回答