Hi,
I have an static class that is calling an service.
And I want to mock the GetNextKey Method call of that class.
public static class KeyServerWorkaround
{
private static readonly WebKeyServiceSoapClient KeyServiceClient = new WebKeyServiceSoapClient();
private static readonly string DbSuffix = ConfigurationManager.AppSettings["keyServerGuDbAlias"];
public static long GetNextKey(object entity)
{
object[] erg = entity.GetType().GetCustomAttributes(typeof(DatabaseObjectTableAttribute), false);
if(erg.Length != 1)
{
throw new ArgumentException("DatabaseObjectTableAttribute für Objekt " + entity.GetType().FullName + " fehlt.", "entity");
}
DatabaseObjectTableAttribute attr = (DatabaseObjectTableAttribute)erg[0];
return KeyServiceClient.getNextKey(DbSuffix, attr.Table, attr.IdColumn);
}
}
My (simplified) UnitTestMethos looks like
[TestMethod]
[Isolated]
public void InsertDatabaseObjectTest()
{
const long nextKey = 1234567L;
Isolate.Fake.StaticMethods(typeof(KeyServerWorkaround), Members.MustSpecifyReturnValues);
Isolate.WhenCalled(() => KeyServerWorkaround.GetNextKey(null)).WillReturn(nextKey); //the Exception is raised here.
//Do something
}
Surprisingly I get that Exception
Test method WKO.Inhouse.DatabaseIO.Tests.DatabaseAccessTest.InsertDatabaseObjectTest threw exception: TypeMock.TypeMockException:
*** Cannot mock types from mscorlib assembly.
Well but I'm pretty sure the class is not in the mscorlib