public Expected(string projectName, string file, string baseDirectory) { ProjectName = projectName; BaseDirectory = baseDirectory; Logger = new TestKarmaLogger(message => Console.WriteLine(message)); try { Directory = Path.GetDirectoryName(file); var expected = Json.ParseFile(file); KarmaConfig = (string)expected["KarmaConfig"]; Name = (string)expected["Name"]; if (string.IsNullOrWhiteSpace(KarmaConfig)) { throw new ArgumentNullException("KarmaConfig", "KarmaConfig is null or empty"); } KarmaConfig = Path.Combine(Directory, KarmaConfig); if (!File.Exists(KarmaConfig)) { throw new FileNotFoundException("KarmaConfig file not found", KarmaConfig); } if (expected["Specs"] != null) { if (!(expected["Specs"] is JArray)) { throw new ArgumentException("Specs is not an array", "Specs"); } Specs = expected["Specs"].OfType<JObject>().Select(s => new ExpectedSpec(s, Directory)).ToList(); } else { Specs = Enumerable.Empty<ExpectedSpec>(); } Globals.IsTest = true; } catch (AggregateException ex) { var innerException = ex.InnerExceptions.FirstOrDefault(); if (innerException != null) { _validator.Validate(false, string.Format("{0}\n{1}", innerException.Message, innerException.StackTrace)); Logger.Error(innerException); } else { _validator.Validate(false, string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); Logger.Error(ex); } } catch (Exception ex) { _validator.Validate(false, string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); Logger.Error(ex); } }
public Expected(string projectName, string file, string baseDirectory) { ProjectName = projectName; BaseDirectory = baseDirectory; Logger = new TestKarmaLogger(message => Console.WriteLine(message)); try { Directory = Path.GetDirectoryName(file); var expected = Json.ParseFile(file); KarmaConfig = (string)expected["KarmaConfig"]; Name = (string)expected["Name"]; if (string.IsNullOrWhiteSpace(KarmaConfig)) { throw new ArgumentNullException("KarmaConfig", "KarmaConfig is null or empty"); } KarmaConfig = Path.Combine(Directory, KarmaConfig); if (!File.Exists(KarmaConfig)) { throw new FileNotFoundException("KarmaConfig file not found", KarmaConfig); } if (expected["Specs"] != null) { if (!(expected["Specs"] is JArray)) { throw new ArgumentException("Specs is not an array", "Specs"); } Specs = expected["Specs"].OfType <JObject>().Select(s => new ExpectedSpec(s, Directory)).ToList(); } else { Specs = Enumerable.Empty <ExpectedSpec>(); } Globals.IsTest = true; } catch (AggregateException ex) { var innerException = ex.InnerExceptions.FirstOrDefault(); if (innerException != null) { _validator.Validate(false, string.Format("{0}\n{1}", innerException.Message, innerException.StackTrace)); Logger.Error(innerException); } else { _validator.Validate(false, string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); Logger.Error(ex); } } catch (Exception ex) { _validator.Validate(false, string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); Logger.Error(ex); } }