다음을 통해 공유


파이프라인에 단위 테스트 기능 사용

이 항목에서는 FlatFileReceive 파이프라인 예제에서 단위 테스트 기능을 사용하여 파이프라인에 대한 단위 테스트를 추가하는 방법을 설명합니다. 파이프라인 단위 테스트는 파이프라인 도구에 설명된 Pipeline.exe 도구와 유사 합니다. 프로젝트 속성의 배포 탭에서 단위 테스트를 사용하도록 설정하면 프로젝트의 파이프라인 클래스는 Microsoft.BizTalk.TestTools.Pipeline.TestableReceivePipeline에서 파생됩니다. 이 클래스는 Pipeline.exe 도구에서 노출하는 기능의 일부를 모델링합니다.

필수 구성 요소

먼저 FlatFileReceive 샘플을 빌드하는 단계를 수행하고 이 샘플에 익숙해져야 합니다. FlatFileReceive 샘플을 빌드하는 단계를 포함하는 설명서는 FlatFileReceive(BizTalk Server 샘플)에서 찾을 수 있습니다.

FlatFileReceive 샘플에 단위 테스트 프로젝트 추가

FlatFileReceive 샘플에 단위 테스트 프로젝트를 추가하려면

  1. Visual Studio에서 FlatFileReceive.sln 솔루션 파일을 엽니다.

  2. 솔루션 탐색기 FlatFileReceive 프로젝트를 마우스 오른쪽 단추로 클릭한 다음 속성을 클릭합니다.

  3. 프로젝트 Designer 배포 속성 페이지 탭을 클릭하고 단위 테스트 사용을True설정합니다.

  4. 변경 내용을 저장하고 프로젝트 속성 페이지를 닫습니다.

  5. 기본 메뉴에서 빌드를 클릭한 다음 솔루션 다시 빌드를 클릭합니다.

  6. 기본 메뉴에서 테스트를 클릭한 다음 새 테스트를 클릭합니다.

  7. 새 테스트 추가 대화 상자에서 테스트 프로젝트에 추가 필드에 대해 새 Visual C# 테스트 프로젝트 만들기 선택합니다. 템플릿 목록에서 단위 테스트 마법사 선택한 다음 확인을 클릭합니다.

  8. 새 테스트 프로젝트 대화 상자에서 프로젝트 이름을 TestProject1로 두고 만들기를 클릭합니다.

  9. 단위 테스트 만들기 대화 상자에서 형식을 확장하고 Microsoft.Samples.BizTalk.FlatFileReceive.FFReceivePipeline 노드에서 FFReceivePipeline() 생성자를 선택합니다. 확인을 클릭합니다.

파이프라인을 테스트할 테스트 코드 추가

파이프라인을 테스트할 테스트 코드를 추가하려면

  1. TestProject1 프로젝트에 다음 참조를 추가합니다.

    • BizTalk 파이프라인 Interop

    • Microsoft.BizTalk.TestTools

    • Microsoft XLANG/s 기본 유형

  2. 솔루션 탐색기에서 FFReceivePipelineTest.cs를 열고 이 파일의 맨 위에 다음 지시문을 추가합니다.

    using System.IO;
    using System.Collections.Specialized;
    using System.Collections.Generic;
    
  3. 파일 아래쪽으로 스크롤하여 FFReceivePipelineConstructorTest 메서드를 다음 코드로 바꿉니다. 이 코드는 파이프라인을 테스트하기 전에 파이프라인 입력이 있는지 확인합니다. 또한 플랫 파일 스키마에 맞는 메시지가 생성되었는지 확인합니다.

    [TestMethod()]
    public void FFReceivePipelineUnitTest()
    {
        //=== Pipeline class derived from TestableReceivePipeline ===//
        FFReceivePipeline target = new FFReceivePipeline();
    
        //=== Collection of messages to test the flat file pipeline ===//
        StringCollection documents = new StringCollection();
        string strSourcePO_XML = @".\..\..\..\FlatFileReceive_in.txt";
        Assert.IsTrue(File.Exists(strSourcePO_XML));
        documents.Add(strSourcePO_XML);
    
        //=== Only a body part for this test message so an empty ===//
        //=== collection will be passed.                         ===//
        StringCollection parts = new StringCollection();
    
        //=== Dictionary mapping the schema to the namespace and type ===//
        //=== as displayed in the properties window for the *.xsd     ===//
        Dictionary<string, string> schemas = new Dictionary<string, string>();
        string SchemaFile = @".\..\..\..\PO.xsd";
        Assert.IsTrue(File.Exists(SchemaFile));
        schemas.Add("Microsoft.Samples.BizTalk.FlatFileReceive.PO", SchemaFile);
    
        //=== Test the execution of the pipeline using the inputs ===//
        target.TestPipeline(documents, parts, schemas);
    
        //=== Validate that the pipeline test produced the message ===//
        //=== which conforms to the schema.                        ===//
        string[] strMessages = Directory.GetFiles(testContextInstance.TestDir + "\\out","Message*.out");
        Assert.IsTrue(strMessages.Length > 0);
        PO PO_target = new PO();
        foreach(string outFile in strMessages)
        {
          Assert.IsTrue(PO_target.ValidateInstance(outFile,Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML));
        }
    }
    

단위 테스트 빌드 및 실행

단위 테스트를 빌드 및 실행하려면

  1. 솔루션 탐색기 TestProject1을 마우스 오른쪽 단추로 클릭한 다음 빌드를 클릭합니다.

  2. 기본 메뉴에서 테스트를 클릭한 다음 Windows 목록에서 테스트 보기를 클릭합니다.

  3. 테스트 보기 창에서 FFReceivePipelineUnitTest를 마우스 오른쪽 단추로 클릭한 다음 선택 영역 실행을 클릭합니다. 테스트 결과 창에 통과됨 이 표시되는지 확인합니다.

  4. TestResults 디렉터리에서 *.out 파일을 확인합니다. 이 파일에는 파이프라인에서 처리한 새 메시지가 포함되어 있어야 합니다. 이 파일은 다음과 같은 디렉터리에 있습니다.

    C:\Program Files\Microsoft BizTalk Server <version>\SDK\Samples\Pipelines\AssemblerDisassembler\FlatFileReceive\TestResults\Wes_BTS2009Svr 2009-02-04 09_01_04\Out

    처리된 메시지는 다음과 같이 표시됩니다.

    <purchaseOrder orderDate="1999-10-20" xmlns="http://FlatFileReceive.PO">
    
      <shipTo country="US" xmlns="">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
      </shipTo>
    
      <billTo country="US" xmlns="">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
      </billTo>
    
      <comment>Hurry, my lawn is going wild!</comment>
    
      <items xmlns="">
    
        <item partNum="872-AA">
          <productName>Lawnmower</productName>
          <quantity>1</quantity>
          <USPrice>148.95</USPrice>
          <comment xmlns="http://FlatFileReceive.PO">Confirm this is electric</comment>
        </item>
    
        <item partNum="926-AA">
          <productName>Baby Monitor</productName>
          <quantity>1</quantity>
          <USPrice>39.98</USPrice>
          <comment xmlns="http://FlatFileReceive.PO">Confirm this is electric</comment>
          <shipDate>1999-05-21</shipDate>
        </item>
    
      </items>
    
    </purchaseOrder>
    
  5. 테스트에 실패한 경우 테스트 결과 창에서 테스트를 두 번 클릭하여 테스트 실패의 원인인 어설션 또는 예외를 확인할 수 있습니다.

테스트 코드 요약

FlatFileReceive 프로젝트에 단위 테스트를 사용하도록 설정했을 때 FFReceivePipeline.btp와 연결된 FFReceivePipeline C# 클래스는 Microsoft.BizTalk.TestTools.Pipeline.TestableReceivePipeline 클래스에서 파생되었습니다. TestProject1FFReceivePipelineUnitTest 메서드는 FFReceivePipeline이 상속한 TestPipeline 메서드를 사용하여 플랫 파일 수신 파이프라인을 테스트했습니다. 파이프라인에서 메시지를 처리한 후 플랫 파일 스키마에 대해 출력 메시지의 유효성이 검사되었습니다. TestPipeline 메서드의 매개 변수는 다음과 같습니다.

매개 변수 이름 설명
문서 파이프라인에서 처리할 메시지가 포함된 StringCollection입니다.
부분 메시지 파트가 포함된 StringCollection입니다.
스키마 각 메시지 유형을 *.xsd 스키마 파일에 매핑하는 데 사용되는 사전 매핑입니다. 키는 Namespace.Type 형식이어야 합니다. 사용되는 네임스페이스 및 형식은 Visual Studio의 *.xsd 파일에 대한 속성 창에서 기록해야 합니다. 아래 스크린샷을 참조하세요.

선택한 XSD 파일의 네임스페이스 및 형식을 강조 표시하는 이미지입니다.

XSD 파일의 속성 창에 노출된 네임스페이스 및 유형

참고 항목

단위 테스트 기능과 스키마 및단위 테스트 작업 맵 사용(Visual Studio)