.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Unit tests for Action which uses RedirectToAction

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :ASP.Net

I have Action method in a controller which uses RedirectToAction(actionName, routeValues[]) 

I want to write the unit test for action method to check the following - 

1. action name

2. ViewData after executing the RedirectToAction.

Someone know how to mock it , please help.

View Complete Post

More Related Resource Links

Generation Test: Automated Unit Tests for Legacy Code with Pex


Creating and maintaining a unit test suite for legacy code can be a challenge. Pex automatically produces a small test suite with high code and assertion coverage.

Nikhil Sachdeva

MSDN Magazine December 2009

Bugslayer: Strengthening Visual Studio Unit Tests


Visual Studio 2005 brought so many new features to the table that it can seem almost overwhelming. One of the most exciting additions is the new unit testing features found in the Test menu on the main menu bar.

John Robbins

MSDN Magazine March 2006

Unit Testing Tips: Write Maintainable Unit Tests That Will Save You Time And Tears


Everybody's talking about unit testing and you want to get into the game too. But you don't want the tests to take up all your development time and energy. Fortunately Roy Osherove is here to dispel some testing myths and put you on the road to efficient unit testing.

Roy Osherove

MSDN Magazine January 2006

enabling ASP.NET MVC2 unit tests in VWD

As stated in http://forums.asp.net/t/1535916.aspx the unit tests are missing from the ASP.NET MVC 2 RTM source code, but are available on CodePlex at http://aspnet.codeplex.com/releases/view/41742).   After installing ASP.NET MVC2 RTM on Visual Web Developer 2008 Express, apparently unit tests are not enabled for VWD - when I create a new MVC2 project I don't get the "Create Unit Test Project" dialog box where I can say"Yes, create a unit test project". (I thought I was presented with that dialog box in earlier versions of either MVC2 RC or MVC1, but maybe not...) Given the source code on codeplex, is it possible to use that to enable unit tests for MVC2 for VWD Express?  If so, are the steps one have to take detailed somewhere?

'File not found' in unit tests problem



I have a unit test that reads from an .xml file and it works fine on my local machine.

However, in TFS when I create a new build it gives the following exception:

Failed    GetArticleByIdTestOptimal        Test method Test.ArticleSystemTest.GetArticleByIdTestOptimal threw exception:  System.Xml.XmlException: ImportFromFile filePath=[.\Articles1to5.xml]. --->  System.IO.FileNotFoundException: Could not find file 'c:\buildarea\TestResults\tfservice 2010-10-19 11_52_19_Any CPU_Release\Out\Articles1to5.xml'..  

Is there some reason why a unit test could pass locally but not in TFS? I've verified that the file is on the build server.

Installing SP1 caused unit tests to fail (checking for classes derived from UserControl)


I have unit tests that check to see if a certain class is derived from a given abstract class. Once I installed Visual Studio 2008 SP1 and KB971092, these unit tests start failing.

However, the odd part is, they only fail when I am checking for a class that is derived from an abstract user control.  So if I use the algorithm to see if Class1 is derived from AbstractClass1, the unit test passes.  If I check to see if View1 is derived from AbstractView1 : UserControl, the unit test fails.  The actual line of code the unit test is failing on is



The code around the failing line is


 // Try to load the assembly
Assembly ____ = Assembly.LoadFrom(assemPath);
// Now that the assembly is loaded get all the types
Type[] types = ____.GetTypes();
// Loop through all the types only returning nonabstract classes
// That are subclasses of the given class
foreach (Type type in types)
  if ((type.IsSubclassOf(subClass)) && (type.IsInterface == false

Unit Test Url.Action




I have this method in a controller, but when i call from Unit test it is always null, If i run the website it works just fine.  How can i fake it so that Url.Action works
within my controller????? 

/// <summary>
        /// Set landing page URL
        /// </summary>
        /// <param name="contentSubType">Content sub type</param>
        /// <returns>Returns the landing page url</returns>
        public string GetLandingPageByContentSubType(ContentTypeLookup contentSubType)
            var landingPage = string.Empty;

            switch (contentSubType)
                case ContentTypeLookup.DesignArticle:
                    landingPage = SiteGlobalSettings.WebsiteUrl;
                    landingPage += Url.Action("DesignHome", "Design");
                case ContentTypeLookup.Product:
                    landingPage = SiteGlobalSettings.WebsiteUrl;
                    landingPage += Url.Action("ProductsHome", "Products");
                case Co

How can I speed up unit tests which use reflection in Visual Studio 2010?


Hi there,

I was thinking about using reflection for unit tests where 2 objects will be compared for equality and GetProperty() and GetFields() methods will be used extensively. However, I know that the performance impact will be very significant. In fact, couple of my coworkers used reflection for a deep copy of some sourceobject to targetobject. The code is absolutely elegant, beautiful and does exactly what it's supposed to do. The problem is they had to scrap it because it was really slow. So, is all lost when it comes to using reflection in unit tests or is there a way to implement it without a ridiculous performance hit? Thanks a lot in advance.

Unit Testing SharePoint - Past, Present, and Sporm

As I described in SharePoint: The Wild West of Software Development there is a serious problem when you develop for SharePoint: ensuring quality through unit testing is really, really hard. And that's where a new open source tool just released today called sporm (SharePoint Object Relational Mapper) comes in. While sporm provides many benefits besides simplified unit testing I wanted to focus on this topic first, because sporm's approach, which models the entity framework in the way it supports POCO's, is a unique feature not available with other SharePoint tools like LINQ to SharePoint.

Performance Tests: Precise Run Time Measurements with System.Diagnostics.Stopwatch

Everybody who does performance optimization stumbles sooner or later over the Stopwatch class in the System.Diagnostics namespace. And everybody has noticed that the measurements of the same function on the same computer can differ 25% -30% in run time. This article shows how single threaded test programs must be designed to get an accuracy of 0.1% - 0.2% out of the Stopwatch class. With this accuracy, algorithms can be tested and compared.

pass value from textbox to action, formcollection best way here?


Hi I'm building a e-commerce store and on quantity of product I'm going with a textbox. I thought I would ask how would you do this? a viewmodel to use a strongly typed textbox or just get the value of the textbox from the formscollection passed in to the action?

Thanks for any input

reading values from config files in NUnit tests


One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?

Test-Driven Design: Using Mocks And Tests To Design Role-Based Objects


Use Test-Driven Development with mock objects to design object oriented code in terms of roles and responsibilities, not categorization of objects into class hierarchies.

Isaiah Perumalla

MSDN Magazine June 2009

Patterns in Practice: The Unit Of Work Pattern And Persistence Ignorance


Jeremy Miller continues his discussion of persistence patterns by reviewing the Unit of Work design pattern and examining the issues around persistence ignorance.

Jeremy Miller

MSDN Magazine June 2009

Test Run: Automating UI Tests In WPF Applications


This month we describe techniques for automating UI testing in Windows Presentation Foundation applications.

James McCaffrey

MSDN Magazine March 2009

Foundations: Unit Testing Workflows And Activities


Matt Milner takes a look at some of the challenges and techniques related to testing Windows Workflow Foundation activities, workflows, and associated components.

Matt Milner

MSDN Magazine November 2008

Unit Testing: Apply Test-Driven Development to your Database Projects


Jamie Laflen extols the benefits of TDD when applied to database development-and supplies some useful techniques along the way.

Jamie Laflen

MSDN Magazine Launch 2008

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend