How To Make HttpContext Available To Be Used By My Unit Tests

Aug 13, 2010

I want to write a unit test which tests the function of a class called UploadedFile. The problem I face is this class' static constructor uses HttpContext.Current property and because I am running my unit test from a class library I do not have an HttpContext at the testing time.

Look at my static constructor:

static UploadedFile()
{
if (HttpContext.Current == null)[code]....

What should I do in my testing environment so that HttpContext.Current won't be null and I can successfully set this:

HttpServerUtility server = HttpContext.Current.Server;

View 2 Replies


Similar Messages:

C# - How To Fake HttpContext For Unit Tests

Aug 15, 2010

I need to fake HttpContext.Current.Application table to access it from my unit tests.I need to store my data somewhere. I thought that I can just pass instance of NameValueCollectionBase but as I descover this base type has no indexer so it's too complicated to use. So what about faking this part of HttpContext? Is it possible? How can I make it? Will be NUnit.

View 2 Replies

C# - Is Possible To Run Some Unit Tests As Smoke Tests

Oct 21, 2010

In my project we use UnitTests (MsTest). We run them manually and in the build script.But for some environments where we deploy manually.We are in the need of having some smoke tests. At the moment I made this smoke tests "manually" (Login, create an user, create a licence, create a product, etc). I know I can run unit tests from command line or from visual studio but...Do you know if is possible to run these mstests (or probably a small subset) from an .aspx page and show the results?EDITED: wondering if mstests or something is able to run the tests and have something visual to show in an .aspx page similar to a list of tests passed and tests failed...I am thinking on running only a small subset of tests (5-6)

View 1 Replies

Writing Useful Unit Tests?

Jul 7, 2010

I have a simple page with a Grid that I'm binding a collection of objects to. I also have some simple functionality on the grid to edit and save rows. I would like to write unit tests for this page, but it's not really making sense to me.For example:

Private Sub LoadGrid()
'Populate Collection
grid.datasource = MyCollection
grid.databind()
end sub

I guess a Sub really doesn't need a unit test, but what if this were a function that returned true when the grid had been loaded. How do you write a unit test for this? What other test should be done on a simple web page like this?

View 2 Replies

MVC :: Unit Tests For Action Which Uses RedirectToAction?

Oct 13, 2010

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 name2. ViewData after executing the RedirectToAction.

View 1 Replies

How To Apply Unit Tests In .NET Webforms

Mar 31, 2010

I'm developing a website in asp.net webforms with 3 layers; UI, BLL and DAL.The website is already developed, but i like have more control about the unit tests of each form Pass specific values at specific inputs for i see, if application survives or not.

I already study about NUnit but in webforms in UI layer how can apply these tests?What i wnat is get some way to test UI (validations) without have to access to the BLL as i was an user.

I'm trying to add the Unit tests to my app but i not sure how to do it!

View 2 Replies

MVC :: Enabling .NET MVC2 Unit Tests In VWD?

Mar 16, 2010

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?

View 5 Replies

C# - Stubbing .NET Page.Form For Unit Tests?

Feb 22, 2011

Fo unit testing ASP.NET controls I need a stubbed Page.

I can create an ASP.NET Page object in my unit tests by subclassing System.Web.UI.Page.However, I cannot find a way to set Page.Form. Adding a form with attribute (runat,server)does not work. Overloading the form in my Subclass does not give the required functionality.

Context:I try to unit test some homemade ASP.NET controls. These control require Page and Page.Form not to be null.

View 3 Replies

Continuous Integration For .Net And Javascript With Unit Tests?

May 4, 2010

I need a Continuous integration tool that will support both .Net Unit tests and Javascript unit tests and perform the builds.It looks like my main options are CruiseControl.NET using JUnit and NUnit or Team City and JS Test Driver.

Are there any other options and which ones have you used or had good or bad experiences with.

View 1 Replies

Visual Studio :: 'File Not Found' In Unit Tests?

Oct 19, 2010

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:uildareaTestResults fservice
2010-10-19 11_52_19_Any CPU_ReleaseOutArticles1to5.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.

View 1 Replies

JQuery :: Integrate Unit Tests With Visual Studio?

Mar 17, 2011

I recently came accross the following article on Stephen Walther's website

[URL]

Basically, it provides some excellent guidance on how to integrate your Javascript tests into Visual Studio. I followed the steps in the article and successfully managed to test Javascript methods using Visual Studio tests.

I am unable however to unit test JQuery methods (I get errors such as "window" undefined). I was wondering if anyone has successfully managed to test jQuery methods on the server using the above link?

View 2 Replies

Write Unit Testing Web Services - HttpContext

Oct 26, 2010

I want to write unit tests for a web service. I create my test project, reference my web project (not service reference, assembly reference), then write some code to test the web services - they work fine. However, there are some services which make sure the user is logged in to the web application by using HttpContext.Current.User.Identity.IsAuthenticated. In the context of the tests, there is no such thing as HttpContext, so the tests always fail. How should these kinds of web services be unit tested?

View 5 Replies

Unit Testing / Mocking HttpContext Without Using Any Mock Framework

Sep 7, 2010

Since I'm having problem with unit testing RenderPartialViewToString() with Moq framework [URL] I'm thinking about getting my controller directly, without using Moq for these particular test, however, how do I mocks (or set) the HttpContext for my test without using any Moq framework?

I need to able to do something similar to this, without Moq of course:

var mockHttpContext = new Mock<ControllerContext>();
mockHttpContext.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("n1\test");
mockHttpContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);

View 2 Replies

Asp.net - Preserve MVC Principles And Make Website More Unit-testing Friendly?

Nov 9, 2010

I've made a simple website in ASP.NET MVC Framework with users, articles etc., and images to users profiles. There is a simple static class for image manipulation (resizing, cropping and saving images on hard drive), placed in "Helper" directory. I wonder what to do with the code to preserve MVC principles and make whole website more unit testing friendly.

View 2 Replies

How To Make Sure That CreateChildControls () Method Is Called When Unit Testing Custom .NET Web Controls

Feb 10, 2010

I want to unit test my rendering engine for an ASP.NET app. I have some custom controls created in that app. Most of those control rely on having CreateChildControls() method called by the ASP.Net engine wheather during initial call or a postback.When running a test CreateChildControls() does not get called and the control is in an "invalid" state.

As a workaround to get the tests going I explicitly call some other public method that calls EnsureChildControls() in it. This in effect causes CreateChildControls() to be executed and the control being initialized properly (just as it would normally when hosted on web server). I would like to get rid of that extra method call and the control to still be in a proper state for testing.

View 1 Replies

C# - Workaround For HttpContext.HideRequestResponse Being Internal? Detect If HttpContext.Request Is Really Available?

Apr 9, 2010

We're migrating an application to use IIS7 integrated mode. In library code that is designed to work either within the context of an HTTP request or not, we commonly have code like this:

if (HttpContext.Current != null &&
HttpContext.Current.Request != null) {
// do something with HttpContext.Current.Request
} else {
// do equivalent thing without HttpContext..
}

But in IIS7 integrated mode the check for HttpContext.Current.Request throws an exception whenever this code is called from Application_Start.

protected void Application_Start(object sender, EventArgs e)
{
SomeLibrary.DoSomethingWithHttpContextCurrentDetection();
}

Results in:

System.Web.HttpException: Request is not available in this context

How can I detect whether the request is really available without wrapping these calls in an exception handler and taking action based on whether an exception is generated or not.

Looking at HttpContext in Reflector I see it has an internal bool HideRequestResponse field but it's internal so I can only get to it with reflection and that's fragile. Is there a more official/approved way to determine if it's ok to call HttpContext.Request?

This blog post about the subject says not to use HttpContext, but how, in generic library code, can you determine if it's ok to use HttpContext?

http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

I'm using the work-around mentioned there which is to use Application_BeginRequest and an initialized field to only initialize once as part of BeginRequest, but that has to be done in every calling application whereas I'd prefer to make the library code more robust and handle this situation regardless of where it's called from.

View 4 Replies

Unit Testing Error - The Unit Test Adapter Failed To Connect To The Data Source Or To Read The Data

May 6, 2010

I'm using VSTS 2K8 and I've set up a Unit Test Project. In it, I have a test class with a method that does a simple assertion. I'm using an Excel 2007 spreadsheet as my data source.

My test method looks like this:

[Code]....


As indicated in the method decoration attributes, my Excel spreadsheet is on my local C:/ Drive. In it, the sheet where all of my data is located is named "Sheet1".I've copied the Excel spreadsheet into my project and I've set its Build Action = "Content" and I've set its Copy to Output Directory = "Copy if Newer".

When trying to run this simple unit test, I receive the following error:

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: ERROR [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.

I've verified that the sheet name is spelled correctly (i.e. Sheet1) and I've verified that my data sources are set correctly.Web searches haven't turned up much at all.
[Code]....

View 5 Replies

Relationship Between HttpContext.Request.Cookies And HttpContext.Response.Cookies

Nov 23, 2010

I have been experimenting with code that will clear all of the cookies in an HttpContext.Response.Initially, I used this:

DateTime cookieExpires = DateTime.Now.AddDays(-1);
for (int i = 0; i < HttpContext.Request.Cookies.Count; i++)
{
HttpContext.Response.Cookies.Add(
new HttpCookie(HttpContext.Request.Cookies[i].Name, null) { Expires = cookieExpires });
}

this will error with an OutOfMemoryException because the for loop never exits - each time you add a cookie to the Response, it also gets added to the `Request.

View 1 Replies

Difference Between ControllerContext.HttpContext.Session And HttpContext.Current.Session

Nov 23, 2010

i'm using an example in which i can fake the session.It's for use in a unittest of a mvc controller.In the test i create a controller and then i do this:

FakeHttpContext httpctx = new FakeHttpContext(null,null,null,null,mSessionItems );
ControllerContext ctx2 = new ControllerContext(httpctx,new RouteData(), target);

here mSessionItems is my session and target is my instance of a controller,and indeed, when i'm in a controller reading this.ControllerContext.HttpContext.Session, i have a session, great!but.... i also read the session outside the controller, and there i use HttpContext.Current.Session, and that is null (or actualy, the HttpContext.Current is null).

View 1 Replies

Tests Set Of Url's And Checks If Get Redirected To Another

Apr 23, 2010

I made a small program which tests a set of url's and checks if they get redirected to another set of urls. Now this program has been working fine till I got a few urls which are of the form [URL] Now the problem occurs when I have a url with "//" not the http://, whenever I use any url with "//" it produces the error The server committed a protocol violation. Section=ResponseStatusLine. If I test the same in the browser it loads the page, but I cannot check the same throught the application. If I remove the "/" then it should work, but then the site wont load.

View 2 Replies

Web Tests Without VS 2010 Ultimate?

Dec 13, 2010

At my previous job we had VS 2008 Team Edition which included the ability to do web tests and load testing right in VS. Currently the company I'm at has VS 2010 Professional but we are thinking of upgrading to Premium, but this still leaves us without the built in Web Testing/Load Testing ability directly in VS.

I'm going to talk to my IT Director and see if they might be willing to go for ultimate, but I need to know first if any off-the-shelf products can fill this hole as the cost is almost double for the Ultimate edition of VS 2010.I really like the testing abilities in 2008 that I worked with, but really just need some of the similar functionality. The ability to record a test and then group a series of tests together, see the HTPP values and results, possibly the ability to do data driven tests and DEFINITELY the need for load testing.

View 2 Replies

MVC :: Use The Structure Map Configuration For The Tests?

Sep 12, 2010

On a MVC 3 Preview Web Application I am using the following:

1 - Structure Map for IOC

2 - Fluent Validation for Validation

3 - AutoMapper for mapping.

Everything is working fine.Now I created a Test Project. How can I use the same Structure Map configuration for the tests?

View 5 Replies

Visual Studio :: Cannot Run More Than 2 Database Integration Tests

Nov 24, 2010

I have written some database integration tests in the format of MS unit test. If I run each test, it runs fine. If I run 2 integration tests, it runs fine. However, if I runs 3 or more test at the same time, one test will show "In Progress", and other shows "Pending", basically, it does not make any progress at all, stays there forever. I turned on SQL Server Profiler, it does not show the test hit the database at all.

Here are some examples of my method:

[Code]....

Here are examples above method integration tests:

[Code]....

View 1 Replies

.net - Is It Possible To Run Tests Using The NUnit Framework In A Hosted Website

Sep 8, 2010

But I have other tests that are essentially deployment tests (you can't test how the production deployment went using a unit test on a build server) and I'd like to use the nUnit framework to run these.But, the production server doesn't have the nUnit command line executer. I'm only allowed to run aspx pages and reference .dll's in bin.What do I need to do to run tests (yeah, yeah, they're not really unit tests--relax) using nUnit in a webpage? Is there a straight forward way to do this, or does this essentially require porting the nUnit winforms test runner to ASP.NET?

View 1 Replies

How To Integration Testing On Application Without Necessarily Running All The Tests Via The Browser

Jun 4, 2010

ASP.Net MVC - How should i do integration testing on an ASP.net MVC application without necessarily running all the tests via the browser?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved