public void FileWriterIsCalledWhenCallingWrite() { var columns = new[] { "one", "two" }; var handleStreams = A.Fake <IHandleStreams>(); handleStreams.StreamWriter = new StreamWriter(new MemoryStream(Encoding.Default.GetBytes("hi"))); var mode = CSVReaderWriter.Mode.Write; A.CallTo(() => _fileOpener.Open("someFile", mode)).Returns(handleStreams); _csvReaderWriter.Open("someFile", mode); _csvReaderWriter.Write(columns); A.CallTo(() => _fileWriter.Write(columns, handleStreams)).MustHaveHappened(); }
public void Write(params string[] columns) { if (_streamHandler?.StreamWriter == null) { throw new Exception("Cannot write file, failed to acquire write mode"); } _fileWriter.Write(columns, _streamHandler); }
public static void Save(Frames frames, string path, IWriteFile fileSystem) { try { fileSystem.Open(path); foreach (int pin in frames.GetPins()) { fileSystem.Write(pin.ToString() + ","); } } finally { fileSystem.Close(); } }
/// <summary> /// ファイル作成 /// </summary> /// <param name="writter"></param> private void CreateFile(IWriteFile writter) { try { // ダイアログ表示 var dialog = new SaveFileDialog(); dialog.Filter = "(*.txt)|*.txt"; //dialog.DefaultExt = "txt"; dialog.FileName = "Dto1.txt"; dialog.RestoreDirectory = true; if (dialog.ShowDialog() != DialogResult.OK) { return; } // 保存 Stream stream = null; using (stream = dialog.OpenFile()) { if (stream != null) { using (var sw = new StreamWriter(stream, Encoding.GetEncoding("UTF-8"))) { for (int i = 0; i < this.dtoView.Rows.Count; i++) { var strType = (string)this.dtoView.Rows[i].Cells[0].Value; var strDec = (string)(this.dtoView.Rows[i].Cells[1].Value ?? ""); var strPhygNm = (string)this.dtoView.Rows[i].Cells[2].Value; var strLgNm = (string)this.dtoView.Rows[i].Cells[3].Value; if (string.IsNullOrWhiteSpace(strType)) { break; } // 値型のセット if (strType == "NUMERIC" || strType == "DECIMAL") { var intDec = this.Get_intValue(strDec); strType = intDec == 0 ? "int" : "double"; } else { strType = "string"; } var item = new WriteItem() { TYPE = strType, PHYGIC_NM = strPhygNm, LOGIC_NM = strLgNm }; // 生成 writter.Write(sw, item); } } } } } catch (Exception ex) { MessageBox.Show(ex.GetBaseException().ToString(), "例外", MessageBoxButtons.OK, MessageBoxIcon.Error); } }