는 소리
internal void StartPipeServer(NamedPipeServerStream pipeServer)
{
Thread thread = new Thread(WaitForConnections);
thread.Start(pipeServer);
}
internal void WaitForConnections(object o)
{
NamedPipeServerStream pipe = (NamedPipeServerStream)o;
pipe.WaitForConnection();
}
HTH, RIP :
using (NamedPipeServerStream input = new NamedPipeServerStream("Test", PipeDirection.InOut))
using (NamedPipeClientStream pipeClient = new NamedPipeClientStream("Test"))
using (MemoryStream output = new MemoryStream())
using (StreamReader inSerial = new StreamReader(pipeClient))
using (StreamWriter outSerial = new StreamWriter(svpConsumer))
{
StartPipeServer(input);
pipeClient.Connect();
using (TestingClass myTest = new TestingClass(onSerial, outSerial))
{
input.Write(...);
input.Flush(...);
Assert on checking output
}
}
?
당신이 단위 테스트를 의미하는 경우, 당신은 할 수 :
- 는 래퍼에게 아마도 인터페이스, 파라미터 : iport
- 하여 SerialPort를 필요로하는 클래스로이 전달 보내기 직렬 포트
- 래퍼 만들기
- 모의
전달 된 SerialPost
internal interface IPort
{
void Connect();
//Other members
}
internal class SerialPort : IPort
{
public void Connect()
{
//Implementation
}
}
public class DataRetriever
{
private IPort _port;
public DataRetriever(IPort port)
{
_port = port;
}
public void ReadData()
{
_port.Connect();
}
}
이제 Data Retriever 클래스를 테스트 할 수 있습니다. Unfortinatly 프레임 워크 (예 : SerialPort 랩퍼)에 가까워지면 유닛 테스트를 수행 할 수 없습니다. 이를 통합 테스트에 맡겨야합니다.
감사합니다. Khurram, 저는 이미 잘 작동하는 가상 직렬 드라이버를 가지고 있지만 수동으로 포트 작동을 테스트해야합니다. '버디 (buddy)'포트를 열어 데이터를 전송하는 것을 자동화 할 수는 있지만 더 깨끗한 방법으로 자금을 조달하고 싶습니다. 내가 너의 제안을 오해하지 않았다면. –