static T ExceptionAs <T>(TypedValue exception) where T : class { var baseException = exception.GetValueAs <System.Exception>(); if (baseException is TargetInvocationException) { baseException = baseException.InnerException; } return(baseException as T); }
bool AreEqual(TypedValue actualValue, TypedValue expectedValue, Cell expectedCell) { if (expectedValue.Type == typeof(DateTime) && actualValue.Type == typeof(DateTime)) { return(expectedValue.ValueString == actualValue.ValueString); } if (expectedValue.IsNull) { return(actualValue.IsNull); } if (actualValue.IsNull) { return(false); } if (expectedValue.GetValueAs <Array>() != null && actualValue.GetValueAs <Array>() != null) { return(ArraysAreEqual(expectedValue.GetValueAs <Array>(), actualValue.GetValueAs <Array>())); } if (expectedValue.Type == typeof(string)) { if (expectedValue.ValueString == actualValue.ValueString) { return(true); } if (expectedCell != null) { var difference = new StringDifference(expectedValue.ValueString, actualValue.ValueString).ToString(); if (difference.Length > 0) { expectedCell.SetAttribute(CellAttribute.Difference, difference); } } return(false); } return(expectedValue.Value.Equals(actualValue.Value)); }
public Tree <string> Compose(TypedValue instance) { var result = new StringBuilder(); result.AppendFormat("<table class=\"hash_table\">{0}", Environment.NewLine); foreach (var keyValue in instance.GetValueAs <Dictionary <string, string> >()) { result.AppendFormat("\t<tr class=\"hash_row\">{2}\t\t<td class=\"hash_key\">{0}</td>{2}\t\t<td class=\"hash_value\">{1}</td>{2}\t</tr>{2}", keyValue.Key, keyValue.Value, Environment.NewLine); } result.Append("</table>"); return(new SlimLeaf(result.ToString())); }
public TypedValue Wrap(TypedValue result) { if (!result.HasValue) { return(result); } if (result.Type.IsPrimitive) { return(result); } if (result.Type == typeof(string)) { return(result); } var wrapInterpreter = result.GetValueAs <Interpreter>(); if (wrapInterpreter != null) { return(result); } if (typeof(IEnumerable <object>).IsAssignableFrom(result.Type)) { return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable <object>), result.Value)); } if (typeof(IDictionary).IsAssignableFrom(result.Type)) { return(MakeInterpreter("fitlibrary.SetFixture", typeof(IEnumerable), result.GetValue <IDictionary>().Values)); } if (typeof(DataTable).IsAssignableFrom(result.Type)) { return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(DataTable), result.Value)); } if (typeof(XmlDocument).IsAssignableFrom(result.Type)) { return(MakeInterpreter("fitlibrary.XmlFixture", typeof(XmlDocument), result.Value)); } if (typeof(IEnumerable).IsAssignableFrom(result.Type)) { return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable), result.Value)); } if (typeof(IEnumerator).IsAssignableFrom(result.Type)) { return(MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerator), result.Value)); } return(MakeInterpreter(ParseInterpreter.DefaultFlowInterpreter, typeof(object), result.Value)); }
private static bool TryResult <T>(TypedValue exception, Format <T> formatter, ref Tree <string> result) where T : class { var baseException = exception.GetValueAs <System.Exception>(); if (baseException is TargetInvocationException) { baseException = baseException.InnerException; } var candidateException = baseException as T; if (candidateException == null) { return(false); } result = MakeResult(string.Format("message:<<{0}>> {1}", formatter(candidateException), candidateException)); return(true); }
public TypedValue Wrap(TypedValue result) { if (!result.HasValue) return result; if (result.Type.IsPrimitive) return result; if (result.Type == typeof(string)) return result; var wrapInterpreter = result.GetValueAs<Interpreter>(); if (wrapInterpreter != null) return result; if (typeof (IEnumerable<object>).IsAssignableFrom(result.Type)) return MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable<object>), result.Value); if (typeof (IDictionary).IsAssignableFrom(result.Type)) return MakeInterpreter("fitlibrary.SetFixture", typeof(IEnumerable), result.GetValue<IDictionary>().Values); if (typeof (DataTable).IsAssignableFrom(result.Type)) return MakeInterpreter("fitlibrary.ArrayFixture", typeof(DataTable), result.Value); if (typeof (XmlDocument).IsAssignableFrom(result.Type)) return MakeInterpreter("fitlibrary.XmlFixture", typeof(XmlDocument), result.Value); if (typeof (IEnumerable).IsAssignableFrom(result.Type)) return MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerable), result.Value); if (typeof (IEnumerator).IsAssignableFrom(result.Type)) return MakeInterpreter("fitlibrary.ArrayFixture", typeof(IEnumerator), result.Value); return MakeInterpreter(ParseInterpreter.DefaultFlowInterpreter, typeof (object), result.Value); }
public TypedValue FindMember(TypedValue instance, MemberQuery query) { return(new TypedValue( instance.GetValueAs <MemberQueryable>().Find(query.Specification), typeof(RuntimeMember))); }
protected T Parse <T>(string cellContent, TypedValue instance) where T : class { TypedValue result = Parser.Parse(typeof(string), TypedValue.Void, new CellTreeLeaf(cellContent)); return(result.GetValueAs <T>()); }
public Tree <Cell> Compose(TypedValue instance) { return(instance.GetValueAs <StoryTestSource>().Parse(Processor)); }