Simbios
asked on
Cant use SPSite on unit test projects?
on my webpart, I have this
private void GetRowCount()
{
IServiceLocator serviceLocator = SharePointServiceLocator.G etCurrent( );
IListsHelper serviceList = serviceLocator.GetInstance <IListsHel per>();
string query = "<Where><Eq><FieldRef Name='Vendedor'/>" +
"<Value Type='Text'>Luis</Value></ Eq></Where >";
int x = serviceList.GetListRowCoun t("Sales Marketing", SPContext.Current.Site.Url , query);
}
It works perfect
but on a unit test project, I hand typed the url like this
[TestMethod]
public void TestRowCount()
{
// In this section we set up the SharePoint Service Locator. We replace the default current service locator with a new instance
// of the ActivatingServiceLocator class. We register our mock classes as the default implementations of ILists.
// Finally we use the service locator to instantiate our mock classes
ActivatingServiceLocator replaceLocator = new ActivatingServiceLocator() ;
SharePointServiceLocator.R eplaceCurr entService Locator(re placeLocat or);
replaceLocator.RegisterTyp eMapping<I ListsHelpe r, MockLists>(InstantiationTy pe.AsSingl eton);
list = SharePointServiceLocator.G etCurrent( ).GetInsta nce<ILists Helper>() as MockLists;
ListsHelper mockList = new ListsHelper();
// In this section we perform the action that we want to test. We create a new instance of Lists
// and we call the GetListRowCount method.
string query = "<Where><Eq><FieldRef Name='Vendedor'/>" +
"<Value Type='Text'>Luis</Value></ Eq></Where >";
int result = mockList.GetListRowCount(" Sales Marketing", "http://w2k8-wss2010", query);
//In this section we use various assert statements to verify that the Lists class behaved as expected
Assert.AreEqual(2,result);
SharePointServiceLocator.R eset();
}
I debugged first the webpart to see the URL, and its exactly the same I typed to make the test.
It says FILENotFoundException, not webapplication has been found at that url??
makes no sense
private void GetRowCount()
{
IServiceLocator serviceLocator = SharePointServiceLocator.G
IListsHelper serviceList = serviceLocator.GetInstance
string query = "<Where><Eq><FieldRef Name='Vendedor'/>" +
"<Value Type='Text'>Luis</Value></
int x = serviceList.GetListRowCoun
}
It works perfect
but on a unit test project, I hand typed the url like this
[TestMethod]
public void TestRowCount()
{
// In this section we set up the SharePoint Service Locator. We replace the default current service locator with a new instance
// of the ActivatingServiceLocator class. We register our mock classes as the default implementations of ILists.
// Finally we use the service locator to instantiate our mock classes
ActivatingServiceLocator replaceLocator = new ActivatingServiceLocator()
SharePointServiceLocator.R
replaceLocator.RegisterTyp
list = SharePointServiceLocator.G
ListsHelper mockList = new ListsHelper();
// In this section we perform the action that we want to test. We create a new instance of Lists
// and we call the GetListRowCount method.
string query = "<Where><Eq><FieldRef Name='Vendedor'/>" +
"<Value Type='Text'>Luis</Value></
int result = mockList.GetListRowCount("
//In this section we use various assert statements to verify that the Lists class behaved as expected
Assert.AreEqual(2,result);
SharePointServiceLocator.R
}
I debugged first the webpart to see the URL, and its exactly the same I typed to make the test.
It says FILENotFoundException, not webapplication has been found at that url??
makes no sense
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.