コード例 #1
0
        private void RemoveNotes_EventsCollection_WithPredicate(
            ContainerType containerType,
            ICollection <MidiEvent> midiEvents,
            Predicate <Note> match,
            ICollection <MidiEvent> expectedMidiEvents,
            int expectedRemovedCount)
        {
            var eventsCollection = new EventsCollection();

            eventsCollection.AddRange(midiEvents);

            switch (containerType)
            {
            case ContainerType.EventsCollection:
            {
                Assert.AreEqual(
                    expectedRemovedCount,
                    eventsCollection.RemoveNotes(match),
                    "Invalid count of removed notes.");

                var expectedEventsCollection = new EventsCollection();
                expectedEventsCollection.AddRange(expectedMidiEvents);
                MidiAsserts.AreEqual(expectedEventsCollection, eventsCollection, true, "Events are invalid.");
                Assert.IsTrue(
                    eventsCollection.All(e => midiEvents.Any(ee => object.ReferenceEquals(e, ee))),
                    "There are new events references.");
            }
            break;

            case ContainerType.TrackChunk:
            {
                var trackChunk = new TrackChunk(eventsCollection);

                Assert.AreEqual(
                    expectedRemovedCount,
                    trackChunk.RemoveNotes(match),
                    "Invalid count of removed notes.");

                var expectedTrackChunk = new TrackChunk(expectedMidiEvents);
                MidiAsserts.AreEqual(expectedTrackChunk, trackChunk, true, "Events are invalid.");
                Assert.IsTrue(
                    trackChunk.Events.All(e => midiEvents.Any(ee => object.ReferenceEquals(e, ee))),
                    "There are new events references.");
            }
            break;

            case ContainerType.TrackChunks:
            case ContainerType.File:
            {
                RemoveNotes_TrackChunks_WithPredicate(
                    containerType == ContainerType.File,
                    new[] { midiEvents },
                    match,
                    new[] { expectedMidiEvents },
                    expectedRemovedCount);
            }
            break;
            }
        }