当前位置: 首页>>代码示例>>C#>>正文


C# PowerShell.InvokeBatchScript方法代码示例

本文整理汇总了C#中PowerShell.InvokeBatchScript方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.InvokeBatchScript方法的具体用法?C# PowerShell.InvokeBatchScript怎么用?C# PowerShell.InvokeBatchScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PowerShell的用法示例。


在下文中一共展示了PowerShell.InvokeBatchScript方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTestCredential

 /// <summary>
 /// Creates the $credential object in the given <paramref name="powershell"/> instance with
 /// user name "testuser" and password "testpass".
 /// </summary>
 /// <param name="powershell">An instance of the <see cref="PowerShell"/> object.</param>
 public static void CreateTestCredential(PowerShell powershell)
 {
     // Create the test credential
     powershell.InvokeBatchScript(
     @"$user = ""testuser""",
     @"$pass = ""[email protected]"" | ConvertTo-SecureString -asPlainText -Force",
     @"$credential = New-Object System.Management.Automation.PSCredential($user, $pass)");
     Assert.IsTrue(powershell.Streams.Error.Count == 0);
 }
开发者ID:johnkors,项目名称:azure-sdk-tools,代码行数:14,代码来源:UnitTestHelper.cs

示例2: ImportSqlDatabaseModule

 /// <summary>
 /// Imports the SqlDatabase Test Manifest to the given <paramref name="powershell"/>
 /// instance.
 /// </summary>
 /// <param name="powershell">An instance of the <see cref="PowerShell"/> object.</param>
 public static void ImportSqlDatabaseModule(PowerShell powershell)
 {
     // Import the test manifest file
     powershell.InvokeBatchScript(
         string.Format(@"Import-Module .\{0}", SqlDatabaseTestManifest));
     Assert.IsTrue(powershell.Streams.Error.Count == 0);
 }
开发者ID:johnkors,项目名称:azure-sdk-tools,代码行数:12,代码来源:UnitTestHelper.cs

示例3: RemoveTestDatabasesWithCertAuth

        /// <summary>
        /// Helper function to remove the test databases.
        /// </summary>
        public static void RemoveTestDatabasesWithCertAuth(PowerShell powershell)
        {
            HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTest.Common.RemoveTestDatabasesWithCertAuth");

            ServerTestHelper.SetDefaultTestSessionSettings(testSession);

            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.");
                        Assert.IsTrue(
                            UnitTestHelper.GetUnitTestClientCertificate().Equals(actual.Certificate),
                            "Expected correct client certificate");
                    });

            using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
            {
                using (new MockHttpServer(
                    exceptionManager,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    testSession))
                {
                    powershell.InvokeBatchScript(
                        @"Remove-AzureSqlDatabase " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdb1 " +
                        @"-Force");
                    powershell.InvokeBatchScript(
                        @"Remove-AzureSqlDatabase " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdb2 " +
                        @"-Force");
                    powershell.InvokeBatchScript(
                        @"Remove-AzureSqlDatabase " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdb3 " +
                        @"-Force");
                }

                powershell.Streams.ClearStreams();
            }
        }
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:50,代码来源:NewAzureSqlDatabaseTests.cs

示例4: SetupUnitTestSubscription

        /// <summary>
        /// Common helper method for other tests to create a unit test subscription
        /// that connects to the mock server.
        /// </summary>
        /// <param name="powershell">The powershell instance used for the test.</param>
        public static WindowsAzureSubscription SetupUnitTestSubscription(PowerShell powershell)
        {
            UnitTestHelper.ImportAzureModule(powershell);

            // Set the client certificate used in the subscription
            powershell.Runspace.SessionStateProxy.SetVariable(
                "clientCertificate",
                UnitTestHelper.GetUnitTestClientCertificate());

            powershell.InvokeBatchScript(
                string.Format(
                    CultureInfo.InvariantCulture,
                    @"Set-AzureSubscription" +
                    @" -SubscriptionName {0}" +
                    @" -SubscriptionId {1}" +
                    @" -Certificate $clientCertificate" +
                    @" -ServiceEndpoint {2}",
                    UnitTestSubscriptionName,
                    UnitTestSubscriptionId,
                    MockHttpServer.DefaultHttpsServerPrefixUri.AbsoluteUri));
            powershell.InvokeBatchScript(
                string.Format(
                    CultureInfo.InvariantCulture,
                    @"Select-AzureSubscription" +
                    @" -SubscriptionName {0}",
                    UnitTestSubscriptionName));
            Collection<PSObject> subscriptionResult = powershell.InvokeBatchScript(
                string.Format(
                    CultureInfo.InvariantCulture,
                    @"Get-AzureSubscription" +
                    @" -Current"));

            Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
            Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
            powershell.Streams.ClearStreams();

            PSObject subscriptionPsObject = subscriptionResult.Single();
            WindowsAzureSubscription subscription =
                subscriptionPsObject.BaseObject as WindowsAzureSubscription;
            Assert.IsTrue(subscription != null, "Expecting a WindowsAzureSubscription object");

            return subscription;
        }
开发者ID:takekazuomi,项目名称:azure-sdk-tools,代码行数:48,代码来源:UnitTestHelper.cs

示例5: CreateTestDatabasesWithCertAuth

        /// <summary>
        /// Helper function to create the test databases.
        /// </summary>
        public static void CreateTestDatabasesWithCertAuth(PowerShell powershell)
        {
            HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTest.Common.CreateTestDatabasesWithCertAuth");

            ServerTestHelper.SetDefaultTestSessionSettings(testSession);

            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.");
                        Assert.IsTrue(
                            UnitTestHelper.GetUnitTestClientCertificate().Equals(actual.Certificate),
                            "Expected correct client certificate");
                    });

            using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
            {
                Collection<PSObject> database1, database2, database3;
                using (new MockHttpServer(
                    exceptionManager,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    testSession))
                {
                    database1 = powershell.InvokeBatchScript(
                        @"$testdb1 = New-AzureSqlDatabase " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdb1 " +
                        @"-Force",
                        @"$testdb1");
                    database2 = powershell.InvokeBatchScript(
                        @"$testdb2 = New-AzureSqlDatabase " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdb2 " +
                        @"-Collation Japanese_CI_AS " +
                        @"-Edition Web " +
                        @"-MaxSizeGB 5 " +
                        @"-Force",
                        @"$testdb2");
                    database3 = powershell.InvokeBatchScript(
                        @"$testdb3 = New-AzureSqlDatabase " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdb3 " +
                        @"-MaxSizeBytes 104857600 " +
                        @"-Force",
                        @"$testdb3");
                }

                Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
                Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
                powershell.Streams.ClearStreams();

                Services.Server.Database database = database1.Single().BaseObject as Services.Server.Database;
                Assert.IsTrue(database != null, "Expecting a Database object");
                DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb1", "Web", 1, 1073741824L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid);

                database = database2.Single().BaseObject as Services.Server.Database;
                Assert.IsTrue(database != null, "Expecting a Database object");
                DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb2", "Web", 5, 5368709120L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid);

                database = database3.Single().BaseObject as Services.Server.Database;
                Assert.IsTrue(database != null, "Expecting a Database object");
                DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb3", "Web", 0, 104857600L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid);
            }
        }
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:72,代码来源:NewAzureSqlDatabaseTests.cs


注:本文中的PowerShell.InvokeBatchScript方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。