我正在构建一个利用 Microsoft Azure 的应用程序,并且我正在使用 Microsoft Azure .NET API 调用来管理我的基础架构。我想进入测试阶段,我很好奇是否有方法可以强制调用失败,其他提供的虚假参数。
例如,我有以下用于启动虚拟机的代码片段。有没有办法让这个调用在给定正确的参数时自动失败?
using (ComputeManagementClient client = new ComputeManagementClient(new CertificateCloudCredentials(c_subscriptionId, MyCert)))
{
var status = client.VirtualMachines.Start(serviceName, deploymentName, vmName);
if (status.Status == OperationStatus.Failed)
{
throw new MachineCreationException(status.Error.Code, null);
}
}
提前致谢!
最佳答案
根据我的(现已删除)评论,ComputeManagementClient
实现了 IComputeManagementClient
。 (有关详细信息,请参阅 MSDN。)一种简单的方法是使用模拟框架来 stub IComputeManagementClient
的实例。 (我使用 Rhino Mocks 。)
有大量资源可用于使用 Rhino Mocks 和其他模拟框架编写单元测试。
关于c# - 如何强制 Microsoft Azure .NET API 调用失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27363947/