コード例 #1
0
 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."));
     }
 }
コード例 #2
0
 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."));
     }
 }
コード例 #3
0
 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."));
     }
 }
コード例 #4
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());
             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));
         }
 }