Skip to main content

Posts

Showing posts from May, 2014

.NET Automated Testing with Session and Microsoft Fakes

I am working on a project that uses session and application level calls nested deep within the code. It is not practical to refactor those calls to pass in the values needed and make Unit Testing possible through dependency injection, so I needed to find a way to create automated tests that would not crash on those calls. I researched and tried out many different approaches. Ultimately what I came up with was to use Microsoft's Fakes to mimmic the Session and Application calls. I was helped greatly by this post, Testing Untestable Code Thanks to MS Fakes , and commented my code with his link in case others at my company need to view it. I created a class that my Web Tests can inherit from that will handle the setup of these Fake calls. Imports System.IO Imports System.Web Imports System.Web.Fakes Imports Microsoft.QualityTools.Testing.Fakes <TestClass()> Public Class SessionTestBase Private _fakeHttpContext As IDisposable <TestInitialize()> Public Sub BeforeEa