public void CompleteTrackingOfInboundMessageWithoutProcessAffiliationAfterStreamLastReadEvent()
        {
            using (var stream = new TrackingStream(new StringStream("some-content")))
            {
                MessageMock.Object.BodyPart.Data = stream;

                var sut = ActivityTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Step));
                sut.TrackActivity();
                MessageMock.Object.BodyPart.Data.Drain();

                ProcessMock.Verify(
                    p => p.TrackActivity(),
                    Times.Never());
                InitiatingMessagingStepMock.Verify(
                    ms => ms.TrackActivity(It.IsAny <ActivityTrackingModes>(), It.IsAny <TrackingStream>()),
                    Times.Never());
                ProcessMock.Verify(
                    p => p.AddStep(InitiatingMessagingStepMock.Object),
                    Times.Never());
                MessagingStepMock.Verify(
                    ms => ms.TrackActivity(It.IsAny <ActivityTrackingModes>(), It.IsAny <TrackingStream>()),
                    Times.Once());
                ProcessMock.Verify(
                    p => p.AddStep(MessagingStepMock.Object),
                    Times.Never());
            }
        }
        public void FindProcessAndCreateMessagingStepBeforeStreamFirstReadEvent()
        {
            var trackingContext = new TrackingContext {
                ProcessActivityId = ActivityId.NewActivityId(),
            };

            using (var stream = new TrackingStream(new StringStream("some-content")))
            {
                MessageMock.Object.BodyPart.Data = stream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
                MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(trackingContext.ProcessActivityId);
                MessageMock.Setup(m => m.GetProperty(TrackingProperties.MessagingStepActivityId)).Returns(trackingContext.MessagingStepActivityId);

                var sut = ActivityTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Step));
                sut.TrackActivity();

                ActivityFactory.Verify(
                    af => af.CreateProcess(It.IsAny <IBaseMessage>(), It.IsAny <string>()),
                    Times.Never());
                ActivityFactory.Verify(
                    af => af.FindProcess(It.Is <TrackingContext>(c => c.ProcessActivityId == trackingContext.ProcessActivityId)),
                    Times.Once());
                ActivityFactory.Verify(
                    af => af.CreateMessagingStep(It.IsAny <IBaseMessage>()),
                    Times.Once());
                ActivityFactory.Verify(
                    af => af.FindMessagingStep(It.IsAny <TrackingContext>()),
                    Times.Never());
            }
        }
        public void CompleteTrackingOfOutboundMessageWithProcessAffiliationAfterStreamLastReadEvent()
        {
            using (var stream = new TrackingStream(new StringStream("some-content")))
            {
                MessageMock.Object.BodyPart.Data = stream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
                MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(ActivityId.NewActivityId());

                var sut = ActivityTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Step));
                sut.TrackActivity();
                MessageMock.Object.BodyPart.Data.Drain();

                ProcessMock.Verify(
                    p => p.TrackActivity(),
                    Times.Never());
                InitiatingMessagingStepMock.Verify(
                    ms => ms.TrackActivity(It.IsAny <ActivityTrackingModes>(), It.IsAny <TrackingStream>()),
                    Times.Never());
                ProcessMock.Verify(
                    p => p.AddStep(InitiatingMessagingStepMock.Object),
                    Times.Never());
                MessagingStepMock.Verify(
                    ms => ms.TrackActivity(It.IsAny <ActivityTrackingModes>(), It.IsAny <TrackingStream>()),
                    Times.Once());
                ProcessMock.Verify(
                    p => p.AddStep(MessagingStepMock.Object),
                    Times.Once());
            }
        }
        public void ResolveProcessNameBeforeStreamFirstReadEvent()
        {
            using (var stream = new TrackingStream(new StringStream("some-content")))
            {
                MessageMock.Object.BodyPart.Data = stream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");

                var sut = ActivityTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Step));
                sut.TrackActivity();

                TrackingResolverMock.Verify(tr => tr.ResolveProcessName(), Times.Once());
            }
        }