public static void Update(string fileName, string configPath, EasyTest easyTest) { using (var optionsStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { Options options = Options.LoadOptions(optionsStream, null, null, configPath); UpdateAppConfigFiles(easyTest, options); } }
public static void UpdateTestFile(EasyTest easyTest) { var xmlSerializer = new XmlSerializer(typeof(Options)); var stringReader = new StringReader(File.ReadAllText(Path.Combine(Path.GetDirectoryName(easyTest.FileName) + "", "config.xml"))); var options = (Options)xmlSerializer.Deserialize(stringReader); UpdateTestFileCore(easyTest.FileName, easyTest.Users.Last(), options); foreach (var includedFile in IncludedFiles(easyTest.FileName)) { UpdateTestFileCore(includedFile, easyTest.Users.Last(), options); } }
public static void UpdateTestConfig(EasyTest easyTest, string fileName) { var user = easyTest.Users.Last(); var xmlSerializer = new XmlSerializer(typeof(Options)); var options = (Options)xmlSerializer.Deserialize(new StringReader(File.ReadAllText(fileName))); UpdatePort(easyTest, options); UpdateAppBinAlias(user, options); UpdateDataBases(user, options); using (var writer = new StreamWriter(fileName)) using (var xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings { Indent = true })) xmlSerializer.Serialize(xmlWriter, options); }
public static void UpdateAdditionalApps(EasyTest easyTest, Options options, User user) { var additionalApps =options.Applications.Cast<TestApplication>() .SelectMany(application => application.AdditionalAttributes) .Where(attribute => attribute.LocalName == "AdditionalApplications") .Select(attribute => attribute.Value); foreach (var additionalApp in additionalApps){ var path = Path.Combine(Path.GetDirectoryName(additionalApp) + "", Path.GetFileName(additionalApp) + ".config"); var document = XDocument.Load(path); UpdateAppConfigCore(easyTest, options, user, document); document.Save(path); } }
private static void UpdatePort(EasyTest easyTest, Options options) { foreach (var application in options.Applications.Cast<TestApplication>()) { var additionalAttribute = application.AdditionalAttributes.FirstOrDefault( attribute => attribute.LocalName.ToLowerInvariant() == "communicationport"); if (additionalAttribute != null) additionalAttribute.Value = easyTest.WinPort.ToString(CultureInfo.InvariantCulture); else { additionalAttribute = application.AdditionalAttributes.First(attribute => attribute.LocalName.ToLowerInvariant() == "url"); additionalAttribute.Value = "http://localhost:" + easyTest.WebPort; } } }
private static LogTests GetLogTests(EasyTest easyTest) { var directoryName = Path.GetDirectoryName(easyTest.FileName) + ""; var fileName = Path.Combine(directoryName, "testslog.xml"); using (var optionsStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { return LogTests.LoadTestsResults(optionsStream); } }
private static void SetupEnviroment(string configPath, EasyTest easyTest) { string fileName = Path.Combine(configPath, "config.xml"); TestUpdater.UpdateTestConfig(easyTest, fileName); AppConfigUpdater.Update(fileName, configPath, easyTest); TestUpdater.UpdateTestFile(easyTest); }
private static void RunTest(string[] args, Queue<EasyTest> testsQueque, EasyTest easyTest) { TestEnviroment.KillWebDev(easyTest.Users.Last().Name); try { bool processAsUser = ProcessAsUser(args[0], easyTest); if (!processAsUser && easyTest.Users.Count < 3) testsQueque.Enqueue(easyTest); } catch (Exception e) { LogErrors(easyTest, e); } }
private static bool ProcessAsUser(string version, EasyTest easyTest) { Process process; string directoryName = Path.GetDirectoryName(easyTest.FileName) + ""; lock (_locker) { var user = easyTest.Users.Last(); Trace.TraceInformation(user.Name + " WinPort:" + easyTest.WinPort + " WebPort:" + easyTest.WebPort + " -->" + easyTest.FileName); SetupEnviroment(directoryName, easyTest); var arguments = string.Format("-e TestExecutor.v{0}.exe -u {1} -p {2} -a {3}", version, user.Name, user.Password, Path.GetFileName(easyTest.FileName)); process = new Process { StartInfo = new ProcessStartInfo(Path.Combine(directoryName, "ProcessAsUser.exe"), arguments) { UseShellExecute = false, RedirectStandardOutput = true, WorkingDirectory = directoryName } }; process.Start(); Thread.Sleep(5000); } process.WaitForExit(); lock (_locker) { CopyXafLogToPath(directoryName); var logTests = GetLogTests(easyTest).Tests.Where(test => test.Name.ToLowerInvariant() == (Path.GetFileNameWithoutExtension(easyTest.FileName) + "").ToLowerInvariant()).ToArray(); if (logTests.All(test => test.Result == "Passed")) { Trace.TraceInformation(easyTest.FileName + " passed"); return true; } Trace.TraceInformation(easyTest.FileName + " not passed=" + string.Join(Environment.NewLine, logTests.SelectMany(test => test.Errors.Select(error => error.Message.Text)))); return false; } }
private static void LogErrors(EasyTest easyTest, Exception e) { lock (_locker) { var directoryName = Path.GetDirectoryName(easyTest.FileName) + ""; string fileName = Path.Combine(directoryName, "config.xml"); using (var optionsStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { Options options = Options.LoadOptions(optionsStream, null, null, directoryName); var logTests = new LogTests(); foreach (var application in options.Applications.Cast<TestApplication>()) { var logTest = new LogTest { ApplicationName = application.Name, Result = "Failed" }; var logError = new LogError { Message = { Text = e.ToString() } }; logTest.Errors.Add(logError); logTests.Tests.Add(logTest); } logTests.Save(Path.Combine(directoryName, "TestsLog.xml")); } } Trace.TraceError(e.ToString()); }
private static void UpdateAppConfig(EasyTest easyTest, Options options, TestAlias alias, User user) { var keyValuePair = LoadAppConfig(alias, options.Applications); if (File.Exists(keyValuePair.Value)) { var document = keyValuePair.Key; UpdateAppConfigCore(easyTest, options, user, document); document.Save(keyValuePair.Value); } }
private static void UpdateAppConfigFiles(EasyTest easyTest, Options options) { var user = easyTest.Users.Last(); if (user.Name!=null){ foreach (var alias in options.Aliases.Cast<TestAlias>().Where(@alias => alias.ContainsAppPath())){ var sourcePath = Path.GetFullPath(alias.UpdateAppPath(null)); if (Directory.Exists(sourcePath)){ var destPath = Path.GetFullPath(alias.UpdateAppPath(user.Name)); DirectoryCopy(sourcePath, destPath, true, sourcePath + @"\" + Program.EasyTestUsersDir); UpdateAppConfig(easyTest, options, alias, user); } } } UpdateAdditionalApps(easyTest, options, user); }
private static void UpdateAppConfigCore(EasyTest easyTest, Options options, User user, XDocument document) { UpdatePort(easyTest.WinPort, document); UpdateConnectionStrings(user, options, document); }