public void ReturnsIntervalsFromSubTransformers()
        {
            var sut = new SessionIdSortingTransformer <TestInterval>(
                () =>
            {
                var transformer = Mock.Of <IEventToIntervalTransformer <TestInterval> >();
                Mock.Get(transformer).Setup(t => t.SignalEndOfEventStream()).Returns(new[] { ExpectedInterval(0, 0) });
                return(transformer);
            });

            sut.ProcessEvent(TestIDEEvent(0, 0, "a"));
            sut.ProcessEvent(TestIDEEvent(0, 0, "a"));
            sut.ProcessEvent(TestIDEEvent(0, 0, "b"));

            Assert.AreEqual(2, sut.SignalEndOfEventStream().Count());
        }
        public void CreatesNewSubTransformerForNewId()
        {
            var count = 0;

            var sut = new SessionIdSortingTransformer <TestInterval>(
                () =>
            {
                count++;
                return(Mock.Of <IEventToIntervalTransformer <TestInterval> >());
            });

            sut.ProcessEvent(TestIDEEvent(0, 0, "a"));
            sut.ProcessEvent(TestIDEEvent(0, 0, "a"));
            sut.ProcessEvent(TestIDEEvent(0, 0, "b"));

            Assert.AreEqual(2, count);
        }
        public void PassesEventsToSubTransformer()
        {
            var events = new[]
            {
                TestIDEEvent(0, 0, "a"),
                TestIDEEvent(1, 1, "a"),
                TestIDEEvent(0, 0, "b")
            };

            var processingInstances = new Dictionary <string, IEventToIntervalTransformer <TestInterval> >();
            var processedEvents     = new List <IDEEvent>();

            var sut = new SessionIdSortingTransformer <TestInterval>(
                () =>
            {
                var transformer = Mock.Of <IEventToIntervalTransformer <TestInterval> >();
                Mock.Get(transformer).Setup(t => t.ProcessEvent(It.IsAny <IDEEvent>())).Callback <IDEEvent>(
                    e =>
                {
                    processedEvents.Add(e);

                    if (processingInstances.ContainsKey(e.IDESessionUUID))
                    {
                        if (processingInstances[e.IDESessionUUID] != transformer)
                        {
                            Assert.Fail();
                        }
                    }
                    else
                    {
                        processingInstances.Add(e.IDESessionUUID, transformer);
                    }
                });
                return(transformer);
            });

            foreach (var e in events)
            {
                sut.ProcessEvent(e);
            }

            CollectionAssert.AreEquivalent(events, processedEvents);
        }