public SMTestBase() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); System.Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; BaseSetup(); }
protected void RunPowerShellTest(params string[] scripts) { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); using (UndoContext context = UndoContext.Current) { context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2)); SetupManagementClients(); List <string> modules = new List <string>(); modules.Add(Path.Combine(EnvironmentSetupHelper.PackageDirectory, @"ServiceManagement\Azure\Compute\AzurePreview.psd1")); modules.Add(Path.Combine(EnvironmentSetupHelper.PackageDirectory, @"ServiceManagement\Azure\Compute\PIR.psd1")); modules.AddRange(Directory.GetFiles(@"Resources\ServiceManagement".AsAbsoluteLocation(), "*.ps1").ToList()); helper.SetupEnvironment(AzureModule.AzureServiceManagement); helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray()); var scriptEnvPath = new List <string>(); scriptEnvPath.Add( string.Format( "$env:PSModulePath=\"{0};$env:PSModulePath\"", Path.Combine(EnvironmentSetupHelper.PackageDirectory, @"ServiceManagement\Azure\Compute").AsAbsoluteLocation())); helper.RunPowerShellTest(scriptEnvPath.ToArray(), scripts); } }
public AddAzureEnvironmentTests() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); dataStore = new MemoryDataStore(); AzureSession.Instance.DataStore = dataStore; }
public EnvironmentSetupHelper() { TestExecutionHelpers.SetUpSessionAndProfile(); var datastore = new MemoryDataStore(); AzureSession.Instance.DataStore = datastore; var rmprofile = new AzureRmProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile)); rmprofile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault())); rmprofile.DefaultContext = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.EnvironmentTable["foo"], new AzureTenant()); rmprofile.DefaultContext.Subscription.SetEnvironment("foo"); if (AzureRmProfileProvider.Instance.Profile == null) { AzureRmProfileProvider.Instance.Profile = rmprofile; } AzureSession.Instance.DataStore = datastore; // Ignore SSL errors System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true; #if !NETSTANDARD ServiceManagementProfileProvider.InitializeServiceManagementProfile(); var profile = new AzureSMProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile)); ProfileClient = new ProfileClient(profile); AdalTokenCache.ClearCookies(); #endif // Set RunningMocked TestMockSupport.RunningMocked = HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback; }
public void BaseSetup() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); if (AzureSession.Instance.DataStore == null || (AzureSession.Instance.DataStore != null && !(AzureSession.Instance.DataStore is MemoryDataStore))) { AzureSession.Instance.DataStore = new MemoryDataStore(); } currentProfile = new AzureSMProfile(); if (currentProfile.Context.Subscription == null) { var newGuid = Guid.NewGuid(); var client = new ProfileClient(currentProfile); var account = new AzureAccount { Id = "test", Type = AzureAccount.AccountType.User, }; account.SetSubscriptions(newGuid.ToString()); client.AddOrSetAccount(account); var sub = new AzureSubscription { Id = newGuid.ToString(), Name = "test" }; sub.SetEnvironment(EnvironmentName.AzureCloud); sub.SetAccount("test"); client.AddOrSetSubscription(sub); client.SetSubscriptionAsDefault(newGuid, "test"); } AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
protected void RunPowerShellTest(params string[] scripts) { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); using (UndoContext context = UndoContext.Current) { context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2)); SetupManagementClients(); var modules = new List <string> { "Resources\\SqlIaaSExtension\\SqlIaaSExtensionTests.ps1", "Resources\\ServiceManagement\\Common.ps1", ".\\Assert.ps1", @"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute\AzurePreview.psd1" }; helper.SetupEnvironment(AzureModule.AzureServiceManagement); helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray()); var scriptEnvPath = new List <string>(); scriptEnvPath.Add( string.Format( "$env:PSModulePath=\"{0};$env:PSModulePath\"", @"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Compute".AsAbsoluteLocation())); helper.RunPowerShellTest(scriptEnvPath, scripts); } }
public virtual void SetupTest() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); new FileSystemHelper(this).CreateAzureSdkDirectoryAndImportPublishSettings(); currentProfile = new AzureSMProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile)); }
public CommonDataCmdletTests(ITestOutputHelper output) { TestExecutionHelpers.SetUpSessionAndProfile(); XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); #if !NETSTANDARD ServiceManagementProfileProvider.InitializeServiceManagementProfile(); #endif }
public void SetupTest() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); AzureSMProfileProvider.Instance.Profile = new AzureSMProfile(); // Create 2 test databases NewAzureSqlDatabaseTests.CreateTestDatabasesWithSqlAuth(); }
public static void InitializeClass(TestContext context) { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); AzureSMProfileProvider.Instance.Profile = new AzureSMProfile(); // Create atleast two test databases NewAzureSqlDatabaseTests.CreateTestDatabasesWithSqlAuth(); // Remove the test databases NewAzureSqlDatabaseTests.RemoveTestDatabasesWithSqlAuth(); }
public void GetsSlots() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); // Setup string slot = "staging"; var clientMock = new Mock <IWebsitesClient>(); clientMock.Setup(c => c.ListWebsites(slot)) .Returns(new List <Site> { new Site { Name = "website1(stage)", WebSpace = "webspace1" }, new Site { Name = "website2(stage)", WebSpace = "webspace1" } }); clientMock.Setup(c => c.GetWebsiteConfiguration(It.IsAny <string>(), slot)) .Returns(new SiteConfig { PublishingUsername = "******" }); SetupProfile(null); // Test var getAzureWebsiteCommand = new GetAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object, Slot = slot }; getAzureWebsiteCommand.ExecuteWithProcessing(); IEnumerable <Site> sites = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)getAzureWebsiteCommand.CommandRuntime).OutputPipeline).Cast <Site>(); Assert.NotNull(sites); Assert.NotEmpty(sites); Assert.Equal(2, sites.Count()); var website1 = sites.ElementAt(0); var website2 = sites.ElementAt(1); Assert.NotNull(website1); Assert.NotNull(website2); Assert.Equal("website1(stage)", website1.Name); Assert.Equal("website2(stage)", website2.Name); }
public void InitializeTest() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); powershell = System.Management.Automation.PowerShell.Create(); MockHttpServer.SetupCertificates(); UnitTestHelper.SetupUnitTestSubscription(powershell); serverName = SqlDatabaseTestSettings.Instance.ServerName; powershell.Runspace.SessionStateProxy.SetVariable("serverName", serverName); }
public virtual void Initialize() { if (!IsInitialized) { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); TestRunSetup(); IsInitialized = true; } this.ApplyFullMocking(); this.ResetIndividualMocks(); }
public void RunPsTest(params string[] scripts) { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); var callingClassType = TestUtilities.GetCallingClass(2); var mockName = TestUtilities.GetCurrentMethodName(2); RunPsTestWorkflow( () => scripts, // no custom initializer null, // no custom cleanup null, callingClassType, mockName); }
public void InitializeTest() { TestStartTime = DateTime.Now; AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); AzureSMProfileProvider.Instance.Profile = new AzureSMProfile(); AzureSession.Instance.DataStore = new MemoryDataStore(); // This test uses the https endpoint, setup the certificates. MockHttpServer.SetupCertificates(); PowerShell = System.Management.Automation.PowerShell.Create(); Subscription = UnitTestHelper.SetupUnitTestSubscription(PowerShell); // Set names for the servers we'll use in PowerShell. PowerShell.Runspace.SessionStateProxy.SetVariable( "homeServerName", HomeServer); PowerShell.Runspace.SessionStateProxy.SetVariable( "partnerServerName", PartnerServer); // Create a new server HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession( string.Format("UnitTest.{0}.{1}", TestContext.FullyQualifiedTestClassName, TestContext.TestName)); ServerTestHelper.SetDefaultTestSessionSettings(testSession); // When testing production use RDFE // testSession.ServiceBaseUri = new Uri("https://management.core.windows.net"); // When testing OneBox use Mock RDFE: if (IsRunningAgainstOneBox) { testSession.ServiceBaseUri = new Uri("https://management.dev.mscds.com:12346/"); } testSession.RequestValidator = new Action <HttpMessage, HttpMessage.Request>( (expected, actual) => { Assert.AreEqual(expected.RequestInfo.Method, actual.Method); Assert.IsTrue( actual.UserAgent.Contains(ApiConstants.UserAgentHeaderValue), "Missing proper UserAgent string."); }); ExceptionManager = new AsyncExceptionManager(); MockHttpServer = new MockHttpServer(ExceptionManager, MockHttpServer.DefaultHttpsServerPrefixUri, testSession); }
/// <summary> /// When running this test double check that the certificate used in Azure.PublishSettings has not expired. /// </summary> public PublishContextTests() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); AzurePowerShell.ProfileDirectory = Test.Utilities.Common.Data.AzureSdkAppDir; service = new AzureServiceWrapper(Directory.GetCurrentDirectory(), Path.GetRandomFileName(), null); service.CreateVirtualCloudPackage(); packagePath = service.Paths.CloudPackage; configPath = service.Paths.CloudConfiguration; settings = ServiceSettingsTestData.Instance.Data[ServiceSettingsState.Default]; ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile))); AzureSession.Instance.DataStore.WriteFile(Test.Utilities.Common.Data.ValidPublishSettings.First(), File.ReadAllText(Test.Utilities.Common.Data.ValidPublishSettings.First())); client.ImportPublishSettings(Test.Utilities.Common.Data.ValidPublishSettings.First(), null); client.Profile.Save(); }
public void OnImport() { try { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); System.Management.Automation.PowerShell invoker = null; invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace); invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServiceManagementStartup.ps1"))); invoker.Invoke(); } catch { // This will throw exception for tests, ignore. } }
public GetIPForwardingTests() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); this.networkingClientMock = new Mock <INetworkManagementClient>(); this.computeClientMock = new Mock <IComputeManagementClient>(); this.managementClientMock = new Mock <IManagementClient>(); this.mockCommandRuntime = new MockCommandRuntime(); this.client = new NetworkClient( networkingClientMock.Object, computeClientMock.Object, managementClientMock.Object, mockCommandRuntime); this.computeClientMock .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse() { Name = DeploymentName })); this.networkingClientMock .Setup(c => c.IPForwarding.GetForRoleAsync( ServiceName, DeploymentName, RoleName, It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new IPForwardingGetResponse() { State = "Enabled" })); this.networkingClientMock .Setup(c => c.IPForwarding.GetForNetworkInterfaceAsync( ServiceName, DeploymentName, RoleName, NetworkInterfaceName, It.IsAny <CancellationToken>())) .Returns(Task.Factory.StartNew(() => new IPForwardingGetResponse() { State = "Disabled" })); }
public void SetupTest() { AzureSessionInitializer.InitializeAzureSession(); ServiceManagementProfileProvider.InitializeServiceManagementProfile(); AzureSMProfileProvider.Instance.Profile = new AzureSMProfile(); }
public EnvironmentSetupHelper() { var module = GetModuleManifest(RmDirectory, "AzureRM.Accounts"); if (string.IsNullOrWhiteSpace(module)) { throw new InvalidOperationException("Could not find Accounts module"); } LogIfNotNull($"Accounts Module path: {module}"); RMProfileModule = module; module = GetModuleManifest(RmDirectory, "AzureRM.Resources"); LogIfNotNull($"Resources Module path: {module}"); RMResourceModule = module; module = GetModuleManifest(RmDirectory, "AzureRM.Insights"); LogIfNotNull($"Insights Module path: {module}"); RMInsightsModule = module; module = GetModuleManifest(RmDirectory, "AzureRM.Storage"); LogIfNotNull($"Storage Management Module path: {module}"); RMStorageModule = module; module = GetModuleManifest(StorageDirectory, "Azure.Storage"); LogIfNotNull($"Storage Data Plane Module path: {module}"); RMStorageDataPlaneModule = module; module = GetModuleManifest(RmDirectory, "AzureRM.OperationalInsights"); LogIfNotNull($"Storage Data Plane Module path: {module}"); RMOperationalInsightsModule = module; module = GetModuleManifest(RmDirectory, "AzureRM.Network"); LogIfNotNull($"Network Module path: {module}"); RMNetworkModule = module; module = GetModuleManifest(StackRmDirectory, "AzureRM.Accounts"); LogIfNotNull($"Stack Accounts Module path: {module}"); StackRMProfileModule = module; module = GetModuleManifest(StackRmDirectory, "AzureRM.Resources"); LogIfNotNull($"Stack Resources Module path: {module}"); StackRMResourceModule = module; module = GetModuleManifest(StackRmDirectory, "AzureRM.Storage"); LogIfNotNull($"Stack Storage Management Plane Module path: {module}"); StackRMStorageModule = module; module = GetModuleManifest(StackStorageDirectory, "Azure.Storage"); LogIfNotNull($"Stack Storage Data Plane Module path: {module}"); StackRMStorageDataPlaneModule = module; TestExecutionHelpers.SetUpSessionAndProfile(); IDataStore datastore = new MemoryDataStore(); if (AzureSession.Instance.DataStore != null && (AzureSession.Instance.DataStore is MemoryDataStore)) { datastore = AzureSession.Instance.DataStore; } AzureSession.Instance.DataStore = datastore; var rmprofile = new AzureRmProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile)); rmprofile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault())); rmprofile.DefaultContext = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.EnvironmentTable["foo"], new AzureTenant()); rmprofile.DefaultContext.Subscription.SetEnvironment("foo"); if (AzureRmProfileProvider.Instance.Profile == null) { AzureRmProfileProvider.Instance.Profile = rmprofile; } AzureSession.Instance.DataStore = datastore; // Ignore SSL errors System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true; #if !NETSTANDARD ServiceManagementProfileProvider.InitializeServiceManagementProfile(); var profile = new AzureSMProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile)); ProfileClient = new ProfileClient(profile); AdalTokenCache.ClearCookies(); #endif // Set RunningMocked TestMockSupport.RunningMocked = HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback; if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".azure", "testcredentials.json"))) { SetEnvironmentVariableFromCredentialFile(); } }