I am loving to use ASP.NET MVC at work and have several projects that we have live right now. We are also migrating our web forms app very slowly by adding more mvc like views in our web forms so they can be ported easier down the road. The one issue I am having so far is testing the code that is in the pages for the mvc apps and the code in the web form views. Runtime errors are so annoying and when on a decent size team, it is almost impossible to test every page at runtime, especially when you don't always know what another developer added or changed.
So I wrote a test that precompiles the entire app and all the code in the aspx page. It is more of a sanity check than anything and has been very helpful. It has caught several simple errors that would have ended up in production and am very thankful for having this sanity test. Here is the sample test code that you can add to your test project:
const string ASPNET_COMPILER_PATH = "C:/Windows/Microsoft.NET/Framework/v2.0.50727/aspnet_compiler -p {0} -v {1}"; const string TERMINAL_APP_NAME = "cmd.exe"; [TestMethod] public void Precompile_all_pages() { string sitePath = @"D:\websites\mywebsite.com\preview"; string siteNode = "preview.mywebsite.com"; string ret = compileProject(sitePath, siteNode); string msg = "Utility to precompile an ASP.NET application\r\nCopyright (C) Microsoft Corporation. All rights reserved.\r\n\r\n"; Assert.AreEqual(msg, ret); } public string compileProject(string compileDir, string iisApplicationPath) { string compileString = string.Format(ASPNET_COMPILER_PATH, compileDir, iisApplicationPath); Process proc = new Process(); proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.FileName = TERMINAL_APP_NAME; //File name to execute proc.StartInfo.Arguments = "/c " + compileString; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardInput = true; proc.Start(); // Execute process proc.WaitForExit(); string output = proc.StandardOutput.ReadToEnd(); return output; }
Remember Me
a@href@title, b, blockquote@cite, i, strong, u
Powered by: newtelligence dasBlog 1.9.6264.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
E-mail