當前位置: 首頁>>代碼示例>>C#>>正文


C# Program.Main方法代碼示例

本文整理匯總了C#中System.Program.Main方法的典型用法代碼示例。如果您正苦於以下問題:C# Program.Main方法的具體用法?C# Program.Main怎麽用?C# Program.Main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Program的用法示例。


在下文中一共展示了Program.Main方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetSecrets

        private void SetSecrets(bool fromCurrentDirectory)
        {
            var secrets = new KeyValuePair<string, string>[]
                        {
                            new KeyValuePair<string, string>("key1", Guid.NewGuid().ToString()),
                            new KeyValuePair<string, string>("Facebook:AppId", Guid.NewGuid().ToString()),
                            new KeyValuePair<string, string>(@"[email protected]\/.~123!#$%^&*())-+==", @"[email protected]\/.~123!#$%^&*())-+=="),
                            new KeyValuePair<string, string>("key2", string.Empty)
                        };

            var projectPath = UserSecretHelper.GetTempSecretProject();
            if (fromCurrentDirectory)
            {
                Directory.SetCurrentDirectory(projectPath);         // Point current directory to the project.json directory.
            }

            var logger = new TestLogger(_runtimeEnv);
            var secretManager = new Program(_runtimeEnv) { Logger = logger };

            foreach (var secret in secrets)
            {
                var parameters = fromCurrentDirectory ?
                    new string[] { "set", secret.Key, secret.Value } :
                    new string[] { "set", secret.Key, secret.Value, "-p", projectPath };
                secretManager.Main(parameters);
            }

            Assert.Equal(4, logger.Messages.Count);

            foreach (var keyValue in secrets)
            {
                Assert.Contains(
                    string.Format("Successfully saved {0} = {1} to the secret store.", keyValue.Key, keyValue.Value),
                    logger.Messages);
            }

            logger.Messages.Clear();
            var args = fromCurrentDirectory ?
                new string[] { "list" } : new string[] { "list", "-p", projectPath };
            secretManager.Main(args);
            Assert.Equal(4, logger.Messages.Count);
            foreach (var keyValue in secrets)
            {
                Assert.Contains(
                    string.Format("{0} = {1}", keyValue.Key, keyValue.Value),
                    logger.Messages);
            }

            // Remove secrets.
            logger.Messages.Clear();
            foreach (var secret in secrets)
            {
                var parameters = fromCurrentDirectory ?
                    new string[] { "remove", secret.Key } :
                    new string[] { "remove", secret.Key, "-p", projectPath };
                secretManager.Main(parameters);
            }

            // Verify secrets are removed.
            logger.Messages.Clear();
            args = fromCurrentDirectory ?
                new string[] { "list" } : new string[] { "list", "-p", projectPath };
            secretManager.Main(args);
            Assert.Equal(1, logger.Messages.Count);
            Assert.Contains(Resources.Error_No_Secrets_Found, logger.Messages);

            UserSecretHelper.DeleteTempSecretProject(projectPath);
        }
開發者ID:leloulight,項目名稱:UserSecrets,代碼行數:68,代碼來源:SecretManagerTests.cs

示例2: List_Empty_Secrets_File

 public void List_Empty_Secrets_File()
 {
     var projectPath = UserSecretHelper.GetTempSecretProject();
     var logger = new TestLogger(_runtimeEnv);
     var secretManager = new Program(_runtimeEnv) { Logger = logger };
     secretManager.Main(new string[] { "list", "-p", projectPath });
     Assert.Equal(1, logger.Messages.Count);
     Assert.Contains(Resources.Error_No_Secrets_Found, logger.Messages);
 }
開發者ID:leloulight,項目名稱:UserSecrets,代碼行數:9,代碼來源:SecretManagerTests.cs

示例3: SetSecret_With_Verbose_Flag

        public void SetSecret_With_Verbose_Flag()
        {
            var projectPath = UserSecretHelper.GetTempSecretProject();
            var logger = new TestLogger(_runtimeEnv, debug: true);
            var secretManager = new Program(_runtimeEnv) { Logger = logger };

            secretManager.Main(new string[] { "-v", "set", "secret1", "value1", "-p", projectPath });
            Assert.Equal(3, logger.Messages.Count);
            Assert.Contains(string.Format("Project file path {0}.", projectPath), logger.Messages);
            Assert.Contains(string.Format("Secrets file path {0}.", PathHelper.GetSecretsPath(projectPath)), logger.Messages);
            Assert.Contains("Successfully saved secret1 = value1 to the secret store.", logger.Messages);
            logger.Messages.Clear();

            secretManager.Main(new string[] { "-v", "list", "-p", projectPath });
            Assert.Equal(3, logger.Messages.Count);
            Assert.Contains(string.Format("Project file path {0}.", projectPath), logger.Messages);
            Assert.Contains(string.Format("Secrets file path {0}.", PathHelper.GetSecretsPath(projectPath)), logger.Messages);
            Assert.Contains("secret1 = value1", logger.Messages);

            UserSecretHelper.DeleteTempSecretProject(projectPath);
        }
開發者ID:leloulight,項目名稱:UserSecrets,代碼行數:21,代碼來源:SecretManagerTests.cs

示例4: Remove_Non_Existing_Secret

 public void Remove_Non_Existing_Secret()
 {
     var projectPath = UserSecretHelper.GetTempSecretProject();
     var logger = new TestLogger(_runtimeEnv);
     var secretManager = new Program(_runtimeEnv) { Logger = logger };
     secretManager.Main(new string[] { "remove", "secret1", "-p", projectPath });
     Assert.Equal(1, logger.Messages.Count);
     Assert.Contains("Cannot find 'secret1' in the secret store.", logger.Messages);
 }
開發者ID:leloulight,項目名稱:UserSecrets,代碼行數:9,代碼來源:SecretManagerTests.cs

示例5: SetSecret_Update_Existing_Secret

        public void SetSecret_Update_Existing_Secret()
        {
            var projectPath = UserSecretHelper.GetTempSecretProject();
            var logger = new TestLogger(_runtimeEnv);
            var secretManager = new Program(_runtimeEnv) { Logger = logger };

            secretManager.Main(new string[] { "set", "secret1", "value1", "-p", projectPath });
            Assert.Equal(1, logger.Messages.Count);
            Assert.Contains("Successfully saved secret1 = value1 to the secret store.", logger.Messages);
            secretManager.Main(new string[] { "set", "secret1", "value2", "-p", projectPath });
            Assert.Equal(2, logger.Messages.Count);
            Assert.Contains("Successfully saved secret1 = value2 to the secret store.", logger.Messages);

            logger.Messages.Clear();

            secretManager.Main(new string[] { "list", "-p", projectPath });
            Assert.Equal(1, logger.Messages.Count);
            Assert.Contains("secret1 = value2", logger.Messages);

            UserSecretHelper.DeleteTempSecretProject(projectPath);
        }
開發者ID:leloulight,項目名稱:UserSecrets,代碼行數:21,代碼來源:SecretManagerTests.cs


注:本文中的System.Program.Main方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。