This blog contains reflections and thoughts on my work as a software engineer

torsdag den 4. februar 2010

MSTest TestCategory and System.Runtime.Caching - two .NET 4.0 lesser-known features

We've been fiddling with Visual Studio 2010 Beta 2 and .NET 4.0 for the past month at work. Along the way I've been peeking a bit in the released features and I'd thought I'd mention the two I've found here which caught me offguard because I didn't know they existed:

MSTest improvements

it seems that MSTest has adopted the Category attribute in NUnit - in the Microsoft.VisualStudio.TestTools.UnitTesting namespace in .NET 4.0 there is a TestCategory attribute for you to use if you have long-running integrationtests you don't need or want to run on your developer machine. The equivelant NUnit Category-attribute has been around for years so to the guys in Seattle: You have seen the light at last. Thank you. Up until now you were stuck with Test Lists which - well - I've never met anyone liking them and not experiencing friction when using them and my mother always told me never to speak badly in public about anyone I didn't like so the issue here is: TestCategory in MSTest are available in .NET 4.0   :o)


There's a new namespace in .NET 4.0 which is System.Runtime.Caching. It basicly encapsulates the good ol' ASP.NET Cache from System.Web so you don't have to include System.Web in non-web assemblies if you want caching out of the box. I've always been irritated by having to either roll my own caching solution or including an assembly called "System.Web" in an assembly consisting of data-access only... It just looked too ugly and incoherent to me.

The namespace contains an abstract ObjectCache with a single implementation called MemoryCache. If you've ever worked with the ASP.NET cache you'll feel fine - Microsoft has for once gone with Principle of Least Surprise during this refactoring. There are CacheItem, CacheDependency, Absolute and Sliding expiration and so forth without the look and feel of an ASP.NET Web-application.... Nice one, Microsoft - I really mean it.

Feel free to put additional lesser-known features in the comments below if you have stumbled upon them and haven't heard or read about them anywhere.