就是我要针对一个方法进行单元测试,可是方法中引用了webservice,当单元测试走到
using(var service = new xxxClient()) { }
它就报错了,请问我该怎么做呢?是该mock一个service吗?还是在单元测试中也引用webservice?
跪求详细步骤
public static void Using<T>(T client, Action<IinterfaceService> action) where T : IinterfaceService
{
if (client is interfaceService)
{
var test = (interfaceService)(client as IinterfaceService);
try
{
action(client);
test.Close();
}
catch (CommunicationException)
{
test.Abort();
}
catch (TimeoutException)
{
test.Abort();
}
catch (Exception)
{
test.Abort();
throw;
}
}
else
{
action(client);
}
}
可以将webservice再写一个同样的方法mock