剛開始編寫單元測試,我現在,阻斷這種情況:字符串轉換爲FILESTREAM在C#
我有具有FileStream對象的方法,我試圖以一種「串」傳遞給它。 所以,我想我的字符串轉換爲的FileStream和我這樣做:
File.WriteAllText(string.Concat(Environment.ExpandEnvironmentVariables("%temp%"),
@"/test.txt"), testFileContent); //writes my string to a temp file!
new FileStream(string.Concat(Environment.ExpandEnvironmentVariables("%temp%"),
@"/test.txt"), FileMode.Open) //open that temp file and uses it as a fileStream!
關閉文件呢!
但是,我想必須有一個非常簡單的替代方案來將字符串轉換爲fileStream。
歡迎提出建議! [注意,這個問題在stackoverflow中有其他答案,但似乎沒有一個簡單的解決方案]
在此先感謝!
問題是我無法更改代碼。這是一個已編譯的庫,我沒有源代碼! –
因此,用你自己的類覆蓋'FileStream'。 –
你將不得不嘲笑文件流,然後如其他人提到 – lloydom