public static string GenerateASCIINameWithInvalidCharacters(int length, char[] InvalidChars = null) { if (null == InvalidChars) { InvalidChars = InvalidFileNameCharacters; } int numberOfInavlidCharacters = RandomGen.Next(1, length); int numberOfValidCharacters = length - numberOfInavlidCharacters; StringBuilder sb = new StringBuilder(GenerateNameFromRange(numberOfValidCharacters, ValidASCIIRange)); var invalidCharList = new List <char>(InvalidFileNameCharacters); if (AgentFactory.GetLanguage() == Language.NodeJS) { invalidCharList.Remove('"'); invalidCharList.Remove('\''); } if (AgentFactory.GetOSType() != OSType.Windows) { // remove bash control characters invalidCharList.Remove('('); invalidCharList.Remove('$'); } for (int i = 0; i < numberOfInavlidCharacters; i++) { int position = RandomGen.Next(sb.Length); char invalidCharacter = invalidCharList[RandomGen.Next(invalidCharList.Count)]; sb.Insert(position, invalidCharacter); } return(sb.ToString()); }
protected static void SetCLIEnv(TestContext testContext) { //add the language specific initialization lang = AgentFactory.GetLanguage(testContext.Properties); isMooncake = Utility.GetTargetEnvironment().Name == "AzureChinaCloud"; string mode = Test.Data.Get("IsResourceMode"); if (!string.IsNullOrEmpty(mode)) { isResourceMode = bool.Parse(mode); } if (lang == Language.PowerShell) { if (isResourceMode) { PowerShellAgent.ImportModules(Constants.ResourceModulePaths);; } else { PowerShellAgent.ImportModules(Constants.ServiceModulePaths); } string snapInName = Test.Data.Get("PSSnapInName"); if (!string.IsNullOrWhiteSpace(snapInName)) { PowerShellAgent.AddSnapIn(snapInName); } //set the default storage context PowerShellAgent.SetStorageContext(StorageAccount.ToString(true)); } else if (lang == Language.NodeJS) { NodeJSAgent.GetOSConfig(Test.Data); // use ConnectionString parameter by default in function test NodeJSAgent.AgentConfig.ConnectionString = StorageAccount.ToString(true); FileUtil.GetOSConfig(Test.Data); } }