public void InnerStreamIsWrappedByReplicatingStreamIfTracked()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed), new MemoryStream());
         Assert.That(Reflector.GetProperty(stream, "InnerStream"), Is.InstanceOf <ReplicatingReadStream>());
     }
 }
        public void SetupCaptureThrowsIfCaptureDescriptorHasAlreadyBeenSetup()
        {
            using (var stream = new TrackingStream(new MemoryStream(_content), new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed)))
            {
                Assert.That(
                    // ReSharper disable AccessToDisposedClosure
                    () => stream.SetupCapture(new MessageBodyCaptureDescriptor("other-data", MessageBodyCaptureMode.Unclaimed)),
                    // ReSharper restore AccessToDisposedClosure
                    Throws.InstanceOf <InvalidOperationException>()
                    .With.Message.EqualTo("TrackingStream's capture has already been setup and cannot be overwritten."));

                Assert.That(
                    // ReSharper disable AccessToDisposedClosure
                    () => stream.SetupCapture(new MessageBodyCaptureDescriptor("other-data", MessageBodyCaptureMode.Claimed), new MemoryStream()),
                    // ReSharper restore AccessToDisposedClosure
                    Throws.InstanceOf <InvalidOperationException>()
                    .With.Message.EqualTo("TrackingStream's capture has already been setup and cannot be overwritten."));
            }
        }
        public void CaptureSetupResetMarkablePosition()
        {
            using (var stream = new TrackingStream(new MemoryStream(_content)))
            {
                var ms = stream.AsMarkable();
                ms.Drain();
                Assert.That(stream.Position, Is.EqualTo(_content.Length));

                stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Unclaimed));
                Assert.That(stream.Position, Is.EqualTo(0));
            }
        }
 public void SetupCaptureAsUnclaimedThrowsWhenCaptureModeIsOther()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         Assert.That(
             // ReSharper disable AccessToDisposedClosure
             () => stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed)),
             // ReSharper restore AccessToDisposedClosure
             Throws.InstanceOf <InvalidOperationException>()
             .With.Message.EqualTo("TrackingStream's capture cannot be setup with a CaptureMode of Claimed; other CaptureMode than Unclaimed requires a capturing stream."));
     }
 }
 public void SetupCaptureAsClaimedThrowsWithoutCapturingStream()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         Assert.That(
             // ReSharper disable AccessToDisposedClosure
             () => stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed), null),
             // ReSharper restore AccessToDisposedClosure
             Throws.InstanceOf <ArgumentNullException>()
             .With.Property("ParamName").EqualTo("capturingStream"));
     }
 }
 public void CaptureThrowsWhenCaptureModeIsNotClaimed()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Unclaimed));
         Assert.That(
             // ReSharper disable AccessToDisposedClosure
             () => stream.Capture(),
             // ReSharper restore AccessToDisposedClosure
             Throws.InstanceOf <InvalidOperationException>()
             .With.Message.EqualTo("TrackingStream cannot be captured because its Descriptor's CaptureMode has not been set to Claimed but to Unclaimed."));
     }
 }
 public void CaptureDrainsInnerStream()
 {
     using (var innerStream = new MemoryStream(_content))
         using (var stream = new TrackingStream(innerStream))
         {
             stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed), new MemoryStream());
             Assert.That(innerStream.Position, Is.EqualTo(0));
             Assert.That(
                 // ReSharper disable AccessToDisposedClosure
                 () => stream.Capture(),
                 // ReSharper restore AccessToDisposedClosure
                 Throws.Nothing);
             Assert.That(innerStream.Position, Is.EqualTo(innerStream.Length));
         }
 }
 public void PayloadIsNotBeingRedeemed()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         Assert.That(stream.IsRedeemed, Is.False);
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Unclaimed));
         Assert.That(stream.IsRedeemed, Is.False);
     }
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         Assert.That(stream.IsRedeemed, Is.False);
         stream.SetupCapture(new MessageBodyCaptureDescriptor("url", MessageBodyCaptureMode.Claimed), new MemoryStream());
         Assert.That(stream.IsRedeemed, Is.False);
     }
 }