public static void CompareSentReceivedEvents( IReadOnlyList <EventToSend> eventsToSend, IReadOnlyList <SentEvent> sentEvents, IReadOnlyList <ReceivedEvent> receivedEvents, TimeSpan maximumEventSendReceiveDelay) { for (var i = 0; i < sentEvents.Count; i++) { var eventToSend = eventsToSend[i]; var sentEvent = sentEvents[i]; var receivedEvent = receivedEvents[i]; Assert.IsTrue( MidiEventEquality.AreEqual(sentEvent.Event, eventToSend.Event, false), $"Sent event ({sentEvent.Event}) doesn't match the one that should be sent ({eventToSend.Event})."); Assert.IsTrue( MidiEventEquality.AreEqual(sentEvent.Event, receivedEvent.Event, false), $"Received event ({receivedEvent.Event}) doesn't match the sent one ({sentEvent.Event})."); var delay = (receivedEvent.Time - sentEvent.Time).Duration(); Assert.LessOrEqual( delay, maximumEventSendReceiveDelay, $"Event was received too late (at {receivedEvent.Time} instead of {sentEvent.Time}). Delay is too big."); } }
private void CompareSentReceivedEvents( IReadOnlyList <SentEvent> sentEvents, IReadOnlyList <ReceivedEvent> receivedEvents, IReadOnlyList <EventToSend> expectedEvents) { var currentTime = TimeSpan.Zero; for (var i = 0; i < sentEvents.Count; i++) { var sentEvent = sentEvents[i]; var receivedEvent = receivedEvents[i]; var expectedEvent = expectedEvents[i]; var expectedTime = (currentTime += expectedEvent.Delay); Assert.IsTrue( MidiEventEquality.AreEqual(sentEvent.Event, expectedEvent.Event, false), $"Sent event {sentEvent.Event} doesn't match expected one {expectedEvent.Event}."); Assert.IsTrue( MidiEventEquality.AreEqual(sentEvent.Event, receivedEvent.Event, false), $"Received event {receivedEvent.Event} doesn't match sent one {sentEvent.Event}."); var offsetFromExpectedTime = (sentEvent.Time - expectedTime).Duration(); Assert.LessOrEqual( offsetFromExpectedTime, SendReceiveUtilities.MaximumEventSendReceiveDelay, $"Event was sent at wrong time (at {sentEvent.Time} instead of {expectedTime})."); } }
private static void CheckProgramEvents(IReadOnlyList <SentEvent> sentEvents, IReadOnlyList <MidiEvent> expectedProgramEvents) { foreach (var programEvent in expectedProgramEvents) { var sentEvent = sentEvents.FirstOrDefault(e => MidiEventEquality.AreEqual(e.Event, programEvent, false)); Assert.IsNotNull(sentEvent, $"Program event {programEvent} was not sent."); Assert.LessOrEqual( sentEvent.Time, SendReceiveUtilities.MaximumEventSendReceiveDelay, $"Program event was sent at wrong time (at {sentEvent.Time} instead of zero)."); } }
private void CompareReceivedEvents( IReadOnlyList <ReceivedEvent> receivedEvents, IReadOnlyList <ReceivedEvent> expectedReceivedEvents) { Assert.AreEqual(expectedReceivedEvents.Count, receivedEvents.Count, "Received events count is invalid."); for (var i = 0; i < receivedEvents.Count; i++) { var receivedEvent = receivedEvents[i]; var expectedReceivedEvent = expectedReceivedEvents[i]; Assert.IsTrue( MidiEventEquality.AreEqual(expectedReceivedEvent.Event, receivedEvent.Event, false), $"Received event {receivedEvent.Event} doesn't match expected one {expectedReceivedEvent.Event}."); var expectedTime = expectedReceivedEvent.Time; var offsetFromExpectedTime = (receivedEvent.Time - expectedTime).Duration(); Assert.LessOrEqual( offsetFromExpectedTime, SendReceiveUtilities.MaximumEventSendReceiveDelay, $"Event was received at wrong time (at {receivedEvent.Time} instead of {expectedTime})."); } }