mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-10-18 14:36:11 +08:00
fdbc4d3e36
Apply similar treatment to PipeStream as #1322 did to ShellStream PipeStream now behaves much more Stream-like. In particular, it performs partial reads (instead of blocking until a certain amount of data is available), blocks until data is available (instead of returning 0 prematurely) and removes the Stream-unlike properties `BlockLastReadBuffer` and `MaxBufferLength`. Sadly I gave up trying to make a benchmark compatible with all the quirks of the previous implementation, but a dumb throughput test (reading and writing simultaneously) shows about 5.2GB/s with this implementation compared to 140MB/s previously. Some cleanup of its usage in the library followed. Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
142 lines
3.1 KiB
C#
142 lines
3.1 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Tests.Common;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class PipeStreamTest_Dispose : TestBase
|
|
{
|
|
private PipeStream _pipeStream;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
base.OnInit();
|
|
|
|
Arrange();
|
|
Act();
|
|
}
|
|
|
|
private void Arrange()
|
|
{
|
|
_pipeStream = new PipeStream();
|
|
}
|
|
|
|
private void Act()
|
|
{
|
|
_pipeStream.Dispose();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CanRead_ShouldReturnTrue()
|
|
{
|
|
Assert.IsTrue(_pipeStream.CanRead);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Flush_ShouldNotThrow()
|
|
{
|
|
_pipeStream.Flush();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Length_ShouldNotThrow()
|
|
{
|
|
_ = _pipeStream.Length;
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Position_Getter_ShouldReturnZero()
|
|
{
|
|
Assert.AreEqual(0, _pipeStream.Position);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Position_Setter_ShouldThrowNotSupportedException()
|
|
{
|
|
try
|
|
{
|
|
_pipeStream.Position = 0;
|
|
Assert.Fail();
|
|
}
|
|
catch (NotSupportedException)
|
|
{
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Read_ByteArrayAndOffsetAndCount_ShouldNotThrow()
|
|
{
|
|
Assert.AreEqual(0, _pipeStream.Read(new byte[1], 0, 1));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ReadByte_ShouldNotThrow()
|
|
{
|
|
Assert.AreEqual(-1, _pipeStream.ReadByte());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Seek_ShouldThrowNotSupportedException()
|
|
{
|
|
try
|
|
{
|
|
_pipeStream.Seek(0, SeekOrigin.Begin);
|
|
Assert.Fail();
|
|
}
|
|
catch (NotSupportedException)
|
|
{
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SetLength_ShouldThrowNotSupportedException()
|
|
{
|
|
try
|
|
{
|
|
_pipeStream.SetLength(0);
|
|
Assert.Fail();
|
|
}
|
|
catch (NotSupportedException)
|
|
{
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Write_ByteArrayAndOffsetAndCount_ShouldThrowObjectDisposedException()
|
|
{
|
|
var buffer = new byte[0];
|
|
const int offset = 0;
|
|
const int count = 0;
|
|
|
|
try
|
|
{
|
|
_pipeStream.Write(buffer, offset, count);
|
|
Assert.Fail();
|
|
}
|
|
catch (ObjectDisposedException)
|
|
{
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void WriteByte_ShouldThrowObjectDisposedException()
|
|
{
|
|
const byte b = 0x0a;
|
|
|
|
try
|
|
{
|
|
_pipeStream.WriteByte(b);
|
|
Assert.Fail();
|
|
}
|
|
catch (ObjectDisposedException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|