public static bool IsEquivalentTo <TPayload>(this IStreamable <Empty, TPayload> input, StreamEvent <TPayload>[] comparison) { Invariant.IsNotNull(input, "input"); Invariant.IsNotNull(comparison, "comparison"); var events = input.ToStreamEventArray(); var orderedEvents = events.OrderBy(e => e.SyncTime).ThenBy(e => e.OtherTime).ThenBy(e => e.Payload).ToArray(); var orderedComparison = comparison.OrderBy(e => e.SyncTime).ThenBy(e => e.OtherTime).ThenBy(e => e.Payload).ToArray(); return(orderedEvents.SequenceEqual(orderedComparison)); }
public static bool IsOrderSensitiveEquivalentTo <TPayload>(this IStreamable <Empty, TPayload> input, StreamEvent <TPayload>[] comparison) { Invariant.IsNotNull(input, "input"); Invariant.IsNotNull(comparison, "comparison"); var events = input.ToStreamEventArray(); // Reodrer stream events with the same timstamp var orderedEvents = (StreamEvent <TPayload>[])events.Clone(); int start = 0; while (start < events.Length) { int end = start + 1; while (end < events.Length && events[end].SyncTime == events[start].SyncTime && !events[start].IsPunctuation && !events[end].IsPunctuation) { end++; } var segment = new ArraySegment <StreamEvent <TPayload> >(events, start, end - start); segment.OrderBy(e => e.OtherTime).ThenBy(e => e.Payload).ToArray().CopyTo(orderedEvents, start); start = end; } // Reodrer stream events with the same timstamp var orderedComparison = (StreamEvent <TPayload>[])comparison.Clone(); start = 0; while (start < comparison.Length) { int end = start + 1; while (end < comparison.Length && comparison[end].SyncTime == comparison[start].SyncTime && !comparison[start].IsPunctuation && !comparison[end].IsPunctuation) { end++; } var segment = new ArraySegment <StreamEvent <TPayload> >(comparison, start, end - start); segment.OrderBy(e => e.OtherTime).ThenBy(e => e.Payload).ToArray().CopyTo(orderedComparison, start); start = end; } return(orderedEvents.SequenceEqual(orderedComparison)); }