public void CaptureOfOutboundMessageDoesNotPiggyBackKernelTransaction()
        {
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");

            using (new TransactionScope())
                using (var stream = new MemoryStream())
                {
                    MessageMock.Object.BodyPart.Data = stream;

                    var transaction = TransactionInterop.GetDtcTransaction(Transaction.Current);
                    PipelineContextMock.As <IPipelineContextEx>()
                    .Setup(pc => pc.GetTransaction())
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    .Returns((IKernelTransaction)transaction);

                    var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                    sut.SetupTracking();

                    ClaimStoreMock.Verify(
                        cs => cs.SetupMessageBodyCapture(
                            It.IsAny <TrackingStream>(),
                            It.IsAny <ActivityTrackingModes>(),
                            It.Is <Func <IKernelTransaction> >(ktf => ktf == null)),
                        Times.Once());
                }
        }
        public void CaptureOfInboundMessagePiggiesBackKernelTransaction()
        {
            using (new TransactionScope())
                using (var stream = new MemoryStream())
                {
                    MessageMock.Object.BodyPart.Data = stream;

                    var transaction = TransactionInterop.GetDtcTransaction(Transaction.Current);
                    PipelineContextMock.As <IPipelineContextEx>()
                    .Setup(pc => pc.GetTransaction())
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    .Returns((IKernelTransaction)transaction);

                    var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                    sut.SetupTracking();

                    ClaimStoreMock.Verify(
                        cs => cs.SetupMessageBodyCapture(
                            It.IsAny <TrackingStream>(),
                            It.IsAny <ActivityTrackingModes>(),
                            // ReSharper disable once SuspiciousTypeConversion.Global
                            It.Is <Func <IKernelTransaction> >(ktf => ReferenceEquals(ktf(), transaction))),
                        Times.Once());
                }
        }
        public void InboundMessageBodyIsNotCheckedIn()
        {
            var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));

            sut.TryCheckInMessageBody();

            ClaimStoreMock.Verify(cs => cs.Claim(MessageMock.Object, It.IsAny <IResourceTracker>()), Times.Never());
        }
        public void OutboundMessageBodyIsNotCheckedOut()
        {
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");

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

            sut.TryCheckOutMessageBody();

            ClaimStoreMock.Verify(cs => cs.Redeem(MessageMock.Object, It.IsAny <IResourceTracker>()), Times.Never());
        }
        public void CaptureIsNotSetupIfTrackingStreamAlreadyHasCaptureDescriptor()
        {
            using (var trackingStream = new TrackingStream(new MemoryStream(), new MessageBodyCaptureDescriptor("url", MessageBodyCaptureMode.Claimed)))
            {
                MessageMock.Object.BodyPart.Data = trackingStream;

                var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                sut.SetupTracking();
            }

            ClaimStoreMock.Verify(
                cs => cs.SetupMessageBodyCapture(It.IsAny <TrackingStream>(), It.IsAny <ActivityTrackingModes>(), It.IsAny <Func <IKernelTransaction> >()),
                Times.Never());
        }
        public void CaptureOfInboundMessageIsSetup()
        {
            using (var stream = new MemoryStream())
            {
                MessageMock.Object.BodyPart.Data = stream;

                var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                sut.SetupTracking();
            }

            ClaimStoreMock.Verify(
                cs => cs.SetupMessageBodyCapture(It.IsAny <TrackingStream>(), It.IsAny <ActivityTrackingModes>(), It.Is <Func <IKernelTransaction> >(ktf => ktf != null)),
                Times.Once());

            Assert.That(MessageMock.Object.BodyPart.Data, Is.TypeOf <TrackingStream>());
        }
        public void CaptureOfOutboundMessageIsSetup()
        {
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");

            using (var stream = new MemoryStream())
            {
                MessageMock.Object.BodyPart.Data = stream;

                var sut = MessageBodyTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Body));
                sut.SetupTracking();
            }

            ClaimStoreMock.Verify(
                cs => cs.SetupMessageBodyCapture(It.IsAny <TrackingStream>(), It.IsAny <ActivityTrackingModes>(), It.Is <Func <IKernelTransaction> >(ktf => ktf == null)),
                Times.Once());

            Assert.That(MessageMock.Object.BodyPart.Data, Is.TypeOf <TrackingStream>());
        }