private void WritePreamble() { if (IsReadOnly) { throw SpecFailure.Sealed(); } }
public void ValidateActual(object actual) { if (actual is null && !_allowNull) { throw SpecFailure.CannotAssertTypeOnNullActual(); } }
protected void ThrowIfDisposed() { if (IsDisposed) { throw SpecFailure.Disposed(GetType().ToString()); } }
private void ThrowIfSealed() { if (IsReadOnly) { throw SpecFailure.Sealed(); } }
static IEnumerable <TKey> Keys(IEnumerable actual) { var ng = actual as IDictionary; if (ng != null) { return(ng.Keys.Cast <TKey>()); } // Look for IDictionary<>, IReadOnlyDictionary<> using reflection var interfaces = actual.GetType().GetTypeInfo().GetInterfaces() .Where(t => t.GetTypeInfo().IsGenericType); { var iface = interfaces.FirstOrDefault(IsGenericDictionary); if (iface != null) { return(((IEnumerable)iface.GetTypeInfo().GetProperty("Keys").GetValue(actual)).Cast <TKey>()); } } // Look for IEnumerable<IGrouping<TKey, TValue>> and // IEnumerable<KeyValuePair<TKey, TValue>> foreach (var iface in interfaces) { PropertyInfo kp; if (IsKVP(iface, out kp)) { var enumMethod = iface.GetTypeInfo().GetMethod("GetEnumerator"); return(LateBoundKVP(actual, enumMethod, kp)); } } throw SpecFailure.CannotTreatAsDictionaryOrGroupings(actual.GetType()); }
protected void ThrowIfReadOnly() { if (IsReadOnly) { throw SpecFailure.ReadOnlyCollection(); } }
private static Exception _TryParse(string text, out TestPlanFilterPattern result) { if (text == null) { result = null; return(new ArgumentNullException()); } text = text.Trim(); if (text.Length == 0) { result = null; return(SpecFailure.AllWhitespace(nameof(text))); } string[] nv = Array.ConvertAll( text.Split(new [] { ':' }, 3), t => t.Trim() ); if (nv.Length == 2 && nv[0] == "regex") { return(_TryParseRegex(nv[1], out result)); } else { result = TestPlanFilterPattern.Wildcard(text); return(null); } }
public override bool Matches(object actual) { if (actual is ValueType) { throw SpecFailure.CannotUseNullOnValueType(actual.GetType()); } return(actual == null); }
protected override object CoreRunTest(TestExecutionContext context) { try { return(InvokeMethodHelper(context.TestObject, null)); } catch (TargetParameterCountException) { throw SpecFailure.FactMethodParamCount(TypeName + "." + MethodName); } }
public void AddSelfTests() { SpecLog.ActivatedSelfTestMode(); if (!TestClass.HasSelfTests) { throw SpecFailure.NoSelfTestsAvailable(); } AddAssembly(typeof(TestMatcher).GetTypeInfo().Assembly); }
protected override object CoreRunTest(TestExecutionContext context) { try { var args = TestMethodArguments.Select(a => RebindDelegates(context.TestObject, a)).ToArray(); return(InvokeMethodHelper(context.TestObject, args)); } catch (TargetParameterCountException) { throw SpecFailure.WrongNumberOfTheoryArguments(TypeName, MethodName, _index); } }
private void CompleteResult() { if (_opts.PassExplicitly) { _result.SetFailed(SpecFailure.ExplicitPassNotSet()); } else { _result.SetSuccess(); } }
public override bool Matches(IEnumerable actual) { if (actual == null) { return(false); } if (actual is Array) { return(((Array)actual).Length == Expected); } if (actual is string) { return(((string)actual).Length == Expected); } throw SpecFailure.HaveLengthWorksWith(actual.GetType()); }
static TestUnit CreateCore(MethodInfo method, IEnumerable <Attribute> attrs) { TestUnit testCase = null; foreach (var attr in attrs.OfType <IReflectionTestUnitFactory>()) { if (testCase == null) { testCase = attr.CreateTestCase(method); } else { throw SpecFailure.MultipleTestUnitFactories(); } } return(testCase); }
private bool DemandRetargetDelegates() { switch (RetargetDelegates) { case RetargetDelegates.Enabled: return(true); case RetargetDelegates.Disabled: return(false); case RetargetDelegates.Unspecified: default: if (Assert.UseStrictMode) { throw SpecFailure.PossibleDelegateRetargeting(); } return(true); } }
internal Assembly LoadAssembly(string asmPath) { string fullPath = Path.GetFullPath(asmPath); if (!File.Exists(fullPath)) { throw SpecFailure.FailedToLoadAssemblyPath(asmPath); } try { SpecLog.LoadAssembly(fullPath); return(LoadAssemblyFromPath(fullPath)); } catch (BadImageFormatException) { throw SpecFailure.FailedToLoadAssembly(asmPath); } catch (FileNotFoundException ex) { throw SpecFailure.FailedToLoadAssemblyPath(asmPath + " -> " + ex.FileName); } catch (IOException ex) { throw SpecFailure.FailedToLoadAssemblyGeneralIO(asmPath, ex.Message); } }
private static Exception _TryParse(string text, out TestId result) { result = default(TestId); if (text == null) { return(new ArgumentNullException(nameof(text))); } text = text.Trim(); if ((text.Length % 2) == 0) { var bytes = new byte[text.Length / 2]; int j = 0; for (int i = 0; i < text.Length; i += 2) { bytes[j++] = Convert.ToByte(text.Substring(i, 2), 16); } result = new TestId(bytes); return(null); } return(SpecFailure.NotParsable(nameof(text), typeof(TestId))); }
public void RunTest(TestExecutionContext context, Action <TestExecutionContext> next) { throw SpecFailure.CouldNotLoadType(_type, _ex); }