public void ShouldCopyEntityBodyWithoutTransformingContents() { IEntityBodyTransformationStrategy transformationStrategy = new CopyEntityBody(ResourceStreams.CurrentFeed()); MemoryStream destination = new MemoryStream(); transformationStrategy.WriteEntityBody(destination); string sourceContents; string destinationContents; using (StreamReader reader = new StreamReader(ResourceStreams.CurrentFeed())) { sourceContents = reader.ReadToEnd(); } destination.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(destination)) { destinationContents = reader.ReadToEnd(); } Assert.False(string.IsNullOrEmpty(sourceContents)); Assert.False(string.IsNullOrEmpty(destinationContents)); Assert.AreEqual(sourceContents, destinationContents); }
public void ShouldNotCloseDestinationStream() { IEntityBodyTransformationStrategy transformationStrategy = new CopyEntityBody(ResourceStreams.CurrentFeed()); MemoryStream destination = new MemoryStream(); transformationStrategy.WriteEntityBody(destination); Assert.AreEqual(0, destination.Seek(0, SeekOrigin.Begin)); }
public void ShouldCloseSourceStream() { FileStream source = new FileStream(@"..\..\Data\productcatalog\current.atom", FileMode.Open); IEntityBodyTransformationStrategy transformationStrategy = new CopyEntityBody(source); MemoryStream destination = new MemoryStream(); transformationStrategy.WriteEntityBody(destination); source.Seek(0, SeekOrigin.Begin); }
public void ShouldSetContentLengthHeader() { var entityBody = new CopyEntityBody(new MemoryStream(new byte[4])); ExecuteTest( responseWrapper => { responseWrapper.WriteContentLength(4); responseWrapper.WriteEntityBody(entityBody); }, response => Assert.AreEqual(4, response.ContentLength)); }
public void ShouldNotSetContentLengthHeaderWhenChunked() { var entityBody = new CopyEntityBody(new MemoryStream(new byte[4])); ExecuteTest( responseWrapper => { responseWrapper.WriteContentLength(4); responseWrapper.WriteIsChunked(true); responseWrapper.WriteEntityBody(entityBody); }, response => Assert.IsNull(response.Headers[HttpResponseHeader.ContentLength])); }
public void ShouldWriteEntityBody() { string content = "some content"; var entityBody = new CopyEntityBody(new MemoryStream(Encoding.UTF8.GetBytes(content))); ExecuteTest( responseWrapper => responseWrapper.WriteEntityBody(entityBody), response => { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string foundContent = reader.ReadToEnd(); Assert.AreEqual(content, foundContent); } }); }