public void CaptureThrowsWhenNoCapturingStream()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content), new MessageBodyCaptureDescriptor("url", MessageBodyCaptureMode.Claimed)))
     {
         Assert.That(
             // ReSharper disable AccessToDisposedClosure
             () => stream.Capture(),
             // ReSharper restore AccessToDisposedClosure
             Throws.InstanceOf <InvalidOperationException>()
             .With.Message.EqualTo("TrackingStream cannot be captured unless it has been setup with another capturing stream to replicate its payload to."));
     }
 }
 public void CaptureThrowsWhenNoCaptureDescriptor()
 {
     using (var stream = new TrackingStream(new MemoryStream(_content)))
     {
         Assert.That(
             // ReSharper disable AccessToDisposedClosure
             () => stream.Capture(),
             // ReSharper restore AccessToDisposedClosure
             Throws.InstanceOf <InvalidOperationException>()
             .With.Message.EqualTo("TrackingStream cannot be captured because its Descriptor is null and has not been initialized for tracking."));
     }
 }
 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));
         }
 }