I have a solution where every single project is strongly signed. I have been using TypeMock 5.3.4.0, and everything works fine until I refactor my test code and move the live code methods into another assembly. They are still under test being handed Mock objects grant you but I get a TypeLoadException could not load type.... when I do this, if I move the code back into the testing assembly it works fine. Whats the deal? This is a huge problem since I can only test code in my test assemblies at the moment!!
Here is the code broken down by assembly:
MyAssembly.Something.Tests:
SPWeb fakeWeb;
SPFeatureReceiverProperties fakeFeatureReceiverProperties;
SPList fakeList;
[TestInitialize]
public void Initialize()
{
fakeWeb = Isolate.Fake.Instance<SPWeb>(Members.ReturnRecursiveFakes);
fakeFeatureReceiverProperties = Isolate.Fake.Instance<SPFeatureReceiverProperties>(Members.ReturnRecursiveFakes);
fakeList = Isolate.Fake.Instance<SPList>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => fakeFeatureReceiverProperties.Feature.Parent).WillReturn(fakeWeb);
}
[TestMethod]
[Isolated]
public void ShouldCheckIfMyProductLibraryListAlreadyExistsBeforeTryingToAdd()
{
const string ListItemTitle = "My Product Library";
var fakeListItem = fakeWeb.Lists[""].Items.Add();
Isolate.WhenCalled(() => fakeListItem.Title).WillReturn(ListItemTitle);
Isolate.WhenCalled(() => fakeWeb.Lists).WillReturnCollectionValuesOf(new[] { fakeListItem });
CreateMyProductLibrary(fakeFeatureReceiverProperties, ListItemTitle);
Isolate.Verify.WasNotCalled(() => fakeWeb.Lists.Add("", "", SPListTemplateType.DocumentLibrary));
}
private void CreateMyProductLibrary(SPFeatureReceiverProperties properties, string listName)
{
using (SPWeb web = properties.Feature.Parent as SPWeb)
{
if (!SPHelpers.ListExists(listName, web.Lists))
{
web.Lists.Add(listName, "test", SPListTemplateType.DocumentLibrary);
}
}
}
MyAssembly.Something:
public static class SPHelpers
{
public static bool ListExists(string name, SPListCollection listCollection)
{
foreach (SPListItem list in listCollection)
{
if (list.Title == name)
{
return true;
}
}
return false;
}
}
It errors out on the SPHelpers, saying it cant load that type...Which is just bizarre!
TestCase 'MyAssembly.Something.Tests.ShouldCreateMyProductLibraryList'
failed: System.TypeLoadException: Could not load type 'MyAssembly.Something.SPHelpers' from assembly 'MyAssembly.Something, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ab129e6374ce594'.
at MyAssembly.Something.Tests.FeatureReceiverTests.CreateMyProductLibrary(SPFeatureReceiverProperties properties, String listName)
C:WorkMyJMyAssembly.Something.TestsFeatureActivationTests.cs(43,0): at MyAssembly.Something.Tests.FeatureReceiverTests.ShouldCreateMyProductLibraryList()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
C:WorkMyJMyAssembly.Something.TestsFeatureActivationTests.cs(40,0): at MyAssembly.Something.Tests.FeatureReceiverTests.ShouldCreateMyProductLibraryList()