Tagged Questions
212
votes
19answers
51k views
NUnit vs Visual Studio 2008's Test Projects for Unit Testing? [closed]
I am going to be starting up a new project at work and want to get into unit testing. We will be using VS 2008, C#, and the ASP.NET MVC stuff. I am looking at using either NUnit or the built in test ...
107
votes
5answers
13k views
ASP.NET MVC: Unit testing controllers that use UrlHelper
One of my controllers actions, one that is being called in an Ajax request, is returning an URL to the client side so it can do a redirection. I'm using Url.RouteUrl(..) and during my unit tests this ...
59
votes
6answers
13k views
How to mock the Request on Controller in ASP.Net MVC?
I have a controller in C# using the ASP.Net MVC framework
public class HomeController:Controller{
public ActionResult Index()
{
if (Request.IsAjaxRequest())
{
//do some ...
44
votes
2answers
9k views
Unit testing with EF4 “Code First” and Repository
I am attempting to get a handle on Unit testing a very simple ASP.NET MVC test app I've built using the Code First approach in the latest EF4 CTP. I'm not very experience with Unit testing / mocking ...
42
votes
9answers
18k views
Mocking Asp.net-mvc Controller Context
So the controller context depends on some asp.net internals. What are some ways to cleanly mock these up for unit tests? Seems like its very easy to clog up tests with tons of setup when I only need, ...
41
votes
9answers
9k views
Unit tests on MVC validation
How can I test that my controller action is putting the correct errors in the ModelState when validating an entity, when I'm using DataAnnotation validation in MVC 2 Preview 1?
Some code to ...
37
votes
4answers
13k views
ASP.NET MVC3 and Entity Framework Code first architecture
My previous question made me think again about layers, repository, dependency injection and architectural stuff like this.
My architecture now looks like this:
I am using EF code first, so I just ...
36
votes
1answer
6k views
How can I unit test my ASP.NET MVC controller that uses FormsAuthentication?
I'm working with a ASP.NET MVC solution in a test driven manner and I want to login a user to my application using forms authentication. The code I would like to end up with in the controller looks ...
36
votes
7answers
11k views
ASP/NET MVC: Test Controllers w/Sessions? Mocking?
I read some of the answers on here re: testing views and controllers, and mocking, but I still can't figure out how to test an ASP.NET MVC controller that reads and sets Session values (or any other ...
27
votes
8answers
1k views
What do you test with your unit tests?
TDD is something that seems to be on everybody's lips these days, and I have tried some on my own but I don't think I'm getting the idea. I am getting a grip on how to write a unit test, but I don't ...
27
votes
4answers
7k views
ASP.Net MVC and nUnit
I have nUnit installed.
I have VS2008 Team Edition installed.
I have ASP.Net MVC Preview 4 (Codeplex) installed.
How do I make Visual Studio show me nUnit as a testing framework when creating a new ...
22
votes
5answers
10k views
How do you mock the session object collection using Moq
I am using shanselmann's MvcMockHelper class to mock up some HttpContext stuff using Moq but the issue I am having is being able to assign something to my mocked session object in my MVC controller ...
21
votes
3answers
12k views
Fake DbContext of Entity Framework 4.1 to Test
I'm using this tutorial to Fake my DbContext and test: http://refactorthis.wordpress.com/2011/05/31/mock-faking-dbcontext-in-entity-framework-4-1-with-a-generic-repository/
But i have to change the ...
20
votes
3answers
5k views
Testing HtmlHelpers in ASP.NET MVC
Is there any way to (unit) test my own HtmlHelpers? In case when I'd like to have custom control (rendered by HtmlHelper) and I know requierements for that control how could I write tests first - and ...
18
votes
4answers
6k views
Unit testing a controller in ASP.NET MVC 2 with RedirectToAction
I have a controller that implements a simple Add operation on an entity and redirects to the Details page:
[HttpPost]
public ActionResult Add(Thing thing)
{
// ... do validation, db stuff ...
...