protected static IEnumerable <ExpectResult> CompareAssert( IEvent <T>[] expected, IEvent <T>[] actual) { var max = Math.Max(expected.Length, actual.Length); for (int i = 0; i < max; i++) { var ex = expected.Skip(i).FirstOrDefault(); var ac = actual.Skip(i).FirstOrDefault(); var expectedString = ex == null ? "No event expected" : Describe.Object(ex); var actualString = ac == null ? "No event actually" : Describe.Object(ac); var result = new ExpectResult { Expectation = expectedString }; var realDiff = CompareObjects.FindDifferences(ex, ac); if (!string.IsNullOrEmpty(realDiff)) { var stringRepresentationsDiffer = expectedString != actualString; result.Failure = stringRepresentationsDiffer ? GetAdjusted("Was: ", actualString) : GetAdjusted("Diff: ", realDiff); } yield return(result); } }
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) }); } }