Skip to content

Commit 416d23b

Browse files
author
Hovsep Mkrtchyan
committed
Fixed OperationalInsights tests.
1 parent 70cc576 commit 416d23b

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/EnvironmentSetupHelper.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ public EnvironmentSetupHelper()
5858
rmprofile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
5959
rmprofile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.Environments["foo"], new AzureTenant());
6060
rmprofile.Context.Subscription.Environment = "foo";
61-
AzureRMCmdlet.DefaultProfile = rmprofile;
62-
AzureSession.DataStore = datastore;
61+
if (AzureRMCmdlet.DefaultProfile == null)
62+
{
63+
AzureRMCmdlet.DefaultProfile = rmprofile;
64+
}
6365
ProfileClient = new ProfileClient(profile);
6466

6567
// Ignore SSL errors
@@ -168,6 +170,11 @@ private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
168170
ProfileClient.AddOrSetEnvironment(environment);
169171
}
170172

173+
if (!AzureRMCmdlet.DefaultProfile.Environments.ContainsKey(testEnvironmentName))
174+
{
175+
AzureRMCmdlet.DefaultProfile.Environments[testEnvironmentName] = environment;
176+
}
177+
171178
if (currentEnvironment.SubscriptionId != null)
172179
{
173180
testSubscription = new AzureSubscription()
@@ -199,6 +206,17 @@ private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
199206
ProfileClient.Profile.Subscriptions[testSubscription.Id] = testSubscription;
200207
ProfileClient.Profile.Accounts[testAccount.Id] = testAccount;
201208
ProfileClient.SetSubscriptionAsDefault(testSubscription.Name, testSubscription.Account);
209+
210+
var testTenant = new AzureTenant() { Id = Guid.NewGuid() };
211+
if (!string.IsNullOrEmpty(currentEnvironment.Tenant))
212+
{
213+
Guid tenant;
214+
if (Guid.TryParse(currentEnvironment.Tenant, out tenant))
215+
{
216+
testTenant.Id = tenant;
217+
}
218+
}
219+
AzureRMCmdlet.DefaultProfile.Context = new AzureContext(testSubscription, testAccount, environment, testTenant);
202220
}
203221
}
204222

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/Common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Gets a valid storage account resource id
3636
#>
3737
function Get-StorageResourceId($rgname, $resourcename)
3838
{
39-
$subscription = (Get-AzureRmSubscription -Default).SubscriptionId
39+
$subscription = (Get-AzureRmContext).Subscription.SubscriptionId
4040
return "/subscriptions/$subscription/resourcegroups/$rgname/providers/microsoft.storage/storageaccounts/$resourcename"
4141
}
4242

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/OperationalInsightsScenarioTestBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
using Microsoft.Azure.Management.Resources;
2020
using Microsoft.Azure.Subscriptions;
2121
using Microsoft.Azure.Test;
22+
using Microsoft.Azure.Test.HttpRecorder;
2223
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2324
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
25+
using System.Collections.Generic;
2426

2527
namespace Microsoft.Azure.Commands.OperationalInsights.Test
2628
{
@@ -51,6 +53,10 @@ protected void SetupManagementClients()
5153

5254
protected void RunPowerShellTest(params string[] scripts)
5355
{
56+
Dictionary<string, string> d = new Dictionary<string, string>();
57+
d.Add("Microsoft.Authorization", null);
58+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
59+
5460
using (UndoContext context = UndoContext.Current)
5561
{
5662
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/StorageInsightTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ namespace Microsoft.Azure.Commands.OperationalInsights.Test
1919
{
2020
public class StorageInsightTests : OperationalInsightsScenarioTestBase
2121
{
22-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
22+
[Fact]
2323
[Trait(Category.AcceptanceType, Category.CheckIn)]
2424
public void TestStorageInsightCreateUpdateDelete()
2525
{
2626
RunPowerShellTest("Test-StorageInsightCreateUpdateDelete");
2727
}
2828

29-
[Fact(Skip = "PSGet Migration: TODO: Get-AzureRmSubscription")]
29+
[Fact]
3030
[Trait(Category.AcceptanceType, Category.CheckIn)]
3131
public void TestStorageInsightCreateFailsWithoutWorkspace()
3232
{

0 commit comments

Comments
 (0)