public void Verify(Group msgs) { var list = new List <string>(); int count = 0; foreach (var exp in msgs.Messages) { count++; var expected = exp.Message; { var type = expected.GetType(); var s = JsonSerializer.SerializeToString(expected, type); var actual = JsonSerializer.DeserializeFromString(s, type); var compare = CompareObjects.FindDifferences(expected, actual); if (!string.IsNullOrEmpty(compare)) { list.Add("JsonSerializer " + exp.Origin + Environment.NewLine + compare); } } { var actual = Serializer.DeepClone(expected); var compare = CompareObjects.FindDifferences(expected, actual); if (!string.IsNullOrWhiteSpace(compare)) { list.Add("ProtoBuf " + exp.Origin + Environment.NewLine + compare); } } } if (list.Count > 0) { Assert.Fail("{0} out of {1}\r\n{2}", list.Count, count, string.Join(Environment.NewLine, list)); } }
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" : ex.ToString(); var actualString = ac == null ? "No event actually" : ac.ToString(); 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) { // there is a difference in textual representations yield return(new ExpectationResult { Passed = false, Text = expectedHumanReadable, Exception = new InvalidOperationException("Was: " + actualHumanReadable) }); } 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("Missing") }); } } for (int i = _expected.Count; i < actual.Count(); i++) { yield return(new ExpectationResult() { Passed = false, Text = "Unexpected message", Exception = new InvalidOperationException("Was: " + Describe.Object(actual[i])) }); } }