Sunday, March 20, 2011

Write unit test for a method depends on RoleProvider

Let's say I have a class like this: public class CustomAuthorizeAttribute : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { return string.IsNullOrEmpty(Roles) ? base.AuthorizeCore(httpContext) : IsUserInRole(Roles); } public static bool IsUserInRole(string...

Wednesday, March 16, 2011

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

You can make the web project perform compile time checking of the markup in the views by modifying the .csproj file and turning on the "MvcBuildViews" property. The advantage of this is that you will know at compile time any problem with a view, not at run time when someone accesses that page. So please follow the below blog to do that: http://blogs.msdn.com/b/jimlamb/archive/2010/04/20/turn-on-compile-time-view-checking-for-asp-net-mvc-projects-in-tfs-build-2010.aspx However,...

Thursday, March 10, 2011

Make class visible to only test assemblies

Yesterday, i was spending my time at work trying to increase the test coverage for our solutions. It's such a hard work because everone wants to write unit tests, everyone want to have better coverage but all people seem to have a lot of stuff to finish before deadline. We talked about it every sprint retrospective and the coverage started to increase very slowly from last week. Hmmm, I always want to be in a TDD team but never...

Sunday, March 6, 2011

Deploy items for unit tests

If you are running a unit test that requires an additional item like testing data, xml file, etc, you need some how to copy these files into test run folder. Executing unit test using VS.NET Testing framework is different to other unit test libraries like NUnit which runs the tests using the compiled assemblies in build folder (Debug/Release). Visual Studio creates deployment files under a folder named TestResults within the solution...