public void TestGetStorageServiceKeysInvalidAccountName() { var fakeHttpHandler = new FakeHttpMessageHandler(); string responseText = "<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Code>BadRequest</Code><Message>The name is not a valid.</Message></Error>"; var response = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new FakeHttpContent(responseText) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); response.Content.Headers.ContentType.CharSet = "utf-8"; fakeHttpHandler.Send = request => response; var fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient(); var target = new MediaServicesClient( new SubscriptionData { SubscriptionId = _subscriptionId }, null, fakeHttpClient, fakeHttpClient); try { var result = target.GetStorageServiceKeys(_accountName).Result; } catch (AggregateException ax) { ServiceManagementClientException x = (ServiceManagementClientException)ax.InnerExceptions.Single(); Assert.AreEqual(HttpStatusCode.BadRequest, x.HttpStatus); return; } Assert.Fail("ServiceManagementClientException expected"); }
public void TestGetStorageServiceKeys() { var fakeHttpHandler = new FakeHttpMessageHandler(); string responseText = "<StorageService xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Url>https://management.core.windows.net/f7190519-c29e-47f2-9019-c5a94c8e75f9/services/storageservices/nimbusivshapo</Url><StorageServiceKeys><Primary>PrimaryKey</Primary><Secondary>SecondaryKey</Secondary></StorageServiceKeys></StorageService>"; var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new FakeHttpContent(responseText), }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); response.Content.Headers.ContentType.CharSet = "utf-8"; fakeHttpHandler.Send = request => response; var fakeHttpClient = fakeHttpHandler.CreateIMediaServicesHttpClient(); var target = new MediaServicesClient( new SubscriptionData { SubscriptionId = _subscriptionId }, null, fakeHttpClient, fakeHttpClient); var result = target.GetStorageServiceKeys(_accountName).Result; Assert.AreEqual("PrimaryKey", result.StorageServiceKeys.Primary); Assert.AreEqual("SecondaryKey", result.StorageServiceKeys.Secondary); }