public void ListAzureDedicatedCircuitServiceProviderSuccessful() { // Setup var serviceProviderName = "TestServiceProvider1"; var serviceProviderName2 = "TestServiceProvier2"; var type1 = "IXP"; var type2 = "Telco"; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock <ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcsMock = new Mock <IDedicatedCircuitServiceProviderOperations>(); List <AzureDedicatedCircuitServiceProvider> dedicatedCircuitServiceProviders = new List <AzureDedicatedCircuitServiceProvider>() { new AzureDedicatedCircuitServiceProvider() { DedicatedCircuitBandwidths = new DedicatedCircuitBandwidth[1] { new DedicatedCircuitBandwidth() { Bandwidth = 10, Label = "T1" } }, DedicatedCircuitLocations = "us-west", Name = serviceProviderName, Type = type1 }, new AzureDedicatedCircuitServiceProvider() { DedicatedCircuitBandwidths = new DedicatedCircuitBandwidth[1] { new DedicatedCircuitBandwidth() { Bandwidth = 10, Label = "T1" } }, DedicatedCircuitLocations = "us-west", Name = serviceProviderName2, Type = type2 } }; DedicatedCircuitServiceProviderListResponse expected = new DedicatedCircuitServiceProviderListResponse() { DedicatedCircuitServiceProviders = dedicatedCircuitServiceProviders, StatusCode = HttpStatusCode.OK }; var t = new Task <DedicatedCircuitServiceProviderListResponse>(() => expected); t.Start(); dcsMock.Setup(f => f.ListAsync(It.IsAny <CancellationToken>())).Returns((CancellationToken cancellation) => t); client.SetupGet(f => f.DedicatedCircuitServiceProvider).Returns(dcsMock.Object); GetAzureDedicatedCircuitServiceProviderCommand cmdlet = new GetAzureDedicatedCircuitServiceProviderCommand() { CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert IEnumerable <AzureDedicatedCircuitServiceProvider> actual = mockCommandRuntime.OutputPipeline[0] as IEnumerable <AzureDedicatedCircuitServiceProvider>; Assert.AreEqual(actual.ToArray().Count(), 2); }
public void ListAzureDedicatedCircuitServiceProviderSuccessful() { // Setup var serviceProviderName = "TestServiceProvider1"; var serviceProviderName2 = "TestServiceProvier2"; var type1 = "IXP"; var type2 = "Telco"; MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); Mock<ExpressRouteManagementClient> client = InitExpressRouteManagementClient(); var dcsMock = new Mock<IDedicatedCircuitServiceProviderOperations>(); List<AzureDedicatedCircuitServiceProvider> dedicatedCircuitServiceProviders = new List <AzureDedicatedCircuitServiceProvider>() { new AzureDedicatedCircuitServiceProvider() { DedicatedCircuitBandwidths = new DedicatedCircuitBandwidth[1] { new DedicatedCircuitBandwidth() { Bandwidth = 10, Label = "T1" } }, DedicatedCircuitLocations = "us-west", Name = serviceProviderName, Type = type1 }, new AzureDedicatedCircuitServiceProvider() { DedicatedCircuitBandwidths = new DedicatedCircuitBandwidth[1] { new DedicatedCircuitBandwidth() { Bandwidth = 10, Label = "T1" } }, DedicatedCircuitLocations = "us-west", Name = serviceProviderName2, Type = type2 } }; DedicatedCircuitServiceProviderListResponse expected = new DedicatedCircuitServiceProviderListResponse() { DedicatedCircuitServiceProviders = dedicatedCircuitServiceProviders, StatusCode = HttpStatusCode.OK }; var t = new Task<DedicatedCircuitServiceProviderListResponse>(() => expected); t.Start(); dcsMock.Setup(f => f.ListAsync(It.IsAny<CancellationToken>())).Returns((CancellationToken cancellation) => t); client.SetupGet(f => f.DedicatedCircuitServiceProviders).Returns(dcsMock.Object); GetAzureDedicatedCircuitServiceProviderCommand cmdlet = new GetAzureDedicatedCircuitServiceProviderCommand() { CommandRuntime = mockCommandRuntime, ExpressRouteClient = new ExpressRouteClient(client.Object) }; cmdlet.ExecuteCmdlet(); // Assert IEnumerable<AzureDedicatedCircuitServiceProvider> actual = mockCommandRuntime.OutputPipeline[0] as IEnumerable<AzureDedicatedCircuitServiceProvider>; Assert.Equal(actual.ToArray().Count(), 2); }
/// <summary> /// The List Dedicated Circuit Service Providers operation retrieves a /// list of available dedicated circuit service providers. /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Dedicated Circuit Service Provider operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.ExpressRoute.Models.DedicatedCircuitServiceProviderListResponse> ListAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); Tracing.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/networking/dedicatedcircuits/serviceproviders?api-version=1.0"; string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2011-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result DedicatedCircuitServiceProviderListResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new DedicatedCircuitServiceProviderListResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement dedicatedCircuitServiceProvidersSequenceElement = responseDoc.Element(XName.Get("DedicatedCircuitServiceProviders", "http://schemas.microsoft.com/windowsazure")); if (dedicatedCircuitServiceProvidersSequenceElement != null) { foreach (XElement dedicatedCircuitServiceProvidersElement in dedicatedCircuitServiceProvidersSequenceElement.Elements(XName.Get("DedicatedCircuitServiceProvider", "http://schemas.microsoft.com/windowsazure"))) { AzureDedicatedCircuitServiceProvider dedicatedCircuitServiceProviderInstance = new AzureDedicatedCircuitServiceProvider(); result.DedicatedCircuitServiceProviders.Add(dedicatedCircuitServiceProviderInstance); XElement nameElement = dedicatedCircuitServiceProvidersElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; dedicatedCircuitServiceProviderInstance.Name = nameInstance; } XElement typeElement = dedicatedCircuitServiceProvidersElement.Element(XName.Get("Type", "http://schemas.microsoft.com/windowsazure")); if (typeElement != null) { string typeInstance = typeElement.Value; dedicatedCircuitServiceProviderInstance.Type = typeInstance; } XElement dedicatedCircuitLocationsElement = dedicatedCircuitServiceProvidersElement.Element(XName.Get("DedicatedCircuitLocations", "http://schemas.microsoft.com/windowsazure")); if (dedicatedCircuitLocationsElement != null) { string dedicatedCircuitLocationsInstance = dedicatedCircuitLocationsElement.Value; dedicatedCircuitServiceProviderInstance.DedicatedCircuitLocations = dedicatedCircuitLocationsInstance; } XElement dedicatedCircuitBandwidthsSequenceElement = dedicatedCircuitServiceProvidersElement.Element(XName.Get("DedicatedCircuitBandwidths", "http://schemas.microsoft.com/windowsazure")); if (dedicatedCircuitBandwidthsSequenceElement != null) { foreach (XElement dedicatedCircuitBandwidthsElement in dedicatedCircuitBandwidthsSequenceElement.Elements(XName.Get("DedicatedCircuitBandwidth", "http://schemas.microsoft.com/windowsazure"))) { DedicatedCircuitBandwidth dedicatedCircuitBandwidthInstance = new DedicatedCircuitBandwidth(); dedicatedCircuitServiceProviderInstance.DedicatedCircuitBandwidths.Add(dedicatedCircuitBandwidthInstance); XElement bandwidthElement = dedicatedCircuitBandwidthsElement.Element(XName.Get("Bandwidth", "http://schemas.microsoft.com/windowsazure")); if (bandwidthElement != null) { uint bandwidthInstance = uint.Parse(bandwidthElement.Value, CultureInfo.InvariantCulture); dedicatedCircuitBandwidthInstance.Bandwidth = bandwidthInstance; } XElement labelElement = dedicatedCircuitBandwidthsElement.Element(XName.Get("Label", "http://schemas.microsoft.com/windowsazure")); if (labelElement != null) { string labelInstance = labelElement.Value; dedicatedCircuitBandwidthInstance.Label = labelInstance; } } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }