Skip to content

Shortening mock tests for servicemanagement networking #597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Hyak.Common;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Azure.Common;
Expand Down Expand Up @@ -96,7 +98,7 @@ public TClient CreateCustomClient<TClient>(params object[] parameters) where TCl
{
throw new ArgumentException(
string.Format("TestManagementClientHelper class wasn't initialized with the {0} client.",
typeof(TClient).Name));
typeof (TClient).Name));
}
else
{
Expand All @@ -107,6 +109,13 @@ public TClient CreateCustomClient<TClient>(params object[] parameters) where TCl
return newRealClient;
}
}
else
{
// Use the WithHandler method to create an extra reference to the http client
// this will prevent the httpClient from being disposed in a long-running test using
// the same client for multiple cmdlets
client = client.WithHandler(new PassThroughDelegatingHandler());
}

return client;
}
Expand Down Expand Up @@ -162,5 +171,17 @@ public void AddUserAgent(string productName)
}

public HashSet<ProductInfoHeaderValue> UserAgents { get; set; }

/// <summary>
/// This class exists to allow adding an additional reference to the httpClient to prevent the client
/// from being disposed. Should not be used execpt in this mocked context.
/// </summary>
class PassThroughDelegatingHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return base.SendAsync(request, cancellationToken);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
// limitations under the License.
// ----------------------------------------------------------------------------------


namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests
{
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Test;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Management;
using Microsoft.WindowsAzure.Management.Compute;
using Microsoft.WindowsAzure.Management.Network;
using Microsoft.WindowsAzure.Management.Storage;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -66,7 +69,9 @@ protected void SetupManagementClients()
{
var client = TestBase.GetServiceClient<NetworkManagementClient>(new RDFETestEnvironmentFactory());
var client2 = TestBase.GetServiceClient<ManagementClient>(new RDFETestEnvironmentFactory());
helper.SetupSomeOfManagementClients(client, client2);
var client3 = TestBase.GetServiceClient<StorageManagementClient>(new RDFETestEnvironmentFactory());
var client4 = TestBase.GetServiceClient<ComputeManagementClient>(new RDFETestEnvironmentFactory());
helper.SetupManagementClients(client, client2, client3, client4);
}

protected void RunPowerShellTest(params string[] scripts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Management.Compute;
using Microsoft.WindowsAzure.Management.Storage;

namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.ScenarioTests
{
using Microsoft.Azure.Common.Authentication;
Expand Down Expand Up @@ -73,7 +76,9 @@ protected void SetupManagementClients()
{
var client = TestBase.GetServiceClient<NetworkManagementClient>(new RDFETestEnvironmentFactory());
var client2 = TestBase.GetServiceClient<ManagementClient>(new RDFETestEnvironmentFactory());
helper.SetupSomeOfManagementClients(client, client2);
var client3 = TestBase.GetServiceClient<ComputeManagementClient>(new RDFETestEnvironmentFactory());
var client4 = TestBase.GetServiceClient<StorageManagementClient>(new RDFETestEnvironmentFactory());
helper.SetupManagementClients(client, client2, client3, client4);
}

protected void RunPowerShellTest(params string[] scripts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Hyak.Common;
using Microsoft.Azure.Subscriptions.Rdfe;

namespace Microsoft.WindowsAzure.Commands.Test.Profile
{
Expand All @@ -31,6 +34,16 @@ public IList<String> ReturnedSubscriptions
set { this._subscriptions = value; }
}

protected override SubscriptionClient WithHandler(ServiceClient<SubscriptionClient> newClient, DelegatingHandler handler)
{
return newClient as SubscriptionClient;
}

public override SubscriptionClient WithHandler(DelegatingHandler handler)
{
return this;
}

public override Microsoft.Azure.Subscriptions.Rdfe.ISubscriptionOperations Subscriptions
{
get { return MockRdfeSubscriptionOperations.Create(this.ReturnedSubscriptions, this.Tenant); }
Expand Down Expand Up @@ -128,6 +141,11 @@ public override Azure.Subscriptions.Csm.ITenantOperations Tenants
return MockCsmTenantOperations.Create(this.ReturnedTenants);
}
}

public override Azure.Subscriptions.Csm.SubscriptionClient WithHandler(DelegatingHandler handler)
{
return this;
}
}

public class MockCsmTenantOperations : Microsoft.Azure.Subscriptions.Csm.ITenantOperations
Expand Down