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()); }
public IEnumerable <ExpectationResult> Assert(object fromWhen) { var actual = ((IEvent <T>[])fromWhen); // structurally equal comparison for (int i = 0; i < _expected.Count; i++) { var expectedHumanReadable = Describe.Object(_expected[i]); if (actual.Length > i) { var diffs = CompareObjects.FindDifferences(_expected[i], actual[i]); if (string.IsNullOrEmpty(diffs)) { yield return(new ExpectationResult { Passed = true, Text = expectedHumanReadable }); } else { var actualHumanReadable = Describe.Object(actual[i]); if (actualHumanReadable != expectedHumanReadable) { var msg = PrintEvil.GetAdjusted("Was: ", actualHumanReadable); // there is a difference in textual representations yield return(new ExpectationResult { Passed = false, Text = expectedHumanReadable, Exception = new InvalidOperationException(msg) }); } else { yield return(new ExpectationResult { Passed = false, Text = expectedHumanReadable, Exception = new InvalidOperationException(diffs) }); } } } else { yield return(new ExpectationResult { Passed = false, Text = expectedHumanReadable, Exception = new InvalidOperationException(" Message is missing") }); } } for (int i = _expected.Count; i < actual.Count(); i++) { var msg = PrintEvil.GetAdjusted("Was: ", Describe.Object(actual[i])); yield return(new ExpectationResult { Passed = false, Text = "Unexpected message", Exception = new InvalidOperationException(msg) }); } }