私は遊んでPex
いて、簡単なクラスを持っています。コードは次のとおりです。
public void WriteLine(string line)
{
Contract.Requires(line != null);
if (_stream == null)
_stream = getStream();
var writer = new StreamWriter(_stream);
writer.WriteLine(line);
}
private Stream getStream()
{
return File.Open(Path, FileMode.Append, FileAccess.Write);
}
私は以下を作成しましたPexMethod
:
[PexMethod(MaxRunsWithoutNewTests = 200)]
public void WriteLine(string line)
{
var ms = new MemoryStream();
MFile.BehaveAsNotImplemented();
MFileStream.BehaveAsNotImplemented();
MStreamWriter.BehaveAsNotImplemented( );
MFile.OpenStringFileModeFileAccess = (p, m, a) => new FileStream(p, m);
MFileStream.ConstructorStringFileMode = (s, p, m) => new StreamWriter(ms);
MStreamWriter.AllInstances.BaseStreamGet = sw => ms;
MStreamWriter.ConstructorStream = (sw, s) =>
{
;
};
MTextWriter.AllInstances.WriteLineString = (tw, l) =>
{
var buf = Encoding.Unicode.GetBytes(line);
ms.Write(buf, 0, buf.Length);
};
var path = "C:\test.txt";
var target = new FileWriter(path);
target.WriteLine(line);
var buffer = ms.ToArray();
var result = Encoding.Unicode.GetString(buffer);
PexAssert.AreEqual<string>(line, result);
}
Pex Exploration
このユニットテストを思いついた:
[TestMethod]
[PexGeneratedBy(typeof(FileWriterTest))]
[PexRaisedException(typeof(PexAssertFailedException))]
[HostType("Moles")]
public void WriteLineThrowsPexAssertFailedException25()
{
this.WriteLine("\udc00");
}
奇妙なことに、スタックがudc00を使用して単体テストを終了し、パラメーター化されたテストに入るとすぐに、paramLineは次のように表されます。
ご覧のとおり、私はすべてのバッファリングをUnicodeで行っています。最終的にメモリストリームから文字列を読み取ろうとすると、中に疑問符が付いたひし形のような奇妙な記号が表示されます。
私が得るエラーは次のとおりです: "PexAssertFailedException" "予期された'奇妙なシンボル'、得られた'�'"
誰かが何が起こっているのか知っていますか?