A promblem about Unit test

Topics: Data Access Application Block
Oct 25, 2007 at 5:05 AM
In my a project ,i use the Enterprise 3.0 and vsts(vs2005),i find a problem I donot know how to reslove
i write a method for getting the data in sql2000

public DataSet GetAllCategory()
{
Database db = DatabaseFactory.CreateDatabase();
DataSet dsCategory = new DataSet();
string sqlcommand="select * from Categories";
DbCommand dbcommand = db.GetSqlStringCommand(sqlcommand);
db.LoadDataSet(dbcommand, dsCategory, "Categories");
return dsCategory;
}

and i build a unit test in test project
/// <summary>
///GetAllCategory () 的测试
///</summary>
DeploymentItem("DataAccess.dll")
TestMethod()
public void GetAllCategoryTest()
{
Category category = new Category();
int expected = 0;
DataSet actual;

actual = category.GetAllCategory();

Assert.AreNotEqual(expected, actual.Tables0.Rows.Count");
}
i run the test project ,find a error

fail GetAllCategoryTest TestProject test method TestProject.CategoryTest.GetAllCategoryTest Execption: System.NullReferenceException:

i debug the test ,i find DataBase cant not be Created;Because The programme can not get the "connstring" from webconfig.

i try a method get the "connstring"
ClassInitialize()
public static void MyClassInitialize(TestContext testContext)
{
ConfigurationSourceFactory.Create();
}
but it is not useful.
please help me .

Oct 25, 2007 at 5:10 AM
Hi,

You should post the stack trace from the exception.

Also, make sure your test assembly's configuration file defines the connection string you need. You can look at EntLib's own test projects (just open the EnterpriseLibrary.VSTS.sln file) for examples.

Hope this helps,
Fernando