Skip to content

Commit

Permalink
Push down Stream related helpers into BaseFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimeast authored and nulltoken committed Oct 27, 2013
1 parent 2bb26a5 commit 36945a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
26 changes: 0 additions & 26 deletions LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,6 @@ public void CanReadBlobFilteredStreamOfUnmodifiedBinary()
}
}

public static void CopyStream(Stream input, Stream output)
{
// Reused from the following Stack Overflow post with permission
// of Jon Skeet (obtained on 25 Feb 2013)
// http://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file/411605#411605
var buffer = new byte[8*1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
}

public static bool StreamEquals(Stream one, Stream two)
{
int onebyte, twobyte;

while ((onebyte = one.ReadByte()) >= 0 && (twobyte = two.ReadByte()) >= 0)
{
if (onebyte != twobyte)
return false;
}

return true;
}

[Fact]
public void CanStageAFileGeneratedFromABlobContentStream()
{
Expand Down
26 changes: 26 additions & 0 deletions LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,31 @@ protected static void EnableRefLog(Repository repository, bool enable = true)
{
repository.Config.Set("core.logAllRefUpdates", enable);
}

public static void CopyStream(Stream input, Stream output)
{
// Reused from the following Stack Overflow post with permission
// of Jon Skeet (obtained on 25 Feb 2013)
// http://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file/411605#411605
var buffer = new byte[8 * 1024];
int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, len);
}
}

public static bool StreamEquals(Stream one, Stream two)
{
int onebyte, twobyte;

while ((onebyte = one.ReadByte()) >= 0 && (twobyte = two.ReadByte()) >= 0)
{
if (onebyte != twobyte)
return false;
}

return true;
}
}
}

0 comments on commit 36945a9

Please sign in to comment.