0

I am building an application that leverages Microsoft Azure and I am using Microsoft Azure .NET API calls for managing my infrastructure. I want to move to the testing phase, and I am curious if there are ways to force the calls to fail other providing bogus parameters.

For instance, I have the following snippet of code which powers on a VM. Is there a way to get this call to automatically fail when given correct parameters?

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);
            }
        }

Thanks in advance!

rharrison33
  • 1,252
  • 4
  • 18
  • 34
  • Agree with Cameron's answer below, another instance this will fail would be when the max Cloud Services allocated for your subscription has been reached. – Sri Kanth Dec 08 '14 at 20:30
  • @rharrison33 Please accept my answer if it answered your question. – Cameron Dec 09 '14 at 22:41

1 Answers1

5

Following up on my (now removed) comment, ComputeManagementClient implements IComputeManagementClient. (See MSDN for details.) An easy way would be to stub up an instance of IComputeManagementClient using a mocking framework. (I use Rhino Mocks.)

There are plenty of resources available for writing unit tests with Rhino Mocks, and other mocking frameworks.

Cameron
  • 2,574
  • 22
  • 37