public void SetupCaptureThrowsIfCaptureDescriptorHasAlreadyBeenSetup()
        {
            using (var stream = new TrackingStream(new MemoryStream(_content), new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed)))
            {
                Invoking(() => stream.SetupCapture(new MessageBodyCaptureDescriptor("other-data", MessageBodyCaptureMode.Unclaimed)))
                .Should().Throw <InvalidOperationException>()
                .WithMessage("TrackingStream's capture has already been setup and cannot be overwritten.");

                Invoking(() => stream.SetupCapture(new MessageBodyCaptureDescriptor("other-data", MessageBodyCaptureMode.Claimed), new MemoryStream()))
                .Should().Throw <InvalidOperationException>()
                .WithMessage("TrackingStream's capture has already been setup and cannot be overwritten.");
            }
        }
 public void InnerStreamIsWrappedByReplicatingStreamIfTracked()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed), new MemoryStream());
         Reflector.GetProperty(stream, "InnerStream").Should().BeOfType <ReplicatingReadStream>();
     }
 }
 public void CaptureThrowsWhenCaptureModeIsNotClaimed()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Unclaimed));
         Invoking(() => stream.Capture()).Should().Throw <InvalidOperationException>()
         .WithMessage("TrackingStream cannot be captured because its Descriptor's CaptureMode has not been set to Claimed but to Unclaimed.");
     }
 }
 public void SetupCaptureAsUnclaimedThrowsWhenCaptureModeIsOther()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         Invoking(() => stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed)))
         .Should().Throw <InvalidOperationException>()
         .WithMessage("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)))
     {
         Invoking(() => stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Claimed), null))
         .Should().Throw <ArgumentNullException>()
         .Which.ParamName.Should().Be("capturingStream");
     }
 }
 public void CaptureSetupResetMarkablePosition()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         var ms = stream.AsMarkable();
         ms.Drain();
         stream.Position.Should().Be(_content.Length);
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Unclaimed));
         stream.Position.Should().Be(0);
     }
 }
 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());
             innerStream.Position.Should().Be(0);
             Invoking(() => stream.Capture()).Should().NotThrow();
             innerStream.Position.Should().Be(innerStream.Length);
         }
 }
 public void PayloadIsNotBeingRedeemed()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         stream.IsRedeemed.Should().BeFalse();
         stream.SetupCapture(new MessageBodyCaptureDescriptor("some-data", MessageBodyCaptureMode.Unclaimed));
         stream.IsRedeemed.Should().BeFalse();
     }
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         stream.IsRedeemed.Should().BeFalse();
         stream.SetupCapture(new MessageBodyCaptureDescriptor("url", MessageBodyCaptureMode.Claimed), new MemoryStream());
         stream.IsRedeemed.Should().BeFalse();
     }
 }