The other day I was writing some unit tests for testing my MVC application’s forms authentication classes. I needed to Mock the System.Web.HttpContext object. There are a couple of ways to do this depending on the version of Visual Studio you are using (i.e. Professional, Premium/Ultimate/Enterprise) and how deep you wish to provide some default data. One takes a little more leg work and requires some manual data setting, but gives you greater control. While the other requires less coding for simple basic use.
The other day I was writing some unit tests on an MVC project. I needed to mock (fake) an HttpRequest object using the System.Web assembly. However, there was a strange issue in creating the fakes assembly and adding it to my Visual Studio solution. Namely, it didn’t show up.Read more
In an earlier post, I provided step-by-step instructions in how to perform Behavior Driven Development using Visual Studio, SpecFlow, WatiN and DryRunner. However, I’ve had a lot of students and blog readers ask me about Selenium, a more-common browser automation tool. So, I’m writing this post to show how to accomplish BDD and automated test driven development (ATDD) using Selenium.Read more
In the previous post, we examined some of the principles behind BDD. If you read it, I’m sure you’re thinking, “Wow! That’s great! But, how do I accomplish this in Visual Studio?” There are a myriad of posts on the Internet that demonstrate different components. However, there’s not really a single post with all of the information compiled. For that reason, I’m going to provide a step-by-step tutorial on how to perform BDD with Visual Studio. Additionally, I will show you how to perform automated testing using your Gherkin scripts.
This week, while moving a client’s VM to Windows Azure, I was also required to upgrade their database from SQL 2005 to SQL Azure. While not extremely difficult, there were a few gotcha’s along the way. These “gotacha’s” were primarily features that had been deprecated. Those deprecated features aren’t the purpose of blog post, however. This post is addressing a connection string issue.
As a Microsoft Certified Trainer over the past 2 years, I’ve had the opportunity of teaching hundreds of professionals how to properly engage in unit testing. Amazingly enough, even though unit testing has been around quite a while, it is still a concept that is very infantile in the corporate arena. Most developers who have adopted unit testing are those who work for start-ups or the few companies who’ve started to embrace agile methodologies executing test-driven development (TDD).
There are times where you may want to display custom validation error messages in MVC. As for me, I’m not a huge fan of the classic ValidationSummary HTML helper. I will still annotate my data model, but I want the errors to have a better presentation in the UI. Occasionally, I may want to display one error at a time. In order to do all of this, there’s a few steps that need to be implemented.
Often times you may want to render a custom validation message that contains HTML markup. If you simply add the line:
This will encode the markup so that less than signs and greater than signs are rendered < and >, respectively. This, of course, is not what you want.
To render your HTML markup, its a little dirty, but it does work.
Simply add the following to your view:
Where “Email” is a property of your model.
When deploying an MVC application to a hosting environment you may receive the error:
[FileNotFoundException: Could not load file or assembly ‘Microsoft.Web.Infrastructure, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.]
This is also one of a few component libraries that are needed for deploying an MVC application:
The system libraries are installed with .NET 4, however, ‘Microsoft.Web.Infrastructure.dll’ is only installed when Visual Studio is installed on the machine. Therefore, short of needing to install MVC and Visual Studio on a production environment, we need to deploy the libraries with out application – and we’d like to do so automatically.
There are a few ways to automatically deploy the ‘Microsoft.Web.Infrastructure.dll’ component library with your application. The steps depend on which version of Visual Studio you are using.
There are times when developing custom web parts and other SharePoint solutions, you need to impersonate a user and view SharePoint from within their context.
Impersonating a user in SharePoint requires a few things: