public void Document(RunResult result) { var env = Before.Select(PAssert.PAssert.CreateSimpleFormatFor).Concat(Docs.Select(e => e().ToString())); PrintEvil.Document(result, env.ToList(), Given.ToArray(), When, _text.ToString()); }
RunResult Run <T>(TypedSpecification <T> spec) { var result = new RunResult { SpecificationName = spec.GetName() }; try { var before = spec.GetBefore(); before.InvokeIfNotNull(); } catch (Exception ex) { result.MarkFailure("Before Failed", ex.InnerException); return(result); } object sut = null; try { var given = spec.GetOn(); sut = given.DynamicInvoke(); result.On = given; } catch (Exception ex) { result.MarkFailure("On Failed", ex.InnerException); return(result); } object whenResult = null; Delegate when; try { when = spec.GetWhen(); if (when == null) { return new RunResult { SpecificationName = spec.GetName(), Passed = false, Message = "No when on specification" } } ; if (when.Method.GetParameters().Length == 1) { whenResult = when.DynamicInvoke(new[] { sut }); } else { whenResult = when.DynamicInvoke(); } if (when.Method.ReturnType != typeof(void)) { result.Result = whenResult; } else { result.Result = sut; } } catch (Exception ex) { result.MarkFailure("When Failed", ex.InnerException); return(result); } var fromWhen = when.Method.ReturnType == typeof(void) ? sut : whenResult; var allOk = true; foreach (var assertion in spec.GetAssertions()) { foreach (var expectationResult in assertion.Assert(fromWhen)) { result.Expectations.Add(expectationResult); if (!expectationResult.Passed) { allOk = false; } } } try { var Finally = spec.GetFinally(); Finally.InvokeIfNotNull(); } catch (Exception ex) { allOk = false; result.Message = "Finally failed"; result.Thrown = ex.InnerException; } result.Passed = allOk; return(result); }
public static void Document <T>( RunResult result, List <string> before, IEvent <T>[] given, ICommand <T> when, string decisions) where T : IIdentity { var passed = result.Passed ? "[Passed]" : "[Failed]"; var cleanupName = result.FoundOnMemberInfo.DeclaringType.Name.CleanupName(); Console.WriteLine("{2} Use case '{0} - {1}'.", cleanupName, result.Name.CleanupName(), passed); var cleared = before .Select(b => (b ?? "").TrimEnd()) .Where(s => !string.IsNullOrEmpty(s)) .ToList(); if (cleared.Any()) { Console.WriteLine(); Console.WriteLine("Environment: "); foreach (var e in cleared) { PrintAdjusted(" ", e); } } if (given.Any()) { Console.WriteLine(); Console.WriteLine("Given:"); for (int i = 0; i < given.Length; i++) { PrintAdjusted(" " + (i + 1) + ". ", Describe.Object(given[i]).Trim()); } } if (when != null) { Console.WriteLine(); Console.WriteLine("When:"); PrintAdjusted(" ", Describe.Object(when).Trim()); } Console.WriteLine(); Console.WriteLine("Expectations:"); foreach (var expecation in result.Expectations) { var s = expecation.Passed ? "[ok]" : "[NO]"; PrintAdjusted(" " + s + " ", expecation.Text.Trim()); if (!expecation.Passed && expecation.Exception != null) { PrintAdjusted(" ", expecation.Exception.Message); } } if (result.Thrown != null) { Console.WriteLine("Specification failed: " + result.Message.Trim()); Console.WriteLine(); Console.WriteLine(result.Thrown); } if (decisions.Length > 0) { Console.WriteLine(""); Console.WriteLine("Decisions made:"); PrintAdjusted(" ", decisions); } Console.WriteLine(new string('-', 80)); Console.WriteLine(); }
public void Document(RunResult result) { Console.WriteLine("Do something"); }