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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Why MVC best for UNIT test and not webforms if there is BL and Input Validation Layer?

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net


ASP.NET MVC sessions and books say ASP.NET MVC enables to do unit testing as logic would be in controller independent to HTTP Request. So that controller can be unit tested indivisually. I do not think so people write their bussiness logic in controllers rather in seperate bussiness layer assembly. So there is no need to test controllers in bussiness perspective.

I do not think so we write web applications without a seperate Bussiness Layer. In this case Bussiness Layer also a clear seperation from UI. So BL can also be tested very well using UNIT testing frameworks either in MVC or in webforms.

then why should we chose ASP.NET MVC over WebForms in terms of UNIT Testing. Could anyone please clarify me in this regard if I'm wrong?

View Complete Post

More Related Resource Links

Input Validation: Enforcing Complex Business Data Rules with WPF


Windows Presentation Foundation has a rich data binding system that includes flexible support for business data validation. We take a look at implementing some complex data input validation scenarios that include customized data errors for users.

Brian Noyes

MSDN Magazine June 2010

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

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

Unit Testing: Exploring The Continuum Of Test Doubles


Creating and using mock component servers simplifies unit testing. Use these examples to get started.

Mark Seemann

MSDN Magazine September 2007

Know Thy Code: Simplify Data Layer Unit Testing using Enterprise Services


If you want to employ unit testing and test-driven development techniques in your database application development process, you'll have different factors to consider than you do when you're not involving a database. For example, you have to maintain a consistent state within the database and be able to roll back transactions when necessary. This article shows you how to get the best of unit testing for your database apps in a safe, usable manner.

Roy Osherove

MSDN Magazine June 2005

Unit Testing: Mock Objects to the Rescue! Test Your .NET Code with NMock


The problem: unit testing libraries, especially data access components, that have a complex set of dependencies. The solution: providing a dynamic mock implementation of your data access classes. Here the author explains just how to make testing easier and more reliable using NMock.

Mark Seemann

MSDN Magazine October 2004

override error message (The value 'test' is not valid for Age) when input incorrect data type for in


Hello everyone,

I've tried to override error message when input incorrect data type in input field on HTML form. For example I have the model like this.

public class Person
public string FirstName {get;set;}
public int Age {get;set;}


For view, I put text input for Age to get it value.

When type some string in Age text box like 'test' and press submit button. I got this error message

The value 'xxx' is not valid for Age

However, I want to change this message and try many way. There 's nothing effect this message value.

Please could you help me to solve this problem.

Who know some tools can help to create fake data which was used in unit test of asp.net mvc project

I was using aps.net mvc unit test, and want to create fake data instead of using real database connection, but the Linq query code and real database was huge and complicated, create fake data in unit test which can mimic real database was a huge job! Who knows some tools can help me to decrease size of real database and create mimic fake data for unit test. Thanks

View data input validation

I got a view has a dropdownlist and a text box for user input.And the form is set to POST.So in order to validate the input of the text box for his age, ie integer, should I use [HTTPPost] above the action body?And use overload method?eg.- Action 1 to show the view useActionResult ShowView()- after the user press 'Submit' button on the view redirect to the action[HTTPPost]ActionResult ShowView(int age){}Just wonder to validate the age, what happen if the input is not integer? Should I redirect to ShowView()?

Validation error: This property can not be set to a null value [updated with test case!]

Hi, In a dynamic data web application, I get a validation error on a non-null nvarchar(50) column in ListDetails.aspx, even though I have entered a value which should be accepted. The validation error is: "This property cannot be set to a null value.". I can not reproduce this on northwind/adventureworks. Any ideas? UPDATE: I have created a complete test case: http://printf.no/DynamicDataBugTest.zip (The archive was scanned with the latest AVG definitions before uploading to my private secure dedicated FreeBSD server) The test case contains: One Dynamic Data Web App project One MS SQL Server 2005 database backup which contains a single table with three columns One screenshot showing how the error manifests itself I am fairly convinced now that this is a reproducible DD bug. -Andreas

Unit Test in MVC. What frameworks do you suggest?

Hello,What Unit Test Framework and Mock would you advice me for test MVC projects.Thank you,Miguel

WCF input validation best practice

Hi guys, I have a WCF service defining a number of methods, and i would like to validate all input (against say a regex)  to ensure all data getting into the service is valid. I use the various enterprise library validation attributes on the data contracts so that this can be handled relatively painlessly. What is the prescribed method for communicating any failures of validation back to the client? Is it possible that raising a fault is not the right thing to do (even raising ValidationFault, no matter how applicable it may seem!) as this is using exceptions to control program flow? If this is not an acceptable manner of communicating validation failure back to the client, then what is the recommended practice? Thanks for any help guys, will be much appreciated! Nick
tag background   

If there is validation error in input box, then how to change its parent <td> tag background-color?

<td id="td1">
                                    <asp:RequiredFieldValidator ID="rfvtxtName" runat="server" ErrorMessage="Specify your Name."
                                        ControlToValidate="txtName" Display="Dynamic" ValidationGroup="vgSubmit" 
                                        CssClass="fieldError" SetFocusOnError="True"></

Validation on the presentation layer in Web Forms


Hi I normally do 3 tier systems with the business logic in the middle layer as is fairly normal. One thing I've never really been happy with is validation on the presentation layer. For instance say I have a text box where users type in a date for e.g. Date of Birth, which maps onto a DOB property of type date. Where is the best place to validate it is a date. I'd like to do it in the BLL but I can't really do that because I need to convert it to a date and it might not parse. However doing some separate presentation layer validation seems messy. Is there a recommended way of doing this?

How do I unit test HttpContext



I have a class library that uses HttpContext a lot, but I am having trouble writing unit tests for the functions. e.g. System.Web.HttpContext.Current.Request.ApplicationPath always return null, that makes class library throws exceptions everywhere.  I am not allowed to change the source codes of class library, so please let me know how to write test cases against it.


Input-validation-Error issue when Model has complex types



I have implemented aps.net mvc validation and it is working fine. Only issue I have "Input-validation-error" css class is not getting applied if model has complex types.

I am using my own data annotations for validation.

Any idea how to resolve  this.



How to unit test C# Web Service with Visual Studio 2010 ultimate


I have webservice running, how to test those web methods using the Test features of Visual Studio 2010.

As with normal web reference i am not able to create the classes and call the webmethods inside the test class.

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