2015-09-01 26 views
1

我正在爲BizTalk實施單元測試。BizTalk數據庫查找functoid - 單元測試

我能夠單元測試BizTalk地圖,只要它不包含外部functoids,如Database Lookup

有什麼辦法可以僞造Database Lookup functoid,這樣我就可以正確地對我的BizTalk地圖進行單元測試了嗎?

我試過http://truenorthit.co.uk/2014/11/17/unit-testing-biztalk-maps-external-functoids/上的建議解決方案,但沒有成功。

我也試圖找到一種方法來使用Microsoft Fakes,但我找不到我需要僞造哪個組件。

回答

0

編輯:我第一次嘗試回答沒有奏效。這個呢。

我只有VS 2010在我的BizTalk虛擬機上,所以這是與痣,但它應該與我希望的假貨一樣工作。它直接執行xslt轉換,並用繞道(shimmed)覆蓋擴展對象集合。這裏的Moled程序集是「C:\ Program Files(x86)\ Microsoft BizTalk Server 2010 \ Developer Tools \ Microsoft.BizTalk.BaseFunctoids.dll」。

var inputStream = Assembly.GetExecutingAssembly() 
        .GetManifestResourceStream("TestProject.TestFile.xml"); 
XPathDocument xpath = new XPathDocument(inputStream); 

var myFunctoids = new Microsoft.BizTalk.BaseFunctoids.Moles.MFunctoidScripts(); 
myFunctoids.DBLookupInt32StringStringStringString = (a, b, c, d, e) => "1"; 
myFunctoids.DBValueExtractInt32String = (a, b) => "result"; 
myFunctoids.DBLookupShutdown =() => ""; 

XsltArgumentList extensionObjects = new XsltArgumentList(); 
extensionObjects.AddExtensionObject("http://schemas.microsoft.com/BizTalk/2003/ScriptNS0", 
            myFunctoids.Instance); 

var outputStream = new MemoryStream(); 

var myMap = (Microsoft.XLANGs.BaseTypes.TransformBase)new Map1(); 
myMap.Transform.Transform(xpath, extensionObjects, outputStream); 

outputStream.Position = 0; 
Assert.AreEqual("<expected>result</expected>", new StreamReader(outputStream).ReadToEnd());