public void RunPSTestWithToken(Func<AzureContext, string, string> testBuilder , params string[] scripts) { var callingClassType = TestUtilities.GetCallingClass(2); var mockName = TestUtilities.GetCurrentMethodName(2); IAuthenticationFactory savedAuthFactory = AzureSession.AuthenticationFactory; try { RunPsTestWorkflow( () => { savedAuthFactory = AzureSession.AuthenticationFactory; var command = new GetAzureSubscriptionCommand(); command.CommandRuntime = new MockCommandRuntime(); command.InvokeBeginProcessing(); var profile = command.Profile; var context = profile.Context; var account = context.Account; var tenant = account.IsPropertySet(AzureAccount.Property.Tenants) ? account.GetPropertyAsArray(AzureAccount.Property.Tenants).First() : "Common"; var subscription = context.Subscription; string token = null; if (account.IsPropertySet(AzureAccount.Property.AccessToken)) { token = account.GetProperty(AzureAccount.Property.AccessToken); } else { var accessToken = AzureSession.AuthenticationFactory.Authenticate(account, context.Environment, tenant, null, ShowDialog.Never); Assert.IsNotNull(accessToken); Assert.IsNotNull(accessToken.AccessToken); token = accessToken.AccessToken; } AzureSession.AuthenticationFactory = new AuthenticationFactory(); var testString = testBuilder(context, token); var returnedScripts = scripts.Concat(new String[] {testString}); return returnedScripts.ToArray(); }, // no custom initializer null, // no custom cleanup null, callingClassType, mockName); } finally { AzureSession.AuthenticationFactory = savedAuthFactory; } }
public void CmdletStartsWithJsonWithoutAccounts() { MockDataStore dataStore = new MockDataStore(); dataStore.VirtualStore[newProfileDataPath] = jsonProfileWithoutAccount; ProfileClient.DataStore = dataStore; GetAzureSubscriptionCommand cmdlt = new GetAzureSubscriptionCommand(); ProfileClient client = new ProfileClient(); Assert.Equal(1, client.Profile.Subscriptions.Count); Assert.Null(AzureSession.CurrentContext.Subscription); Assert.Null(AzureSession.CurrentContext.Account); }