Friday, April 22, 2011

MVC RouteConstraint is the culprite

Today, several of our live product sites got a serious issue. The page that renders a list of businesses took over 1 minutes to render. We couldn't find out the problem in serveral hours. After a while keep investigating, we found that the call of below method took about 6 seconds to run:  UrlHelper.Action("action", "controller", RouteValueCollection)   That means on a page that contains 10 links to the business detail...

Tuesday, April 19, 2011

Optional Parameter Is Ugly

Optional Parameter has been introduced since C# 4.0. It's a nice feature indeed. Let's say we wanted to create a Html Helper method that can generate a Html markup of a link by providing the inner Html, controller and action name. The method would look like: HtmlLink(string innerHtml, string action, stirng controller) Definetily, there would be a requirement to provide a routeValue object to make the link in some cases like...

Thursday, April 14, 2011

How to mock the MVC View Engine

Let's say we've created an HtmlHelper extension method to render a partial view without a need to provide a partial view name based on the type or template hint of a view model. The helper would look like: public static void DisplayModel(this HtmlHelper htmlHelper, object model) { var type = model.GetType(); var modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, type); if (string.IsNullOrEmpty(modelMetadata.TemplateHint)) ...

Friday, April 8, 2011

What is the best unit test naming convention?

I'm not good at namming actually because I'm not an English native speaker. So I tried many best practices about naming the test methods and I met a few interesting strategies: - [Subject_Scenario_Result] or - [MethodName_StateUnderTest_ExpectedBehavior] And i found a very interesting way at: http://stevesmithblog.com/blog/unit-test-naming-convention/ For me I think those methods both have pros and cons. For the first...

Turn on Compile-time View Checking for ASP.NET MVC Projects for DEBUG only

I wrote a post about "Turn on Compile-time View Checking for ASP.NET MVC Projects" Today, we got a annoying problem with it. Our team have a gate checkin in TFS. Basically, it will build the solution when someone checks in code and if it builds successfully as well as all tests pass, the checkin will be approved. Some dude in our team did...