public ResultsFile RunAlone(string id, IEnumerable <string> dlls) { #if x64 if (!Environment.Is64BitProcess) { throw new Exception("This runner is expected to run 64bit"); } #endif #if SILVERLIGHT var am = dlls.Select(Assembly.Load).ToList(); #else var am = dlls.Select(Assembly.LoadFile).ToList(); #endif var runner = Runner.Create(id, am); PrintOutAloneStart(id); var file = new ResultsFile(); runner.RunAll(r => { PrintOutAloneResults(r); file.Add(r); }); PrintOutAloneEnd(id, file); return(file); }
public static string GenerateReport(ResultsFile resultsFile) { var template = File.ReadAllText(Application.GetEmbeddedFile(typeof(ReportBuilder).Assembly, "Template.html")); var errorMessages = Safe(_ => GetErrorMessages(resultsFile)) ?? new string[0]; var errorText = GetMessagesText(errorMessages, "error"); var warningMessages = Safe(_ => GetWarningMessages(resultsFile)) ?? new string[0]; var warningText = GetMessagesText(warningMessages, "warning"); var debugMessages = Safe(_ => GetDebugMessages(resultsFile)) ?? new string[0]; var debugText = GetMessagesText(debugMessages, "debug"); var cannotRunMessages = Safe(_ => GetCannotRunMessages(resultsFile)) ?? new string[0]; var cannotRunText = GetMessagesText(cannotRunMessages, "cannot run"); return(template .Replace("<span class=\"placeholder-messages-total-count\"></span>", Safe(_ => GetMessagesTotalCount(errorMessages.Length, warningMessages.Length, resultsFile))) .Replace("<span class=\"placeholder-error-messages-count\"></span>", $"{errorMessages.Length}") .Replace("<span class=\"placeholder-warning-messages-count\"></span>", $"{warningMessages.Length}") .Replace("<span class=\"placeholder-run-tests-count\"></span>", Safe(_ => GetRunTestsCount(resultsFile))) .Replace("<span class=\"placeholder-total-tests-count\"></span>", Safe(_ => GetTotalTestsCount())) .Replace("<span class=\"placeholder-instances-count\"></span>", Safe(_ => GetInstancesCount(resultsFile))) .Replace("<span class=\"placeholder-report-created\"></span>", Safe(_ => GetReportCreated())) .Replace("<div class=\"placeholder-instances-roles\"></div>", Safe(_ => GetInstancesRoles(resultsFile))) .Replace("<div class=\"placeholder-instances-modules\"></div>", Safe(_ => GetInstancesModules(resultsFile))) .Replace("<div class=\"placeholder-error-messages\"></div>", Safe(_ => errorText)) .Replace("<div class=\"placeholder-warning-messages\"></div>", warningText) .Replace("<div class=\"placeholder-cannot-run-messages\"></div>", cannotRunText) .Replace("<div class=\"placeholder-debug-messages\"></div>", debugText)); }
static int Main(string[] args) { ConventionTestProcessor.CIResultOutput.Disable = true; var id = "net40-converage"; var asms = new[] { Assembly.GetAssembly(typeof(BasicTests.Basic)), Assembly.GetAssembly(typeof(ConstraintsTests.Basic)), Assembly.GetAssembly(typeof(XunitTests.Basic)), Assembly.GetAssembly(typeof(NunitTests.Basic)), Assembly.GetAssembly(typeof(FsUnitTests.BasicTests)), }; var runner = Runner.Create(id, asms); var file = new ResultsFile(); runner.RunAll(r => { string js = r.ToItemJson(); var r2 = Newtonsoft.Json.JsonConvert.DeserializeObject <Result>(js); file.Add(r2); }); var result = file.ToListJson(); return(ConventionTestProcessor.Program.VerifyJsonResults(new[] { result })); }
private static List <ResultsFile> FilesInTestCases(Dictionary <string, object> data) { Dictionary <string, object> results = (Dictionary <string, object>)data["results"]; List <Dictionary <string, object> > cases = (List <Dictionary <string, object> >)results["cases"]; var files = new List <ResultsFile>(); int num = 0; foreach (Dictionary <string, object> c in cases) { if (c.ContainsKey("files")) { List <string> caseFiles = (List <string>)c["files"]; foreach (string caseFile in caseFiles) { var resultsFile = new ResultsFile() { Num = num, File = caseFile }; files.Add(resultsFile); } } num++; } return(files); }
private static string GetInstancesModules(ResultsFile resultsFile) { var contexts = resultsFile.Packages.Values .ToArray(x => x.GetResources().OfType <ISitecoreInformationContext>().FirstOrDefault()); var map = contexts.SelectMany(x => x.ModulesInformation.InstalledModules.Values.Select(z => new { InstanceName = x.InstanceName, ProductName = $"{z.Release.ProductName}", Version = $"{z.Release.Version}", })).GroupBy(x => x.ProductName); if (!map.Any()) { return(""); } var sb = new StringBuilder(); new Table(map.ToArray(x => new TableRow( new[] { new Pair("Module", x.Key) } .Concat(x.Select(z => new Pair(z.InstanceName, z.Version))) .ToArray()))) .ToHtml(sb); return("<h3>Modules:</h3><div>" + sb + "</div>"); }
private static string GetRunTestsCount(ResultsFile resultsFile) { var runTestsCount = resultsFile.Solution .Where(x => !x.Results.CannotRun.Any()) .GroupBy(x => x.Owner.Name) .Count(); return($"{runTestsCount}"); }
public static void ToFiles(ResultsFile file, IDictionary <string, string> typesAndPaths) { foreach (var typeAndPath in typesAndPaths) { switch (typeAndPath.Key) { default: File.WriteAllText(typeAndPath.Value, file.ToListJson()); break; } } }
public override int GetHashCode() { unchecked { var result = base.GetHashCode(); result = (result * 397) ^ ResultsFile.GetHashCode(); result = (result * 397) ^ PrecursorMz.GetHashCode(); result = (result * 397) ^ MatchedPrecursorMz.GetHashCode(); result = (result * 397) ^ RetentionTime.GetHashCode(); result = (result * 397) ^ MzBytes.GetHashCode(); result = (result * 397) ^ IntensityBytes.GetHashCode(); return(result); } }
public override int GetHashCode() { unchecked { var result = base.GetHashCode(); result = (result * 397) ^ ResultsFile.GetHashCode(); result = (result * 397) ^ PrecursorMz.GetHashCode(); result = (result * 397) ^ MatchedPrecursorMz.GetHashCode(); result = (result * 397) ^ (DocumentPeptide == null ? 0 : DocumentPeptide.GetHashCode()); result = (result * 397) ^ DocumentPrecursorCharge.GetHashCode(); result = (result * 397) ^ RetentionTime.GetHashCode(); result = (result * 397) ^ MzBytes.GetHashCode(); result = (result * 397) ^ IntensityBytes.GetHashCode(); return(result); } }
public void WhenFinished(ResultsFile file) { var rt = new RunTests(); rt.PrintOutAloneStart(_id); foreach (var r in file.Results) { rt.PrintOutAloneResults(r); } rt.PrintOutAloneEnd(_id, file); if (_outputs != null && _outputs.Any()) { WriteResults.ToFiles(file, _outputs); Environment.ExitCode = file.HasError ? 1 : 0; } }
public void PrintOutAloneEnd(string id, ResultsFile file) { if (TeamCity) { Console.WriteLine("##teamcity[testSuiteStarted name='{0}']", id); } else { Console.WriteLine("Finished"); Console.WriteLine(); var resultCount = file.ResultCount; foreach (var kp in resultCount.OrderBy(it => it.Key)) { Console.WriteLine(" {0,-15}{1,4}", kp.Key, kp.Value); } Console.WriteLine("{0,-17}{1,4}", "Total", resultCount.Select(r => r.Value).Sum()); } }
public static ResultsFile RunTests([NotNull] SupportPackageDataProvider[] packages, [NotNull] ISystemContext system, [CanBeNull] Action <ITestMetadata, int, int> onTestRun = null) { // get tests TestsLibrary.Init(); var solutionTests = new TestManager() .GetTests() .ToArray(); var totalCount = solutionTests.Length; // run solution tests var resultsFile = new ResultsFile(); resultsFile.Solution = new TestRunner() .RunTests(solutionTests, packages, system, (test, index) => onTestRun?.Invoke(test, index, totalCount)) .ToArray(); resultsFile.Packages = packages.ToMap(x => x.FileName, x => x as IDataProvider); return(resultsFile); }
private static string GetInstancesRoles(ResultsFile resultsFile) { var contexts = resultsFile.Packages.Values .ToArray(x => new { SitecoreInformationContext = x.GetResources().OfType <ISitecoreInformationContext>().FirstOrDefault(), RolesContext = x.GetResources().OfType <IServerRolesContext>().FirstOrDefault(), }); var data = contexts .ToArray(x => new { InstanceName = x.SitecoreInformationContext?.InstanceName, Roles = x.RolesContext?.Select(z => z.ToString().EmptyToNull()) }); var instancesRoles = data .Where(x => x.InstanceName != null && x.Roles != null) .Select(x => $"<tr><td>{x.InstanceName}<td>{string.Join(", ", x.Roles)}") .JoinToString("\r\n"); return(instancesRoles); }
private static string GetInstancesCount(ResultsFile resultsFile) { var instancesCount = $"{resultsFile.Packages?.Count ?? -1}"; return(instancesCount); }
public GoalDifferenceCalculator(ResultsFile results) { _results = results; }
private static string GetMessagesTotalCount(int errorMessages, int warningMessages, ResultsFile resultsFile) { var count = errorMessages + warningMessages + resultsFile.Solution.Count(z => z.Results.DebugLogs.Any(c => c != null)); return($"{count}"); }
public void Test() { var test = new TestMetadata("MyTest"); var simple = "There is an issue"; var link = new Uri("http://localhost"); var results = new TestResults(); results.Add(new TestOutput(TestResultState.Error, simple, link, new DetailedMessage(new Container(new Text("Detailed issue variant 1"), new BulletedList("list item 1", "list item 2"))), "instance1")); results.Add(new TestOutput(TestResultState.Error, simple, link, new DetailedMessage(new Container(new Text("Detailed issue variant 1"), new BulletedList("list item 1", "list item 2"))), "instance2")); results.Add(new TestOutput(TestResultState.Error, simple, link, new DetailedMessage(new Container(new Text("Detailed issue variant 2"), new BulletedList("list item 3"))), "instance3")); var file = new ResultsFile { Solution = new ITestReport[] { new TestReport(test, results), } }; var errors = ReportBuilder.GetMessagesText(ReportBuilder.GetErrorMessages(file), "errors").Replace("\r", "").Replace("\n", "").Replace(" ", " ").Replace(" ", " "); AssertEqual(("" + " <div class='alert alert-danger alert-dismissible fade show' role='alert'> " + " <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span> </button> " + " <h4 class='alert-heading'> " + " <a href='#E1'>E1</a>. <span class='test-name'>MyTest</span>" + " </h4>" + " <div class='short-message'>" + " There is an issue" + " </div>" + " <a href='#' data-toggle='modal' data-target='#E1-details'>See full details.</a> " + " <div id='E1-details' class='modal fade' tabindex='-1' role='dialog' aria-labelledby='myLargeModalLabel' aria-hidden='true'> " + " <div class='modal-dialog modal-lg'> " + " <div class='modal-content'> " + " <div class='modal-header'> " + " <h5 class='modal-title'>E1. MyTest</h5> " + " <button type='button' class='close' data-dismiss='modal' aria-label='Close'> <span aria-hidden='true'>×</span> </button> " + " </div> " + "" + " <div class='modal-body'>" + "" + " <div class='detailed-message'>" + " <div class='applies-to'>instance1</div>" + " Detailed issue variant 1" + " <ul>" + " <li>list item 1</li>" + " <li>list item 2</li>" + " </ul>" + " <div>" + " Get more information in <a href='http://localhost/'>this document</a>." + " </div>" + " </div>" + " <hr />" + " <div class='detailed-message'>" + " <div class='applies-to'>instance2</div>" + " Detailed issue variant 1" + " <ul>" + " <li>list item 1</li>" + " <li>list item 2</li>" + " </ul>" + " <div>" + " Get more information in <a href='http://localhost/'>this document</a>." + " </div>" + " </div>" + " <hr />" + " <div class='detailed-message'>" + " <div class='applies-to'>instance3</div>" + " Detailed issue variant 2" + " <ul>" + " <li>list item 3</li>" + " </ul>" + " <div>" + " Get more information in <a href='http://localhost/'>this document</a>." + " </div>" + " </div> " + "" + " </div> " + " </div> " + " </div> " + " </div> " + " </div>"), errors); }
private static IEnumerable <string> GetMessages(string alertType, string prefix, ResultsFile resultsFile, Func <ITestReport, IEnumerable <ITestResultData> > getMessages) { var counter = 1; foreach (var group in resultsFile.Solution.GroupBy(x => x.Owner.Name)) { var test = group.Key; // e.g. all error messages from this test var messages = group.SelectMany(getMessages); // data grouped by short messages, and every group has dictionary [ instance => detailed messages[] ] var data = messages .GroupBy(x => x.Message.ToString(OutputFormat.Html)) .ToArray(g => new { Message = g.Key, PerInstance = g .GroupBy(x => x.Instance) .ToDictionary(x => x.Key ?? "", x => x.ToArray()) }); if (!data.Any()) { continue; } var shortMessages = new List <string>(); var detailedMessages = new List <string>(); foreach (var messageGroup in data) { var shortMessage = messageGroup.Message; if (string.IsNullOrWhiteSpace(shortMessage.Replace(" ", " ").Replace("<br />", "").Replace("<br>", ""))) { continue; } shortMessages.Add(shortMessage); foreach (var instanceGroup in messageGroup.PerInstance) { var instanceName = instanceGroup.Key; var detailedMessage = ""; if (!string.IsNullOrEmpty(instanceName)) { detailedMessage += $"<div class='applies-to'>{instanceName}</div>"; } var detailedMessages1 = instanceGroup.Value .Select(x => RenderDetailedMessage(x, shortMessage)) .GroupBy(x => x) // to remove duplicates .ToArray(x => x.Key); detailedMessage += detailedMessages1.JoinToString(""); detailedMessages.Add(detailedMessage); } } var id = $"{prefix}{counter++}"; var header = $"<h4 class='alert-heading'>" + $" <a href='#{id}'>{id}</a>. <span class='test-name'>{test}</span>" + $"</h4>"; var briefView = $"<div class=\'short-message\'>{string.Join("</div><hr /><div class='short-message'>", shortMessages)}</div>"; if (detailedMessages.All(string.IsNullOrWhiteSpace)) { yield return(GetMessage(alertType, header + briefView)); continue; } if (AreSame(shortMessages, detailedMessages)) { yield return(GetMessage(alertType, header + briefView)); continue; } var detailedView = $"<div class=\'detailed-message\'>{string.Join("</div><hr /><div class='detailed-message'>", detailedMessages)}</div>"; var html = $"" + $"{header}" + $"{briefView}" + $"<a href='#' data-toggle='modal' data-target='#{id}-details'>See full details.</a>" + $" <div id='{id}-details' class='modal fade' tabindex='-1' role='dialog' aria-labelledby='myLargeModalLabel' aria-hidden='true'>" + $" <div class='modal-dialog modal-lg'>" + $" <div class='modal-content'>" + $" <div class='modal-header'>" + $" <h5 class='modal-title'>{id}. {test}</h5>" + $" <button type='button' class='close' data-dismiss='modal' aria-label='Close'> <span aria-hidden='true'>×</span> </button>" + $" </div>" + $" <div class='modal-body'>" + $" {detailedView}" + $" </div>" + $" </div>" + $" </div>" + $" </div>"; yield return(GetMessage(alertType, html)); } }
public GoalDifferencePlusCalculator(ResultsFile results, GoalDifferences unadjustedGoalDifferences) { _results = results; _unadjustedGoalDifferences = unadjustedGoalDifferences; }
private static string[] GetCannotRunMessages(ResultsFile resultsFile) { return(GetMessages("info", "C", resultsFile, r => r.Results.CannotRun).ToArray()); }
private static string[] GetDebugMessages(ResultsFile resultsFile) { return(GetMessages("info", "D", resultsFile, r => r.Results.DebugLogs.Select(GetDebugMessages)).ToArray()); }
private static string[] GetWarningMessages(ResultsFile resultsFile) { return(GetMessages("warning", "W", resultsFile, r => r.Results.Warnings).ToArray()); }
internal static string[] GetErrorMessages(ResultsFile resultsFile) { return(GetMessages("danger", "E", resultsFile, r => r.Results.Errors).ToArray()); }
private static FilesUploadReturn FilesUpload(List <ResultsFile> files, string keyPrefix, Dictionary <string, string> auth, string target) { const long expireBuffer = 30; // 30 seconds var expiration = Convert.ToInt64((string)auth["Expiration"]); const int maxActiveUploads = 10; // Upload at most 10 files simultaneously to avoid hogging the client machine. var transferUtility = CreateTransferUtility(auth); while (files.Count != 0 || uploading.Count != 0) { try { if (uploading.Count < maxActiveUploads && files.Count != 0) { // Check if new credentials required. long now = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000; if (now + expireBuffer > expiration) // Check within 30 seconds of expiry. { if (uploading.Count == 0) { // Wait for all current transfers to complete before creating new TransferUtility. RefreshCredentialsResponse response = RefreshCredentials(target, keyPrefix); if (response.Success != true) { // Must stop upload due to failure to get new credentials. warnings.Add(response.Message); break; } else { string key = (string)response.Upload["key"]; string uploadMessage = (string)response.Upload["message"]; bool permit = (bool)response.Upload["permit"]; auth = (Dictionary <string, string>)response.Upload["auth"]; if (permit != true) { // Must stop upload due to failure to be permitted for new credentials. warnings.Add(uploadMessage); break; } // upload permitted expiration = Convert.ToInt64((string)auth["Expiration"]); transferUtility = CreateTransferUtility(auth); } } } if (now + expireBuffer < expiration) { // Check within 30 seconds of expiry. // Load new file for upload. if (files.Count > 0) { ResultsFile resultsFile = files[0]; files.RemoveAt(0); if (!File.Exists(resultsFile.File)) { warnings.Add("File not found: " + Path.GetFileName(resultsFile.File)); } else { String key = keyPrefix + "/" + resultsFile.Num + "/" + Path.GetFileName(resultsFile.File); var transfer = new TransferUtilityUploadRequest() { BucketName = "tesults-results", Key = key, FilePath = resultsFile.File }; transfer.UploadProgressEvent += TransferUploadProgressEvent; uploading.Add(resultsFile.File); try { transferUtility.Upload(transfer); } catch (Exception ex) { uploading.Remove(resultsFile.File); warnings.Add("Failed to upload file."); } } } } } } catch (Exception ex) { warnings.Add("Error occurred while uploading files."); break; } } return(new FilesUploadReturn() { Message = "Success. " + filesUploaded + " files uploaded. " + bytesUploaded + " bytes uploaded.", Warnings = warnings }); }