Unit Testing Cannot Get Db Connection String From Web.config?

Apr 23, 2010

When I doing unit testing, I suddenlt got error message like:

The test adapter ('Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=, Culture=neutral, ublicKeyToken=b03f5f7f11d50a3a') required to execute this test could not be loaded. Check that the test adapter is installed properly. Operation is not valid due to the current state of the object.

I had this before, to resolve this is to set default run in my testrun.config. After that, I can run unit testings, but I got error :

System.NullReferenceException: Object reference not set to an instance of an object.

The problem is that unit testing cannot initiate DBConnection. Here is my DBconn.vb:


View 4 Replies

Similar Messages:

Provider Connection String Of Entity Framework Be Substituted With A DB Connection String Already Defined In Web.config?

Feb 2, 2011

I have a db connection string 'ApplicationServices' defined in the connectionString section of web.config and 3 Entity Framework connection strings which have the provider connection string attribute with the same connection string as the one in 'ApplicationServices'. Is there a way to reference connectionString in 'ApplicationServices' for the provider connection string attribute of the EF connection string in the web.config, rather than providing the connection string all over again?

View 1 Replies

Architecture :: Unit Testing - Testing Private Methods Using PrivateObject?

Feb 23, 2011

Recently for a class to implement unit test for one of its private methods I used PrivateObject by creating private accessor instead of refelection, to which i received a code review comment as below

"My main concern with Private Object is the use of object[] in constructor. It replaces strong typing enforced by compiler with JavaScript-style run-time error detection.Consequently , personally, I would not recommend it."

Comments above confused me beacuse as per my understanding reflection also needs the object[] to invoke any method.

View 2 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:


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.

View 5 Replies

Web Forms :: How To Access Connection Connection String From Sub Folder Web.config File

Mar 15, 2011

just for my testing purpose i know i can define both the connection's outside in a single web config file by different name's and access them in my front end according to it but what if i want to have seprate for both connection's web.config situation is like this see image so i want to access my connections from second web config file how i can do that.


i tired this but its giving error


View 1 Replies

Making Ado.net Connection Class Or Connection String In Web.config?

Oct 18, 2010

I am preparing for an Access2007 db conversion at the beginning of the year and would like to know what the best process would be for connecting to the sqlserver2005 database. I have read about adding the connection string to the web.config file. I have also read about using ADO.NET and put the connection information into a class and not the web.config file.

I would like to hear from others as to what you have used, are using, or plan on using for a webapp (vs2010), and why so I can get an understanding.

View 3 Replies

Configuration :: Deploy Web.config And App.config Connection String?

May 3, 2010

I have deploy my web site, it contains a project!

in MyWeb there are all the aspx page and some entites datamodel, in MyApp there are the class with function like "getter data from DB" and there is a entity data model.

afeter the deploy, I have only the web.config and the connection string for the entity datamodel....itīs run ok, read/write the data on the DB.

The problem is with MyApp.....after the deploy it is a dll file and I donīt have the app.config and the entity inside it donīt run, not read/write nothing on the DB.

There arenīt error or messager but not read/write the data in the MyApp project.

all run on the iis 7

now...the question is:

I lose the connection string (in app.config) after the deploy?

Can I put a entity in the MyWeb and read it in another project (myApp)?

ps: for connect to DB I use not the c# code:

var db=from x in AccessDB.Example select x;

View 1 Replies

Getting Connection String Out Of App.config

Feb 1, 2011

I added a database to my project. When I did so an app.config file was added to my project. (Yes I know I have dangerous info in the connection string. I shall change that but for now I am messing around with test stuff.)

<?xml version="1.0" encoding="utf-8" ?>
<add name="NyStories.Properties.Settings.storyConnectionString"
connectionString="Data Source=|DataDirectory|story.sdf;Password=driver;Persist Security Info=True"
providerName="Microsoft.SqlServerCe.Client.3.5" />

I did a google search on how to get the connection string value and found. string sConn = ConfigurationSettings.AppSettings["ConnectionString"]; I am getting a warning that this is obsolete. It has been replaced by ConfigurationManager.AppSettings. Ok Fine. According to the docs, it is also in System.Confiuguration which I already have a using statement for above. But when I attempt to use it, it is not part of the assembly.

View 4 Replies

MVC :: More Than One Connection String In Web.config?

Feb 14, 2011

My web application has to retrieve database from more then two difference sql server.

for example, one from localhost, one from different server ip.

all firewall setting was finished, but i just dont know how to code and use it.

here is my web.config :


this defines only one database in my localhost.but i need to call different connection strings each time i need.

how do i implement this?

View 4 Replies

What Is The Point Of Unit Testing

Apr 3, 2011

I have been looking at the unit testing topic and honestly I have never yet seen it in a live application.

Im a little foggy on the subject....
A simple example is if I am populating a listbox with data, I would know through debugging if the data is being populated and if it wasnt it would probably be easy to figure out why. Futhermore I couldnt possibly put it in production if it wasnt work so, why would I need to do a unit test? I dont see the point of it.

View 4 Replies

MVC :: Unit Testing View?

Mar 18, 2011

In MVC, the unit testing is primarily surrounding the controllers. The Model is rarely tested, and the View not at all. What is the consensus on this?

View 13 Replies

Using The Moq Framework To Do Unit Testing?

Feb 11, 2010

I'm using the Moq framework to do my unit testing. I'm following some really useful instructions outlined here to mock the httpcontext, specifically for the purposes of testing the url referrer:[URL]

Everything seems to compile fine, however when running the test I get the following error:

System.Web.HttpException: Invalid use
of SimpleWorkerRequest constructor.
Application path cannot be overridden
in this context. Please use
SimpleWorkerRequest constructor that
does not override the application

When analyzing I find the error seems to be thrown at the following line:

var wr = new SimpleWorkerRequest("", "", "", "", writer); I'm not sure what to make of this. What is the SimpleWorkerRequest and how does it work in creating the HttpContext in Moq?? Why is my use of it invalid according to the debugger??

UPDATE: Here is the complete method I use taken from the website above

public static HttpContextBase FakeHttpContext()
var httpContext = new Mock<HttpContextBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
var cookies = new HttpCookieCollection();
httpContext.Setup(x => x.Server).Returns(server.Object);
httpContext.Setup(x => x.Session).Returns(session.Object);
httpContext.Setup(x => x.Request).Returns(request.Object);
httpContext.Setup(x => x.Response).Returns(response.Object);
response.Setup(x => x.Cookies).Returns(cookies);
httpContext.SetupGet(x => x.Request.Url).Returns(new Uri("http://www.csuci.edu"));
httpContext.SetupGet(x => x.Request.UrlReferrer).Returns(new Uri("http://www.csuci.edu"));
//var writer = new StringWriter();
//var wr = new SimpleWorkerRequest("", "", "", "", writer);
//HttpContext.Current = new HttpContext(wr);
return httpContext.Object;

I commented out the problem lines, that seemed to fix it, but I'm still not sure what those lines were supposed to do and why they were causing error.

View 1 Replies

MVC :: Breakpoints Not Getting Hit In Unit Testing?

Mar 2, 2010

I created a new ASP.NET MVC application and the accompanying unit tests that can be generated automatically. I created a new Controller method and tried to wire up a test. The test failed, and I tried to step through the test code to find out the state of certain variables. The breakpoint showed as being set, but it never was hit.

I did a Google search on this, and there are many other people wondering the same thing - why doesn't this work? The answers have been sketchy at best. The most proliferant seems to be that the unit tests are run in the production configuration instead of the debug configuration, and so several steps are required to get breakpoints to work. Seriously? This is something I would expect to be enabled by default. What good is test code you can't step through? Why create a set of unit tests that require you to jump through several hoops to get this very basic feature running? NUnit (and I suppose others) don't have this issue.

how to get the breakpoints to work were completely different than all the others, and I'd like to know if anyone has an idea of how to enable debugging of the unit tests that are included in Visual Studio 2008.

View 4 Replies

What Is The Best Unit Testing Framework For C# 3.5

Mar 21, 2011

I would like to have information on the available unit testing frameworks in .NET realm. Especially the ones which are suitable for ASP.NET (C# .NET 3.5).

View 3 Replies

Unit Testing ProfileBase In C#?

Aug 10, 2010

I need to implement my own Profile properties and was going to inherit from System.Web.Profile.ProfileBase to achieve this.

What I don't understand is how to best unit test this Profile class in isolation without hitting the database.

View 1 Replies

How To Start With Unit Testing

Jan 27, 2011

I'd like to write some code and then just write the unit tests for the important stuff.

I know the tools. I know how to write a unit test.

I wrote some code (couple off classes) and I don't know where to start. I'm missing the semantic.

How to pick up what to unit test ?

Should I unit test every class extra ?

Should I try to simulate every possible variation of method's parameters ?

View 2 Replies

Read Connection String From Web.config

Jan 28, 2011

I called the string in my Data layer

string connectionName = System.Configuration.ConfigurationSettings.AppSettings["Connection"].ToString();

now how could call it in SqlConnection con

View 11 Replies

Where To Store Connection String In Web.Config

Mar 25, 2011

We can store Connection String in Web.config file in two ways One is

<add name="LocalSqlServer"
connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True"
providerName="System.Data.SqlClient" />

Other One is

<add key="ConnectionString"
value="server=localhost;database=Northwind;uid=sa;password=secret;" />

Now I want to know What is difference between these two approach? Which one is better way? What are their limitations?

UPDATE:Can you explain that <connectionString> has any significant advantage over <appSetting>?

View 5 Replies

Configuration :: Is Possible To Have More Then One Connection String In The Web.config

Oct 19, 2010

I have been preparing for a conversion of an old application to an ASP.NET webapplication at beginning of the year. Generally, the development version of the webapp will also be the webapp that goes into production. We here make "clones" of the database server, assign new name, etc, which is then used for development, training, and so on without any threat of changing data on the real db (sql server 2005). I know it is possible to have more then one connection string in the web.config. My question centers around if there is a simple method for allow multiple connection strings and pick the one that is to be used for dev, production, training, and so on? I originally thought about constructing some type of admin form that the connection string can be selected from.

View 2 Replies

C# - Add And Access Connection String From Web.config?

Nov 18, 2010

I want to add connection string to connect to mysql in web.config and access the same in my code c# how can i do this?

here is my code onclick of a button to connect to database.

protected void Button2_Click(object sender, EventArgs e)
String a = DropDownList1.SelectedItem.Value;
String b = DropDownList3.SelectedItem.Value.PadLeft(3, '0');


View 2 Replies

Configuration :: Get Sql Connection String From Web.config?

Dec 15, 2010

I have an app that is a bit old and will eventiall be rewritten but until I get the time it needs to continue to be patched. THe app is desgined broken into three layers (Web, DAL, BLL) The web site uses the DAL.DLL and BLL.DLL and the Website has some dataaccess and the sonnection string is saved in the web.config. For the DAL it is stored in the app.settings. Is there a way for the DAL to use the connection string that is stored in the Web.config even thought it is in DLL for the production site?

View 2 Replies

How To Implement Unit Testing For A .Net Web Application

Sep 3, 2010

I want to imlement the Unit Testing in my asp.net web application.How to identify the scope of this. I mean, How should i start on this front.

View 2 Replies

Unit Testing - How To Mock A Model In MVC

Nov 11, 2010

I've made a custom model, and I want to mock it. I'm fairly new to MVC, and very new to unit testing. Most approaches I've seen create an interface for the class and then make a mock that implements the same interface. However I can't seem to get this to work when actually passing the interface into the View. Cue "simplified" example:


Upon a HttpPost I get a "Cannot create an instance of an interface" exception. I seems that I can't have my cake (passing a model) and eat it (pass mock for unit testing). Maybe there's a better approach to unit testing models bound to views?

View 3 Replies

MVC :: Unit Testing Razor View?

Mar 3, 2011

How can I render a razor view in a Unit Test?When I change for instance a html helper method, I sometimes forget to update all the views which uses that html method. So the view I forgot generates a YSOD.I would like to create unit tests that renders a view and fails if I forgot to make the neccecary updates.

View 2 Replies

C# - Unit Testing Custom BuildProvider?

Feb 18, 2011

How can BuildProvider's GenerateCode method be tested. I created a BuildProvider and now I want to unit test it. Is it possible? Initial question was not clear enough. I don't want to stub AssemblyBuilder, I want to mimic asp.net request. I want to make sure that VirtualPathProvider and BuildProvider work fine together.

One more clarification, I am not really interested in generated code from build provider, it is used only to kick-start compilation in medium-trust environment, I already have a code, I need build provider just so I could compile since CodeDomProvider is not accessible directly in medium trust.

public override void GenerateCode(AssemblyBuilder assemblyBuilder)
string outputName = VirtualPath.Substring(VirtualPath.LastIndexOf('/') + 1);
outputName = outputName.Substring(0, outputName.LastIndexOf('.'));
_compilationContext = (CompilationContext)HttpContext.Current.Items[outputName];
var tw = assemblyBuilder.CreateCodeFile(this);
foreach (var assembly in CompilerServices.GetLoadedAssemblies().Where(a => !a.IsDynamic))

View 1 Replies

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