<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Business Process Integration &#187; Test</title>
	<atom:link href="http://www.businessprocessintegration.net/tag/test/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.businessprocessintegration.net</link>
	<description>All that matters is integration (with BizTalk Server ;-)</description>
	<lastBuildDate>Fri, 28 Oct 2011 10:16:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unit testing script/C#-code in a SSIS package</title>
		<link>http://www.businessprocessintegration.net/2010/06/unit-testing-scriptc-code-in-a-ssis-package/</link>
		<comments>http://www.businessprocessintegration.net/2010/06/unit-testing-scriptc-code-in-a-ssis-package/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 17:30:00 +0000</pubDate>
		<dc:creator>Gerben van Ophuizen</dc:creator>
				<category><![CDATA[BPI]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://www.businessprocessintegration.net/2010/06/unit-testing-scriptc-code-in-a-ssis-package/</guid>
		<description><![CDATA[In SQL Server SSIS you can use the Script Task to add your custom code (for eg. in C#).
 
SSIS makes it very easily to debug your package, and also debug your custom source code. It is only a pity that you can’t unit test your own script code. I searched on the internet, but [...]]]></description>
			<content:encoded><![CDATA[<p>In SQL Server SSIS you can use the Script Task to add your custom code (for eg. in C#).</p>
<p><a href="http://www.businessprocessintegration.net/wp-content/uploads/2010/06/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.businessprocessintegration.net/wp-content/uploads/2010/06/image_thumb.png" width="112" height="65" /></a> </p>
<p>SSIS makes it very easily to debug your package, and also debug your custom source code. It is only a pity that you can’t unit test your own script code. I searched on the internet, but I found only how to test your SSIS (DTS) package via unit testing. I dived into this and created a generic approach for unit testing .Net code from a SSIS package.</p>
<p>First I researched what happens with the source code and how this will be executed runtime. The source code is stored in the package (mypackage.dtsx). Each Script Task will lead to a new project and also a new namespace. The namespace looks something like: ‘ST_1234567890abcdef01234567890abcde.csproj’. With this knowledge you can find your source code in the package, but better; also the binary, the .dll, the compiled code. Each time you change your source code, SSIS will compile the code and put the dll as Base64 string in the SSIS package. This looks like:</p>
<blockquote><p>}]]&gt;&lt;/ProjectItem&gt;&lt;BinaryItem Name=&quot;\bin\release\st_1234567890abcdef01234567890abcde.csproj.dll&quot;&gt;TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA      <br />AAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1v       <br />ZGUuDQ0KJAAAAAAAAABQRQAATAEDAP5jD0wAAAAAAAAAAOAAAiELAQgAAD4AAAAIAAAAAAAAHlwA…</p>
</blockquote>
<p>With this knowledge, we can read the package, access the Base64 string with namespace as search item (lowercase). This Base64 string can be stored as dll on your file system. It is possible to reference this dll in a unit test project. But the problem is that the signature of the dll will change when you change your package. A better approach is to load the dll into memory and use the properties and methods using reflection. Here are some code snippets:</p>
<p>Load package:</p>
<blockquote><p>XmlDocument package = new XmlDocument();      <br />try       <br />{       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; package.Load(pathAndFileToYourDtsPackage);       <br />}       <br />catch (Exception ex)       <br />{       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new Exception(&quot;your message&quot;);       <br />}</p>
</blockquote>
<p>Access the Base64 string</p>
<blockquote><p>string xPathToBinary = @&quot;//BinaryItem[@Name='\bin\release\&quot; + namespaceClass.ToLower() + &quot;.dll']&quot;;      <br />XmlNode element = package.SelectSingleNode(xPathToBinary);</p>
</blockquote>
<p>Save your dll</p>
<blockquote><p>using (FileStream fs = File.Create(yourDllFileName))      <br />{       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; byte[] buffer = Convert.FromBase64String(element.InnerText);       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fs.Write(buffer, 0, buffer.Length);       <br />}</p>
</blockquote>
<p>Now you can use reflection to load your dll, instantiate the class and access methods and properties. Here are some code snippets:</p>
<blockquote><p>_assembly = Assembly.LoadFile(_dllFileName);</p>
<p>string typeName = namespaceClass + &quot;.&quot; + className;      <br />_classType = _assembly.GetType(typeName);</p>
<p>_classInstance = _assembly.CreateInstance(_classType.FullName, false, BindingFlags.CreateInstance, null, yourConstructorParameters, System.Globalization.CultureInfo.InvariantCulture, null);</p>
</blockquote>
<p>Now you can use methods like GetMethod, InvokeMember and GetProperty to access your methods and properties.</p>
<p>You can write your unit tests in a separate test project, and use above methodology to unit test your Task Scripts. For now I only see one disadvantage: you work with ‘late binding’, so you don’t have access to your methods and properties straight away. But when everything is in place and ‘green’, then it doesn’t matter anymore <img src='http://www.businessprocessintegration.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (my opinion).</p>
<p>&#160;</p>
<p>Do you think there are other possibilities? Other approach so you can use early binding? Please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.businessprocessintegration.net/2010/06/unit-testing-scriptc-code-in-a-ssis-package/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New release BizTalk Software Factory</title>
		<link>http://www.businessprocessintegration.net/2009/09/new-release-biztalk-software-factory/</link>
		<comments>http://www.businessprocessintegration.net/2009/09/new-release-biztalk-software-factory/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 05:35:23 +0000</pubDate>
		<dc:creator>Gerben van Ophuizen</dc:creator>
				<category><![CDATA[BPI]]></category>
		<category><![CDATA[BizTalk]]></category>
		<category><![CDATA[BSF]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://www.businessprocessintegration.net/2009/09/new-release-biztalk-software-factory/</guid>
		<description><![CDATA[Jean Paul Smit has released a new version of the BizTalk Software Factory. This version has been updated to Visual Studio 2008 and BizTalk Server 2009. A nice new feature since this year is the integration of the BizTalk Deployment Framework (5.0 beta). Also Unit Testing with schemas and mappings are included.
Check it out on: [...]]]></description>
			<content:encoded><![CDATA[<p>Jean Paul Smit has released a new version of the BizTalk Software Factory. This version has been updated to Visual Studio 2008 and <strong>BizTalk Server 2009</strong>. A nice new feature since this year is the integration of the BizTalk Deployment Framework (5.0 beta). Also Unit Testing with schemas and mappings are included.</p>
<p>Check it out on: <a title="http://bsf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32987" href="http://bsf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32987">http://bsf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32987</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.businessprocessintegration.net/2009/09/new-release-biztalk-software-factory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing with BizTalk Server 2009</title>
		<link>http://www.businessprocessintegration.net/2009/01/testing-with-biztalk-server-2009/</link>
		<comments>http://www.businessprocessintegration.net/2009/01/testing-with-biztalk-server-2009/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 11:00:00 +0000</pubDate>
		<dc:creator>Gerben van Ophuizen</dc:creator>
				<category><![CDATA[BPI]]></category>
		<category><![CDATA[BizTalk]]></category>
		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://gerbenvanophuizen/2009/01/08/testing-with-biztalk-server-2009/</guid>
		<description><![CDATA[Have a look at the blog: http://geekswithblogs.net/michaelstephenson/archive/2008/12/12/127828.aspx
This one contains some links to some test features in BizTalk Server 2009.
]]></description>
			<content:encoded><![CDATA[<p>Have a look at the blog: <a href="http://geekswithblogs.net/michaelstephenson/archive/2008/12/12/127828.aspx">http://geekswithblogs.net/michaelstephenson/archive/2008/12/12/127828.aspx</a></p>
<p>This one contains some links to some test features in BizTalk Server 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.businessprocessintegration.net/2009/01/testing-with-biztalk-server-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

