Geeks With Blogs

News View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn
Michael Stephenson keeping your feet on premise while your heads in the cloud

Ive been interested in exploring the opportunities around the Fakes Framework for testing BizTalk solutions for a while now, and until recently its been sitting as one of the many blog articles I have intended to write but haven't got around to. This week we have started looking at a BizTalk 2013 project and this presented an excellent opportunity to explore this idea.

I decided to look at the common problem people have faced in the past when you want to unit test some code and it has a dependency on the underlying BizTalk assemblies and they were difficult to mock out with one of the common mock frameworks. One of the most common examples was when you write a helper class for an orchestration and the method takes an XLANGMessage object as an input parameter. This is quite a common pattern that people have struggles with. Often the way people would handle this was to write a method that takes XLANGMessage and in that method extract the message body then call a 2nd method which did the logic required. This approach meant you could easily unit test the 2nd method and the first method people would often skip unit testing.

Although this wasn't ideal, it often worked and we would just accept this method would be tested as part of the BizUnit tests of the entire solution.

Let's take a look at a sample method that we may be trying to test.

You can see that we want to extract the message body from the BizTalk message and then return it as a string. The big problem with unit testing this method is the dependency on the XLANGMessage object and how difficult it could be to correctly construct this object to pass into the test.

Since we now have Visual Studio 2012 available this brings in the Fakes Framework and we have a few new things available to us which will make this easier. First we need to look at our references to a couple of the underlying BizTalk assemblies and create Fakes for them. To do this right click on the references assembly and click Add Fake Assembly

 

Once we have a Fakes assembly we can then create Shims and Stubs of the various objects which are within this assembly. Im not going to go too much into the detail behind shims and stubs, but will provide some links to reference articles later.

We can now write a unit test where we can fake the reference to the underlying BizTalk assemblies and make them much easier to work with and allow us to focus on the method we want to test. The below code snippet shows how we will create our test. It will call a helper method which will create the shim of the XLANGMessage and then pass it into our method to test.

You can see in the above method that our test becomes very simple while still using the XLANGMessage or BTXMessage which derives from it. One key point to note in this method is the use of the ShimContext and its disposal which ensure the shim framework is created and cleaned up after our tests have used it.

Now lets look at the method which creates our message.

You can see this method is where the fakes framework magic is happening. We firstly create a stub of the XLANGPart object and assign our string to be its stream that is returned when we call the RetrieveAsType method. We then need to create stubs of a couple of other classes which are needed to create the stub of the BTXMessage. On this message we set the return for the intexer property to be our XLANGPart which we created earlier.

Finally we create a shim of the BTSMessage and return it.

This method for creating a fake XLANGMessage is probably quite reusable for most of your unit testing scenarios as we tend to usually interact with the message body in a helper class but not that much else.

 

Conclusion

Hopefully this example has shown you how easy it can be to use the Fakes framework to test code which you may have previously thought was untestable. This happens a lot when you have dependancies on the underlying BizTalk assemblies in your unit tests.

I think there could be quite a few other opportunities where this framework could be used to complement our existing BizTalk testing practices and I plan to explore these over the coming weeks.

The code for this sample is available on the following link:

https://s3.amazonaws.com/CSCBlogSamples/ShimExample.zip

 

References

I mentioned earlier Id point out a few other sources if your interested in the fakes framework and want to find out more. Id probably start with the following:

 

Posted on Monday, April 29, 2013 12:18 PM BizTalk , BizTalk Testing | Back to top


Comments on this post: Testing BizTalk XLANGMessage with the Fakes Framework

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Nice!

Thanks for sharing, the DateTime.Now examples are not that helpfull when trying to test BizTalk ESB Itineraryservices :)

Left by Sander on May 14, 2013 2:22 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
good Once the unit installation can be over, Clash Royale for Windows 8 downloaded record to open up and set up it applying BlueStacks. Clash Royale for Computer nice.
Left by hardik on May 10, 2016 11:12 PM

# shareitforpcapp
Requesting Gravatar...
good It is normally one of the few software that permits cross-platform transferring. shareitforpcapp You will discover the software show up in the search outcomes. SHAREit PC Free nice.
Left by rushi on Jul 05, 2016 4:54 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
good You can acquire signal when they happen to be broadcasting. Bigo Live APK Download and as well socialize with people. BIGO LIVE is usually nice.
Left by jayshil on Aug 12, 2016 11:13 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
awesome then install it on your windows os and obtain appreciate play view apk Sadly, Play View for iPhone isn't offered at App Store nice.
Left by mahi on Dec 28, 2016 9:27 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
good you watch video and movie streaming around the Mobdro for android is included in professional version. Those that nice.
Left by jacob on Feb 13, 2017 11:23 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
good Youtube Downloader from our site or other partner peggo app a video clip extremely spontaneous than other nice.
Left by fender on Feb 23, 2017 7:55 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Thanks for this good post here keep posting in the future Xmodgames app
Left by stuart gray on Mar 01, 2017 8:59 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
great news to hear on!!! Xmodgames app for android</a
Left by miley cyrus on Mar 03, 2017 2:25 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
important one!!! this should be shared xmodgames update
Left by stuart sen on Mar 04, 2017 10:29 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
There will be a selection <a href=""https://www.wattpad.com/354773391-instantly-download-kodi-on-android-apk-iphone"">Kodi APK entitled Cast this Tab to on the right-hand element. Click on the little arrow notify withdraw and click Cast entire display of all the application's attachments tons of choices
Left by johnny on Mar 23, 2017 9:32 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
There will be a selection Kodi APK entitled Cast this Tab to on the right-hand element. Click on the little arrow notify withdraw and click Cast entire display of all the application's attachments tons of choices
Left by johnny on Mar 23, 2017 9:34 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
There will be a selection entitled Cast this Tab to on the right-hand readymag.com element. Click on the little arrow notify withdraw and click Cast entire display of all the application's attachments tons of Read More choices
Left by juan on Mar 23, 2017 9:36 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
There will be a selection entitled Cast this Tab to on the right-hand element. Click on the little arrow freespaceway.com notify withdraw and click Cast entire display of all the application's attachments tons of choices
Left by juan on Mar 23, 2017 9:38 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
There will be a selection entitled Cast this Tab to on the right-hand element. Click on the little arrow notify withdraw and click Cast entire <a href=""http://kodidownload64586.pages10.com/Kodi-Download-Computer-iOS-Devices-APK-Android-3731663"">pages10.com/ display of all the application's attachments tons of choices
Left by juarez on Mar 23, 2017 9:39 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...

There will be a selection entitled Cast this Tab to on the right-hand element. Click on the little arrow notify withdraw and click Cast entire pages10.com/ display of all the application's attachments tons of choices
Left by juarez on Mar 23, 2017 9:40 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
wow this is very nice one to see thanks for this Newaccounts.org/
Left by newaccount on Mar 24, 2017 10:53 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
very nice one to save information here to save www.newmailaccounts.org/ gmail sign up have like this
Left by Rajesh on Mar 29, 2017 7:31 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
woowowowowo so nice

123Movies Download
Left by nigga da boi on Apr 03, 2017 7:49 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
it prevents the uneven noise around you. Simply have facetime for pc If your reasoning that you intend to have this FaceTime App.
Left by dhrupad on Apr 13, 2017 5:26 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
It is likewise possible to shut off location setups. Musical.ly Login little to no pay, now YouTubers can earn money, or at the very.
Left by jay on Apr 15, 2017 12:05 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Good all the tehy inforamtion about Androdumpper APK Official site to download free WPS connect.
Left by sive on Apr 16, 2017 10:46 PM

# xhubs
Requesting Gravatar...
You will see hundreds of groups inside this section including different type xhubs xHubs APK for Android directly without any problem or concern.
Left by Denise on Jun 08, 2017 10:04 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
I hope you really enjoyed this game. If you have faced any issues while downloading this game, kindly contact us by simply writing us in the comment box provided below. Our experts will come back you very soon. thanks for share Gta san andreas apk indir and gangstar rio city of saints apk
Left by Tamanna Bhatia on Jun 18, 2017 12:19 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
As you knew that more than 2.2 million applications are available on different application stores on the market, have you questioned yourself, Freedom apk for non root how the app developers make money from the apps and games? The first thing which hit our mind is advertisements. and framaroot apk download for android 4.2.2
Left by Zinda Tiger on Jun 19, 2017 10:26 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Now a days students are very popular in everyone’s life everyone. Many people are addicted to so many TV shows TV serials and lot many films, so the people are looking to download the latest updates and latest April episodes new TV series. usb debugging disabled broken screen and link unblocker
Left by Zinda Tiger on Jun 21, 2017 11:24 PM

# <a href="https://xmodgamess.com/">download xmodgames</a>
Requesting Gravatar...
xmod games is nothing but an assiatant application which helps to play many games with complete control.They will help you

in cheating the game levels .
download xmodgames
Left by download xmodgames on Jun 27, 2017 9:41 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Want to send SMS for promoting your business. Then contact RKV IT Solutions for Bulk Sms Services. We are the leading Bulk Sms Service Provider in Patna, Bihar.
IT companies in patna
Left by RKV IT Solutions on Jun 28, 2017 7:19 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
You should follow some steps to setup your own emulator. It is most complicated work but Download Wechat will make your emulator for your PC/Laptop. Make sure you follow any tutorial to make your Emulator.
Left by James Smith on Jul 21, 2017 8:02 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Can't use your Epson L220 because of driver issue? Here is the solution. Download epson l220 driver by clicking on the link and enjoy.
Left by Sagar Kumar on Jul 22, 2017 10:30 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
For only Android Smartphones and also tablet machineliker.me your Android device and break out automobile.
Left by edwardian on Aug 01, 2017 7:02 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
To get solutions for all the technical issues you may have while using the internet and its various aspects like installation error of applications, login errors, failed DNS probe, internet access issues, etc, you may visit my
site here. We strive to get all your issues sorted out at the earliest.
Left by Andrew Jackman on Aug 08, 2017 11:30 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
As this app is not available in the King Root Arts so I have decided to come up with a dedicated Framaroot apk blog from which you can download all versions of Framaroot apk. On this blog, I will cover all details related to Framaroot including FAQ and how to install framaroot.
Left by Brian on Aug 14, 2017 11:11 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
If you've decided to start an online business, or an online component for a bricks and mortar enterprise, then you are probably considering starting a website. The process can be a bit daunting, but here are some simple steps that will help you create a website that will build your business. laser level guide

Left by James C. Oconnell on Sep 21, 2017 6:56 PM

# bestandroidtvbox
Requesting Gravatar...
your TV viewing experience. I created this bestandroidtvbox It can do pretty much anything you want,
Left by peter on Sep 26, 2017 6:09 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Thats really great infomration thanks for that.

Raja
My site
Left by Rajathegreat on Sep 30, 2017 3:58 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Discover 4 things you must know in order to turn your blog from a virtual deadland to a living breathing community! Read on to find out more.
laser level reviews
Left by James C. Oconnell on Oct 10, 2017 1:42 AM

# imobdro.com
Requesting Gravatar...
video clip streaming app created for Android. Below In this short article, imobdro video clip stream from the web. Mobdro Online TV for Android is presently supported.
Left by Preiss on Oct 10, 2017 5:16 PM

# diwali images
Requesting Gravatar...
download latest images and wallpapers..

happy diwali
happy diwali 2017
Left by diwali wallpapers on Oct 16, 2017 1:01 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Best things you can discover is by using TweakBox
Left by Ronald on Oct 19, 2017 8:00 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Picking a blog name can be difficult at times, especially when the niche is very high in competition and there aren't any good blog names available. Well, don't get worried because my short article will help you to pick a good blog name. Your domain name should be easy to remember, this helps your visitors to remember the name and to visit back later for more interesting articles. See more

Left by James C. Oconnell on Oct 27, 2017 8:00 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
There are many benefits with the LiteBlue Online Login services that the users get. It will most importantly allow the users to access their employment status, work status and career guidelines within the Postal community.
click here

Left by hr on Nov 08, 2017 2:01 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
I haven’t used the latest Xlang messenger and don’t know much about the same. From this post, I got a clear picture of the tool and will be looking to get this one. It looks to be a nice one to have for many purposes. Thanks for the share. Merito inpatient drug rehab
Left by lionel on Nov 12, 2017 9:55 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
You do not have to be a programmer to build a great website! Do you have Microsoft Word 2007? You can create your page text with graphics, logos, and more using Microsoft Word 2007 or Word 2010. supplement reviews

Left by James C. Oconnell on Nov 15, 2017 9:09 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Looking for successful online business owners to share which Website Content Management system you use, (e.g. WordPress, Wix, Drupal, etc) and why? visit the website

Left by James C. Oconnell on Nov 16, 2017 10:59 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
If you are reading this article right now, you are probably debating on whether or not you should have a website designed for you. We will tell you right now, having a site designed for you will do a lot of good for your business and here's why. male enhancement as seen on tv

Left by James C. Oconnell on Nov 22, 2017 1:42 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
If you are one among them after that find out about How to obtain Musically your ability as well as imagination by making videos.
Left by ketty on Dec 05, 2017 6:12 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Thanks for sharing an amazing article with us. Merry Christmas and Happy New Year 2018
Left by Amilaa on Dec 06, 2017 2:38 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
If you're setting up an online business, your website should get a great deal of your attention as you create what is effectively your "window into the world." If you don't have an actual physical location for your business or a "stone and glass" operation, the appearance of your website will convey volumes about your business to potential customers and clients. uk lease hire

Left by James C. Oconnell on Dec 07, 2017 12:44 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...

it prevents the uneven noise around you. It is likewise possible to shut off location setups.Good information all are useful.NICE ARTICLE
essay on holi in hindi
Left by happy1 on Jan 16, 2018 9:51 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
FaceTime App Download for Android APK, iPhone & PC Windows: Video calling is becoming popular facetime for pc
Left by tech on Feb 06, 2018 7:16 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Bollywood, Hollywood, South Indian, Cartoon DVDRip, Dual Audio mp4 3gp Mobile Movies & Tv Shows
Left by tech on Feb 06, 2018 7:17 AM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Myxer free ringtones for android download is available which would empower you to make your own myxer
vshare
myxer
Left by myxer on Feb 06, 2018 4:54 PM

# Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Hi there..... the information is very good and interesting and i really loved reading this, please keep updating it! thank you for sharing this article
ISO Certification in Bahrain
Left by certvalue143 on Feb 20, 2018 6:34 PM

# http://www.airrescuers.com/
Requesting Gravatar...
Thanks for the great post keep up the amazing work.

http://www.airrescuers.com/
Left by Sanjay Mishra on Mar 23, 2018 7:58 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
Yeah!! amazing. Thanks for sharing such animations
Left by http://www.airrescuers.com/ on Mar 23, 2018 8:11 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
BSEB is going to announce the long waited 12th results soon for the academic year 2017-18. This article will give you the full update regarding the https://www.bihar12thresult2018.netand all about it. Students searching for the same on the internet can take the reference of this post and this can help you get the answers for all your queries regarding BSEB 12th exams and results. So, read this and obtain the all the latest information.
Left by Hari on Mar 26, 2018 7:21 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
BSEB is going to announce the long waited 12th results soon for the academic year 2017-18. This article will give you the full update regarding the result and all about it. Students searching for the same on the internet can take the reference of this post and this can help you get the answers for all your queries regarding BSEB 12th exams and results. So, read this and obtain the all the latest information.
Left by www.bihar12thresult2018.net on Mar 26, 2018 7:25 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
BSEB is going to announce the long waited 12th results soon for the academic year 2017-18. This article will give you the full update regarding the Bihar board 12th result 2018 and all about it. Students searching for the same on the internet can take the reference of this post and this can help you get the answers for all your queries regarding BSEB 12th exams and results. So, read this and obtain the all the latest information.
Left by Results on Mar 26, 2018 10:15 PM

# re: Testing BizTalk XLANGMessage with the Fakes Framework
Requesting Gravatar...
BSEB soon going to announce Bihar board 2018 result on their offical website . This time they assured that their will no link fail issue on result day.

Here, the result will be available for intermediate science, commerce and arts result

BSEB Bihar Board soon going to declare long waited result of session 2017-18 .

Copy checking and Evaluation process about to complete.and soon Bihar Board 2018 result will get declared
BSEB 2018 result is going to announce the long waited 12th results soon for the academic year 2017-18. This article will give you the full update regarding the BSEb 12th RESULT 2018 and all about it. Students searching for the same on the internet can take the reference of this post and this can help you get the answers for all your queries regarding BSEb 10th RESULT exams and results. So, read this and obtain the all the latest information.
Left by rakk on Apr 20, 2018 6:39 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Stephenson | Powered by: GeeksWithBlogs.net