"Working on the complexity that is always indirectly implied by simpilicity."

Gallio and Mb-Unit release v3.0.4

You can find many of the new features over at Jeff Brown's blog.  Some of the cooler features of note is the integration with the visual studio testing system, wrapping testing for exceptions into a delegate, and data store called Ambient, in which you can store state for your tests.  I've integrated this into amplify which is again, now on GitHub. I did run into a few lil issues when setting this up though....

The biggest issue was finding out how to turn a project into a test project in order to get the visual studio integration working for Gallio. Basically you need to make modifications to the .csproj file and add an XML element of <ProjectTypeGuids> into the first <PropertyGroup> of the file. 

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 
</ProjectTypeGuids>

After this, I could get the Gallio tests showing up in visual studio.

Gallio-Test-View

Now this coupled with really helps with the testing process especially since with certain versions of Visual Studio, Test Driven .Net will let you run visual studio's code coverage with Gallio.

CodeCoverage

Again, one of the cooler features was the improvements to Mb-Unit's Asserts (which did change the API, but its all good, cause I wrap the Asserts that I use in BDD style mixin Methods, so I just need to change them in one place). The one really change of note would be adding Assert.Throw and Assert.Throw<T>, to which you can wrap throwing an exception into a delegate.

WrappingExceptions

All in all nice improvements to both Gallio and Mb-Unit, which are now incorporated into amplify.

Labels: , , , , , , , , ,

Sample Mixins for HttpRequestBase to use with Asp.Net MVC

Being a semi avid user of rails for my day job, you tend to miss a couple of things that rails has that is not in Asp.Net's MVC framework. It is a great start and the control over the html (minus laziness of whoever ever developed their "Html.DropDownList" extension method, grrr INDENT YOUR NEW LINES!!), is much greater than what webforms gives you. One of the missing things that I miss is the request.xhr?, request.post?, etc methods that end to be helpful when deciding if this is an AJAX call or an actual action call to return the correct page.

So how do you determine if the request is an ajax request or just a regular page request. What about enforcing that a page is SSL?  What about doing different things depending if the request is a GET or POST? 

So after some googling about headers, rails, and such: here are the first go around of extension methods for HttpRequestBase that should come in handy.

public static class ControllerMixins
{

		public static bool IsPost(this HttpRequestBase obj)
		{
			return obj.Headers["REQUEST_METHOD"].ToLower() == "post";
		}

		public static bool IsGet(this HttpRequestBase obj)
		{
			return obj.Headers["REQUEST_METHOD"].ToLower() == "get";
		}

		public static bool IsXhr(this HttpRequestBase obj)
		{
			string value = obj.Headers["HTTP_X_REQUESTED_WITH"];
			return (!string.IsNullOrEmpty(value) && value.ToLower() == "xmlhttprequest");
		}

		public static bool IsSSL(this HttpRequestBase obj)
		{
			return obj.Headers["HTTPS"] == "on" ||
				obj.Headers["'HTTP_X_FORWARDED_PROTO'"] == "https";
		}
}

Labels: , , , , ,