private static string GetDependencyName(HealthTest ht) { if (!string.IsNullOrWhiteSpace(ht.TestIdentifier)) { return(ht.TestIdentifier); } return(ht.TestName); }
public string Index() { var result = string.Empty; try { var tests = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(HealthTest).IsAssignableFrom(p)) .Where(x => !x.IsInterface) .Where(x => !x.IsAbstract); var model = new IndexPageModel(); string loc = Assembly.GetAssembly(typeof(HealthTest)).Location; FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(loc); model.PageTitle = versionInfo.ProductName + " " + versionInfo.FileVersion; model.Footer = versionInfo.ProductName + " © " + DateTime.Now.Year; foreach (var item in tests) { var watch = Stopwatch.StartNew(); var displayTestResult = new DisplayTestResult(); HealthTest instance = null; // creating an instance of the test try { instance = Activator.CreateInstance(item) as HealthTest; displayTestResult.TestName = instance.TestName; } catch (Exception ex) { displayTestResult.Successful = false; displayTestResult.ErrorMessage = ex.Message; } // running the test try { var testResult = instance.Run(); displayTestResult.Successful = testResult.Successful; displayTestResult.ErrorMessage = testResult.ErrorMessage; } catch (Exception ex) { displayTestResult.Successful = false; displayTestResult.ErrorMessage = ex.Message; } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; displayTestResult.ExecutionTime = elapsedMs + " ms"; model.TestResults.Add(displayTestResult); } var template = ReadEmbeddedResource("HealthCheck.Mvc.Views.Health.Index.html"); var templateKey = Guid.NewGuid().ToString(); result = Engine.Razor.RunCompile(template, templateKey, null, model); } catch (Exception ex2) { result = "An error occurred: " + ex2.Message; } return(result); }