chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
If I run the test in a Windows Server 2003 with SharePoint. The test passed. But If I do in Developer Machine (vista Business with SP2) only with the SharePoint assemblies copied, the test showed me the next error:

Test method Evaluacion.PruebasUnitarias.SharePoint.ControladorLibreriaEvaluacion.ListarObjetosLibreria threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SharePoint.Library, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.

I tryed everything...I registered the Microsoft.SharePoint.dll, Microsoft.SharePoint.Search.dll and Microsoft.SharePoint.Security.dll in the GAC.

I copied the same dlls in C:Program FilesMicrosoft Visual Studio 9.0Common7IDEPublicAssemblies directory in order to take from Net Tab in References inside VS 2008.

I tryed to copy the dlls in isapi 12 hive directory and reference visual studio from that location. But nothing change!

I tried too uninstalled visual studio 2008 and Installed again with sP1 too, and finally typemock without any other addin in visual studio.

But nothing worked!.

I have TypeMock 5.3 for SharePoint installed in both machines (the sever is a virtual machine in my vista machine)

My test is just that:

public void ListarObjetosLibreria() {

// Arrange
string nombreLibreria = "Prueba";
var fakeSite = Isolate.Fake.Instance<SPSite>(Members.ReturnRecursiveFakes);
SPWeb miWeb = fakeSite.OpenWeb();
////var _controladorLibreria = new ControladorLibreria();
// Act
//IList<Libreria> listado = _controladorLibreria.ObtenerListado(miWeb, nombreLibreria);
// Asert
//Assert.AreEqual(Lisado != null);

I noted when I just had this line: var fakeSite = Isolate.Fake.Instance<SPSite>(Members.ReturnRecursiveFakes);
and the Assert line like Asser.IsNotnull(fakeSite); It worked!, in my vista machine without SharePoint Server installed there.
But when I moved to the next line : SPWeb miWeb = fakeSite.OpenWeb(); And the assert was for miWeb object: Assert.IsNotNull(miWeb);
The error message showed up!.

I really want to test my sharepoint code in my develop machine like the blogs write about it, but I did not find the way.

Could someone help me or have a workaround. I did not find any reference for typemock. or SharePoint library that really help me, in the net.

Thanks in advance!
asked by jmho.gua (640 points)

2 Answers

0 votes

I see a couple of things that may have gone wrong:

This sort of an exception is received in Sharepoint unit test projects where you miss a dependency to isolate, and an original implementation of Sharepoint code tries to execute. A recent similar case can be seen here: ... highlight=.

According to the code you posted the test is only comprised of creating a fake site, extracting a web from it and asserting against that web - is that indeed the test you are running? In that case can you try to add the Sharepoint.dll assembly reference as a disk-location reference rather than installing it in GAC? It looks like your test can't find the assembly.

Please let us know if any of this help.

Typemock Support
answered by doron (17.2k points)
0 votes
Thanks for your response. I have serveral questions about your response?

I dont folow you when you say:
This sort of an exception is received in Sharepoint unit test projects where you miss a dependency to isolate, and an original implementation of Sharepoint code tries to execute.
What means that?. I added the [Isolated] Attribute if is what you mean?.
But It didn´t work.

This is not the test that I really want to test but, I comment everyting in order to reduce my test and see if I can make to work.
I already try to add assembly reference from my disk alocation, was my first test. But nothing did work!. Y almost try with your code sample:
public void RepositoryAdd_FakeSPServer_PropertiesAreSetWithCorrectArguments() {
var fakeWeb = Isolate.Fake.Instance<SPWeb>(Members.ReturnRecursiveFakes);
var fakeUser = fakeWeb.SiteUsers.GetByID(1);
var fakeItem = fakeWeb.Lists[""].Items.Add();
Isolate.WhenCalled(() => fakeItem[0]).WillReturn(1);
//Registration registration = new Registration() { CourseId = 1234, RegistrationStatus = "Pending", Title = "UnitTest", UserId = 100 };
//RegistrationRepository repository = new RegistrationRepository();
//int id = repository.Add(registration, false, fakeWeb);
Assert.AreEqual(1, fakeItem.ID);
//Isolate.Verify.WasCalledWithExactArguments(() => fakeItem[Fields.Title] = "UnitTest");
//Isolate.Verify.WasCalledWithExactArguments(() => fakeItem[Fields.UserId] = 100);
//Isolate.Verify.WasCalledWithExactArguments(() => fakeItem[Fields.User] = fakeUser);
//Isolate.Verify.WasCalledWithExactArguments(() => fakeItem[Fields.Status] = "Pending");

but it did not work too!. How I said first, It works in a server installation. But not from my developer machine in Vista with SP2.
Installed. I read docs in microsoft and some folks mention that Testing sharePoint needs to be run in server that it has installed
SharePoint Server. So I don't know if I'm missing some configuration. I disable the ACL in Vista. But nothing change. I run VS2008 as Administrator but nothing!.
answered by jmho.gua (640 points)