这是我的单元测试:
[TestCategory("Repo")]
[TestMethod]
[ExpectedException(typeof(System.ServiceModel.FaultException))]
public void RepoUnitTest_ExpectError()
{
var repo = new CreateClientRepository(ClientServiceWrapper);
IClientObject input = new ClientObject
{
ClientId = 0,
ClientName = null
};
repo.CreateClient(input);
}
我正在向我的客户端存储库提供无效输入,该存储库又调用第三方客户端服务,并且我希望客户端服务会引发错误。而且,客户端服务也会抛出异常,但不是我期望的那样。我希望它是“System.ServiceModel.FaultException”,但它给了我这个:
Test method RepoUnitTest_ExpectError threw exception
System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],
but exception System.ServiceModel.FaultException was expected.
不知道我在“ExpectedException”中放了什么,所以这个单元测试通过了正确的预期异常。