In my previous article I outlined a way to unit test HttpContext.Current. This was in code outside of a Controller. But what happens if we’re within a Controller? Inside a Controller HttpContext is abstract because it is of type HttpContextBase. This means we can mock it. But how do we achieve that? How do we hook into those internal Controller properties? We need to inject a mocked HttpContextBase into our Controller somehow. We can do this by overriding the ControllerContext. In this post I’ll share the NUnit template I use for testing Controllers. I'll show you how to create a fake HttpContext. I'll also detail how to mock out the dependencies using NSubstitute.
How well do you test your code? Maybe you're a TDD ninja. Perhaps you're just trying to develop the habit of unit testing. You're trying to break away from mocking up an HTML page just for testing. Trouble is, you've fallen at the first hurdle. You're writing a test against code that calls HttpContext. Well, HttpContext.Current to be exact. And the test fails. How frustrating is that? It's not even your code! In this post I'll walk you through a simple technique to make HttpContext.Current testable.
One common scenario presents itself over and over when developing MVC websites. How do we provide information to our users when they post data back to our server? Often, our users will fill in a form and post it back to the server. They now need a visual response to let them know that the operation was successful. In this post I’ll be exploring the idea of adding messages to TempData. We’ll display the messages in our view via an Html helper.
Display templates (along with Editor templates) are a powerful feature of ASP.NET MVC. They allow us to create reusable HTML snippets, much like we do with partial views. In this post we'll discuss how display templates can simplify our view logic. We'll display a collection of data without a single foreach loop in sight.
For those of us new to Dependency Injection, a common question to ask is: "How many dependencies is too many?" Coupled with, and soon following this question, comes: "How can I reduce this number?" With Controllers, we tend to focus on dependencies that pass data to and fro. We first take in, or "inject", interfaces into our Controller. We can then call the methods we need within our Controller logic. In this post I’ll discuss the use of generic factories for reducing Controller dependencies.
Making the jump from WebForms to ASP.NET MVC presents many challenges. One of the more difficult concepts to grasp is knowing what you should put where. You understand that a View is equal to a Page. You’ve got your head around the fact that a View needs a Controller Action to create it. You get that routing comes into play to match URLs to your Controller Actions. So far so good. You’re even warming to the idea of using ViewModels to pass data to your Views. Question is, how should you populate your ViewModel with data? In this article I’ll be discussing the idea of using factories to create our ViewModels.
Imagine the scenario in which you have a bunch of items that need displaying in a view. Each item has an action button of some kind. We need to grab the id associated with that item so we can pass it back to the server. One approach to this problem is to handle the form submission with jQuery. In this article I’ll explain how we can solve this with jQuery data attributes.
Have you ever looked at sites that have real-time filtering of a grid or list of products and wondered "how can I do that?" Maybe you're developing a few intranet apps that would do well having this type of functionality. Perhaps you’ve looked around for good tutorials with examples so you can understand the process but you’re not even sure where to start?
We recently encountered the dreaded 'Not running in a hosted service or the Development Fabric' yellow screen of death whilst developing a client website hosted inside Azure. This post outlines one approach to accessing Blob/Table/Queue Storage services from an Azure Web Site.
How to run Jasmine tests in Visual Studio using JsTestDriver, covering configuring JsTestDriver and Jasmine and invoking the tests via a shortcut key.
How to configure IIS Express so that it runs from Visual Studio without needing Visual Studio to be run with Admin rights.
Anyone who is familiar with TFS will have noted the apparent lack of filtering available when you view the history of a project within Source Control Explorer. This filtering and searching capability is available, but is hidden away inside a separate install, Team Foundation Power Tools.
I often get developers who are unfamiliar with the branching and merging process within TFS asking me how it works, so I've put together a short guide that explains the basics. This won't be applicable in all situations and covers the basic scenario of creating a single branch from Main and then merging that branch back in at a later date. This article assumes that you know your way around the TFS and Visual Studio environments.
A short guide to implementing custom 301 redirects for an ASP.NET Webforms application by using an HttpModule.
I've put this article together to highlight some of the things you need to think about if you're thinking of taking the rather large step into the land of opportunity that is freelancing. There are a myriad of issues to think through if you decide to go down that route, but the rewards are worth the effort. Hopefully this article will provide you with some clarification to help make your decision about whether to freelance a little easier.
How to pass Json data to a RESTful WCF 4 service using Json.Net and the WebApi HttpClient
Tips on running a local Continuous Integration build via a Visual Studio shortcut key, with a focus on PSake.
An exploration of ways to sell the unit test idea to organisations and projects that are unwilling to engage in/realise the benefits of the practice
A revisiting of an old question that I touched upon in my round-up of XPDay 2011 with some extra thoughts thrown in
A few tips and tricks that I use most often with ReSharper. Always happy to hear about more!
An overview of XP Day 2011, held over 2 days in Central London. A thoroughly worthwhile conference run in the open spaces style over both days
The first of a 2 part series on effect mapping and specification by example as tools for project planning. This first part focuses on effect maps
The second of a 2 part series on effect mapping and specification by example as tools for project planning. This second part focuses on specifications
The last of a 3 part series detailing my observations and experiences when I attended the Scrum Alliance Global Gathering in London in October 2011.
The second of a 3 part series detailing my observations and experiences when I attended the Scrum Alliance Global Gathering in London in October 2011.
The first of a 3 part series detailing my observations and experiences when I attended the Scrum Alliance Global Gathering in London in October 2011.