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 Setup() { profile = new WindowsAzureProfile(new Mock <IProfileStore>().Object); profile.ImportPublishSettings(Data.ValidPublishSettings.First()); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new GetAzureSubscriptionCommand { Profile = profile, CommandRuntime = mockCommandRuntime }; }
public void Setup() { profile = new WindowsAzureProfile(new Mock<IProfileStore>().Object); profile.ImportPublishSettings(Data.ValidPublishSettings.First()); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new GetAzureSubscriptionCommand { Profile = profile, CommandRuntime = mockCommandRuntime }; }