private void ValidateTests(EdisonContext context) { var tests = context.Tests; if (tests == default(IList<string>) || !tests.Any()) { return; } tests = tests.Distinct().ToList(); var files = context.Tests.Where(x => x.Contains('\\') || x.Contains('/')).ToList(); tests = tests.Where(x => !x.Contains('\\') && !x.Contains('/')).ToList(); var _file = string.Empty; foreach (var file in files) { _file = file.Trim(); if (!FileRepository.Exists(_file)) { throw new ValidationException("File for list of tests not found: '{0}'", _file); } tests.AddRange(FileRepository.ReadAllLines(_file, Encoding.UTF8)); } context.Tests = tests.Distinct().ToList(); }
public void Validate(EdisonContext context) { // need to validate a solution first, for its assemblies SolutionValidator(context); // assemblies are mandatory, if there are none and no solution is passed then validation fails var assemblies = context.Assemblies; if (assemblies == default(IList<string>) || !assemblies.Any()) { if (string.IsNullOrWhiteSpace(context.Solution)) { throw new ValidationException("No assembly or solution paths were supplied."); } return; } assemblies = assemblies.Distinct().ToList(); var files = assemblies.Where(x => string.IsNullOrWhiteSpace(PathRepository.GetExtension(x.Trim()))).ToList(); assemblies = assemblies.Where(x => !string.IsNullOrWhiteSpace(PathRepository.GetExtension(x.Trim()))).ToList(); var _file = string.Empty; foreach (var file in files) { _file = file.Trim(); if (!FileRepository.Exists(_file)) { throw new ValidationException("File for list of assemblies not found: '{0}'", _file); } assemblies.AddRange(FileRepository.ReadAllLines(_file, Encoding.UTF8)); } assemblies = assemblies.Distinct().ToList(); for (var i = 0; i < assemblies.Count; i++) { if (string.IsNullOrWhiteSpace(assemblies[i])) { throw new ValidationException("Assembly cannot be null or empty"); } assemblies[i] = assemblies[i].Trim(); if (!PathRepository.GetExtension(assemblies[i]).Equals(DllExtension, StringComparison.InvariantCultureIgnoreCase)) { throw new ValidationException("Assembly is not a valid {0} file: '{1}'", DllExtension, assemblies[i]); } if (!FileRepository.Exists(assemblies[i])) { throw new ValidationException("Assembly not found: '{0}'", assemblies[i]); } } context.Assemblies = assemblies; }
/// <summary> /// Validates the specified context. Where properties don't match what the validator expects, then a /// ValidationException will be thrown. If a property is empty and not required, then the validator /// will default the value. /// </summary> /// <param name="context">The context.</param> public static void Validate(EdisonContext context) { Validate(context, new AssemblyValidator(), new RerunThresholdValidator(), new OutputValidator(), new ThreadValidator(), new TestResultUrlValidator(), new NamespaceValidator()); }
public TestFixtureThread(int threadId, EdisonContext context, TestResultDictionary resultQueue, IEnumerable<Type> fixtures, Exception globalSetupEx, ConcurrencyType concurrenyType, int numberOfTestThreads) { ThreadId = threadId; Context = context; ResultQueue = resultQueue; GlobalSetupException = globalSetupEx; TestFixtures = fixtures; NumberOfTestThreads = numberOfTestThreads; }
public void Validate(EdisonContext context) { if (context.NumberOfFixtureThreads <= 0) { throw new ValidationException("Number of fixture threads supplied must be greater than 0, but got '{0}'", context.NumberOfFixtureThreads); } if (context.NumberOfTestThreads <= 0) { throw new ValidationException("Number of test threads supplied must be greater than 0, but got '{0}'", context.NumberOfTestThreads); } }
public void Validate(EdisonContext context) { if (context.RerunThreshold < 0) { throw new ValidationException("Value must be greater than or equal to 0 for re-run threshold, but got '{0}'", context.RerunThreshold); } if (context.RerunThreshold > 100) { throw new ValidationException("Value must be less than or equal to 100 for re-run threshold, but got '{0}'", context.RerunThreshold); } }
public TestThread(int threadId, TestResultDictionary resultQueue, IEnumerable<MethodInfo> tests, Type testFixture, int testFixtureRepeatIndex, TestCaseAttribute testFixtureCase, object activator, Exception globalSetupEx, Exception fixtureSetupEx, Exception activatorEx, EdisonContext context, ConcurrencyType concurrenyType) { ThreadId = threadId; Context = context; ResultQueue = resultQueue; TestFixture = testFixture; TestFixtureRepeatIndex = testFixtureRepeatIndex; Activator = activator; TestFixtureCase = testFixtureCase; GlobalSetupException = globalSetupEx; FixtureSetupException = fixtureSetupEx; ActivatorException = activatorEx; Tests = tests; }
public void Validate(EdisonContext context) { if (string.IsNullOrWhiteSpace(context.OutputFile)) { context.OutputFile = OutputFileName; } if (string.IsNullOrWhiteSpace(context.OutputDirectory)) { context.OutputDirectory = Environment.CurrentDirectory; } if (!DirectoryRepository.Exists(context.OutputDirectory)) { throw new ValidationException("Output folder supplied does not exist: '{0}'", context.OutputDirectory); } }
public void Validate(EdisonContext context) { if (string.IsNullOrWhiteSpace(context.TestResultURL)) { return; } try { var request = WebRequestRepository.Create(context.TestResultURL); request.Timeout = 30; using (var response = request.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream())) { } } } catch (Exception ex) { throw new ValidationException("Connection to provided TestRunURL ('{0}') failed:{1}{2}", context.TestResultURL, Environment.NewLine, ex.Message); } }
private void SetupContext(List<string> tests, List<string> fixtures) { EdisonContext = EdisonContext.Create(); EdisonContext.Assemblies.Add(FilePath); EdisonContext.NumberOfFixtureThreads = (int)FixtureThreadNumericBox.Value; EdisonContext.NumberOfTestThreads = (int)TestThreadNumericBox.Value; EdisonContext.DisableConsoleOutput = DisableConsoleCheckBox.Checked; EdisonContext.DisableTestOutput = DisableTestCheckBox.Checked; EdisonContext.IncludedCategories.AddRange(IncludedCategoriesCheckList.CheckedItems.Cast<string>()); EdisonContext.ExcludedCategories.AddRange(ExcludedCategoriesCheckList.CheckedItems.Cast<string>()); EdisonContext.Suite = SuiteCheckList.CheckedItems.Cast<string>().FirstOrDefault(); if (tests != default(List<string>)) { EdisonContext.Tests.AddRange(tests); } if (fixtures != default(List<string>)) { EdisonContext.Fixtures.AddRange(fixtures); } EdisonContext.DisableFileOutput = true; EdisonContext.ConsoleOutputType = OutputType.Txt; EdisonContext.OnTestResult += EdisonContext_OnTestResult; }
private void Run(EdisonContext context) { try { context.Run(); } catch (ValidationException vex) { MessageBox.Show(vex.Message, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(string.Format("{0}{2}{2}{1}", ex.Message, ex.StackTrace, Environment.NewLine), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetRunTestButton("Run"); SetProgress(100); }
public TestResultDictionary(EdisonContext context) { Results = new ConcurrentDictionary<string,TestResult>(); Context = context; }
/// <summary> /// Validates the specified context using the specified validators. Where properties don't match what /// the validator expects, then a ValidationException will be thrown. If a property is empty and not /// required, then the validator will default the value. /// </summary> /// <param name="context">The context.</param> /// <param name="validators">The validators.</param> public static void Validate(EdisonContext context, params IValidator[] validators) { validators.ToList().ForEach(x => x.Validate(context)); }
public static bool Parse(EdisonContext context, string[] args) { if (context == default(EdisonContext)) { throw new Exception("No EdisonContext supplied for parsing parameters"); } // Check to see if any arguments were passed, or that an Edisonfile exists var options = new ConsoleOptions(); var anyArgs = (args != default(string[]) && args.Length > 0); if (!anyArgs && !File.Exists(ConsoleOptions.EDISONFILE)) { Logger.Instance.WriteMessage(options.GetUsage()); return false; } // Attempt to parse then into a the options if (!Parser.Default.ParseArguments(args, options)) { Logger.Instance.WriteMessage(options.GetUsage()); return false; } // If there were no arguments passed, or the option's Edisonfile is set, serialize the options if (!anyArgs || !string.IsNullOrWhiteSpace(options.Edisonfile)) { var file = string.IsNullOrWhiteSpace(options.Edisonfile) ? ConsoleOptions.EDISONFILE : options.Edisonfile; if (!File.Exists(file)) { throw new ArgumentException(string.Format("Edisonfile does not exist: {0}", file)); } var yaml = new Deserializer(namingConvention: new UnderscoredNamingConvention()); using (var reader = new StreamReader(file)) { options.InjectYaml(yaml.Deserialize<Dictionary<object, object>>(reader)); } } // Show the help usage text if required if (options.ShowHelp) { Logger.Instance.WriteMessage(options.GetUsage()); return false; } // Show the version of Edison if required if (options.ShowVersion) { Logger.Instance.WriteMessage(options.GetVersion()); return false; } context.Assemblies = new List<string>(EnumerableHelper.SafeGuard(options.Assemblies)); context.IncludedCategories = new List<string>(EnumerableHelper.SafeGuard(options.IncludedCategories)); context.ExcludedCategories = new List<string>(EnumerableHelper.SafeGuard(options.ExcludedCategories)); context.Tests = new List<string>(EnumerableHelper.SafeGuard(options.Tests)); context.Fixtures = new List<string>(EnumerableHelper.SafeGuard(options.Fixtures)); context.Solution = options.Solution; context.SolutionConfiguration = options.SolutionConfiguration; context.Suite = options.Suite; context.RerunFailedTests = options.RerunFailedTests; context.DisableFileOutput = options.DisableFileOutput; context.DisableConsoleOutput = options.DisableConsoleOutput; context.DisableTestOutput = options.DisableTestOutput; context.ConsoleOutputType = options.ConsoleOutputType; context.OutputType = options.OutputType; context.TestRunId = options.TestRunId; context.RerunThreshold = options.RerunThreshold; context.OutputFile = options.OutputFile; context.OutputDirectory = options.OutputDirectory; context.NumberOfFixtureThreads = options.FixtureThreads; context.NumberOfTestThreads = options.TestThreads; context.TestResultURL = options.TestResultUrl; return true; }
private void SolutionValidator(EdisonContext context) { // solution is optional, so if not passed skip validation if (string.IsNullOrWhiteSpace(context.Solution)) { return; } // validate solution configuration first if (string.IsNullOrWhiteSpace(context.SolutionConfiguration)) { context.SolutionConfiguration = SlnConfigDefault; } context.Solution = context.Solution.Trim(); if (!PathRepository.GetExtension(context.Solution).Equals(SlnExtension, StringComparison.InvariantCultureIgnoreCase)) { throw new ValidationException("Solution is not a valid {0} file: '{1}'", SlnExtension, context.Solution); } if (!FileRepository.Exists(context.Solution)) { throw new ValidationException("Solution file not found: '{0}'", context.Solution); } var contents = FileRepository.ReadAllText(context.Solution, Encoding.UTF8); var groups = Regex.Matches(contents, SlnRegex) .Cast<Match>() .Select(x => x.Groups) .ToList(); var solutionDir = PathRepository.GetDirectoryName(context.Solution); foreach (var group in groups) { var path = PathRepository.Combine(solutionDir, group["path"].Value, "bin", context.SolutionConfiguration, group["project"].Value + DllExtension); if (!FileRepository.Exists(path)) { throw new ValidationException("Assembly file from solution cannot be found: '{0}'", path); } context.Assemblies.Add(path); } }
public void Validate(EdisonContext context) { ValidateTests(context); ValidateFixtures(context); }