diff --git a/src/Nancy.Tests/Unit/IO/RequestStreamFixture.cs b/src/Nancy.Tests/Unit/IO/RequestStreamFixture.cs
index 44a64c07c5..39b9db7d93 100644
--- a/src/Nancy.Tests/Unit/IO/RequestStreamFixture.cs
+++ b/src/Nancy.Tests/Unit/IO/RequestStreamFixture.cs
@@ -5,7 +5,6 @@ namespace Nancy.Tests.Unit.IO
using FakeItEasy;
using Nancy.IO;
using Xunit;
- using Xunit.Extensions;
public class RequestStreamFixture
{
@@ -148,6 +147,21 @@ public void Should_return_false_when_queried_about_supporting_seeking()
result.ShouldBeFalse();
}
+ [Fact]
+ public void Should_return_true_when_queried_about_supporting_seeking_if_buffered()
+ {
+ // Given
+ var stream = new ConfigurableMemoryStream();
+ var request = RequestStream.FromStream(stream, 0, 1, false);
+ request.BufferStream();
+
+ // When
+ var result = request.CanSeek;
+
+ // Then
+ result.ShouldBeTrue();
+ }
+
[Fact]
public void Should_return_underlaying_stream_when_queried_about_supporting_timeout()
{
diff --git a/src/Nancy/IO/RequestStream.cs b/src/Nancy/IO/RequestStream.cs
index 23a4e32ee5..172ebf6ccf 100644
--- a/src/Nancy/IO/RequestStream.cs
+++ b/src/Nancy/IO/RequestStream.cs
@@ -125,7 +125,14 @@ public override bool CanRead
/// Returns depending on whether the stream is buffered or not.
public override bool CanSeek
{
- get { return this.stream.CanSeek; }
+ get
+ {
+ if (!isBuffered)
+ {
+ return false;
+ }
+ return this.stream.CanSeek;
+ }
}
///
@@ -311,6 +318,10 @@ public override int ReadByte()
/// A value of type indicating the reference point used to obtain the new position.
public override long Seek(long offset, SeekOrigin origin)
{
+ if (!isBuffered)
+ {
+ throw new NotSupportedException();
+ }
return this.stream.Seek(offset, origin);
}
@@ -322,6 +333,10 @@ public override long Seek(long offset, SeekOrigin origin)
/// This functionality is not supported by the type and will always throw .
public override void SetLength(long value)
{
+ if (!isBuffered)
+ {
+ throw new NotSupportedException();
+ }
this.stream.SetLength(value);
}