Unit Testing in BizTalk – TestFile v2.0

Some time ago I made a post about using external file dependencies with NUnit. That post was about using a class called TestFile, which implemented IDisposable, to temporarily store files to disk, and then clean them up afterwards. While learning my way around the BizTalk unit testing capabilities in BizTalk 2009, I realized that this class could use some minor initial modifications to make life easier. To that end, I present to you that updated class. The most important new feature is the ability to support having it generate the file name as a temp file, and the ability to load resources from any Assembly in the AppDomain.

public class TestFile : IDisposable
{
    private bool _disposedValue = false;
    private string _resourceName;
    private string _fileName;

    public TestFile(string resourceName) : this(null, resourceName) { }

    public TestFile(string fileName, string resourceName)
    {
        if (fileName == null)
        {
            this.FileName = Path.GetTempFileName();
            File.Delete(this.FileName);
        }
        else 
            this.FileName = fileName;

        using (Stream s = LoadResourceFromAppDomain(resourceName))
        using (StreamReader sr = new StreamReader(s))
        using (StreamWriter sw = File.CreateText(this.FileName))
        {
            sw.Write(sr.ReadToEnd());
            sw.Flush();
        }
    }

    private Stream LoadResourceFromAppDomain(string resourceName)
    {
        Assembly[] appDomainAssemblies = AppDomain.CurrentDomain.GetAssemblies();
        Stream outStream = null;

        foreach (var lAssem in appDomainAssemblies)
        {
            outStream = lAssem.GetManifestResourceStream(resourceName);
            if (outStream != null) return outStream;
        }

        throw new Exception(string.Format("Unable to find resource stream {0}",resourceName));
    }

    public string FileName
    {
        get { return _fileName; }
        set
        {
            _fileName = value;
        }
    }
    

    protected virtual void Dispose(bool disposing)
    {
        if (!this._disposedValue)
        {
            if (disposing)
            {
                if (File.Exists(_fileName))
                {
                    File.Delete(_fileName);
                }
            }
        }
        this._disposedValue = true;
    }

    #region IDisposable Members

    public void Dispose()
    {
        // Do not change this code.Put cleanup code in Dispose(bool disposing) above.
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    #endregion
}

BizTalk Server 2009 on MSDN

I’m thrilled to announce that BizTalk Server 2009 has become available on MSDN, as of last Saturday.

The 2009 release includes many cool things, but I’d like to highlight the unit testing capabilities that have been added to the product.  With this release, there is now support for unit testing of Maps, Schemas and Pipelines.  While not perfect, these features are a great initial down payment on bringing BizTalk development in line with state of the art practices in other development areas.  I’m so thrilled that these features have been added that I will be doing a post series over the next several weeks on reducing the friction in unit testing these features, and you can look forward to the first installment shortly.

Visual Studio 2008 JQuery Intellisense

After following through various step-by-step instructions on getting the JQuery intellisense to work with Visual Studio 2008 SP1, I was still having issues getting it to work correctly.  The first and slightly more obvious reason for the intellisense to not work was down to using absolute paths for the script file.


<script type=”text/javascript” src=”/Scripts/jquery-1.3.2.min.js”></script>


This should be


<script type=”text/javascript” src=”~/Scripts/jquery-1.3.2.min.js”></script>


The second and far more idiosyncratic problem was occurring when I had also referenced other script files. So, I would have something like the following.


<script type=”text/javascript” src=”~/Scripts/jquery-1.3.2.min.js”></script>


<script type=”text/javascript” src=”~/Scripts/another-script.js”></script>


 


Strangely enough every time I referenced an additional script to the jquery core in my Site.Master the intellisense would suddenly stop working. It turns out that there is a dependency on an associated file named with a -vsdoc suffix to the script filename.


For the above example you would need an “another-script-vsdoc.js” file located in the same folder as the actual script file. It doesn’t matter whether this contains any comments to support Visual Studio intellisense, it merely needs to exist.


An additional note to point out is that the intellisense will not work if you are using any kind of server side scripting in the path, which is also pretty obvious if you think about it.


<script type=”text/javascript” src=”<%=ResolveUrl(“~/Scripts/jquery-1.3.2.min.js”)%>“></script>

BizMock for BizTalk Agile Testing

BizMock for BizTalk Agile Testing

BizMock is a new framework usedfor quick testing of BizTalk orchestrations, maps and more.Create unit tests with regular C# MS tests, enhanced with a fluent interface API and a TDD approach.Use its mocking capabilities, to avoid relying on dependent infraestructure like web services or DBs.
The following list shows all the standard artifact types that BizMock […]

Microsoft Press is giving away 40% Discount on its 25th Anniversary

Microsoft Press is giving away 40% Discount on its 25th Anniversary

Microsoft Press is giving away 40% Discount on selective 25 books to celebrate their 25th Anniversary.
Some of the books include:
Introducing Microsoft Silverlight 2.0 2nd Edition
Microsoft Visual C# 2008 Step by Step 3rd Edition,
Programming Microsoft ASP.NET 3.5
MCTS Self Paced Training Kit (Exam 70-503): Microsoft .NET Framework 3.5 Windows Communication Foundation Book/DVD/CD Package
Microsoft SQL Server 2008 T-SQL […]

Hosting WCF Services in Windows Azure

Hi folks,


Windows Azure is Microsoft’s cloud services operating system, based on Windows Server 2008 and .Net Framework 3.5 SP1. Azure is currently in a Community Technology Preview stage and you can register and try it out for free on this page.


Many of you may have wondered what is the experience of hosting WCF services in the Azure cloud. We have created a full set of samples on our newly launched Code Gallery site:



  • WCF Azure Samples

The samples show hosting WCF services for use by Silverlight clients and ASP.NET AJAX clients, as well as REST WCF services built using the new WCF REST Starter Kit.


You may also find some useful workarounds on the WCF known issues page.


 


Cheers,
-Yavor Georgiev
Program Manager, Connected Framework Team


 


 

Improve performance by disabling tracking

By default tracking in BizTalk is enabled for a couple of components that are useful during development and testing, but mostly overkill for a process that is solid, and has been running for a while.

The first thing is to create a separate host that is dedicated solely for tracking:

The other things to increase performance is to disable tracking in orchestrations:

The third thing is to disable the pipeline tracking: