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 InnerStreamIsWrappedByMarkableStream() { using (var stream = new TrackingStream(new MemoryStream(_content))) { stream.AsMarkable(); Assert.That(Reflector.GetProperty(stream, "InnerStream"), Is.InstanceOf <MarkableForwardOnlyEventingReadStream>()); } }
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 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 PayloadIsBeingRedeemed() { Assert.That( () => new TrackingStream(new MemoryStream(), new MessageBodyCaptureDescriptor("url", MessageBodyCaptureMode.Unclaimed)), Throws.ArgumentException.With.Message.StartsWith( "A TrackingStream, whose payload is being redeemed, cannot be instantiated with a CaptureDescriptor having a CaptureMode of Unclaimed; " + "the only compliant CaptureMode is Claimed.")); using (var stream = new TrackingStream(new MemoryStream(_content), new MessageBodyCaptureDescriptor("url", MessageBodyCaptureMode.Claimed))) { Assert.That(stream.IsRedeemed, Is.True); } }
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); } }
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 EventsAreNotFiredThroughMarkableInnerStream() { using (var stream = new TrackingStream(new MemoryStream(_content))) { var edgeEventsCount = 0; stream.AfterLastReadEvent += (sender, args) => ++ edgeEventsCount; stream.BeforeFirstReadEvent += (sender, args) => ++ edgeEventsCount; var eventsCount = 0; stream.ReadEvent += (sender, args) => ++ eventsCount; var markableForwardOnlyEventingReadStream = stream.AsMarkable(); Assert.That(edgeEventsCount, Is.EqualTo(0)); Assert.That(eventsCount, Is.EqualTo(0)); markableForwardOnlyEventingReadStream.Drain(); Assert.That(edgeEventsCount, Is.EqualTo(0)); Assert.That(eventsCount, Is.EqualTo(0)); } }