public void op_Item_stringNull() { using (var obj = new StreamWriterDictionary()) { // ReSharper disable AccessToDisposedClosure Assert.Throws <ArgumentNullException>(() => obj.Item(null as string)); // ReSharper restore AccessToDisposedClosure } }
public void op_Item_FileInfo() { using (var file = new TempFile()) { using (var obj = new StreamWriterDictionary()) { obj.Item(file.Info).Write("example"); } file.Info.Refresh(); Assert.True(file.Info.Exists); } }
public void op_Dispose() { using (var file = new TempFile()) { var obj = new StreamWriterDictionary(); obj.Dispose(); // ReSharper disable AccessToDisposedClosure Assert.Throws <InvalidOperationException>(() => obj.Item(file.Info)); // ReSharper restore AccessToDisposedClosure } }
public void op_Item_string_string_FileModeTruncate_FileAccessReadWrite_FileShareWrite() { using (var file = new TempFile()) { using (var obj = new StreamWriterDictionary("example")) { obj.Item(file.Info.FullName, "one", FileMode.Truncate, FileAccess.ReadWrite, FileShare.Write).Write("two"); } var expected = "one{0}two".FormatWith(Environment.NewLine); var actual = File.ReadAllText(file.Info.FullName); Assert.Equal(expected, actual); } }
public void op_Item_string_stringNull_FileModeTruncate_FileAccessReadWrite_FileShareWrite() { using (var file = new TempFile()) { using (var obj = new StreamWriterDictionary()) { obj.Item(file.Info.FullName, null, FileMode.Truncate, FileAccess.ReadWrite, FileShare.Write); } var expected = string.Empty; var actual = File.ReadAllText(file.Info.FullName); Assert.Equal(expected, actual); } }
public void op_Item_string_string() { using (var file = new TempFile()) { using (var obj = new StreamWriterDictionary()) { obj.Item(file.Info.FullName, "one").Write("two"); } var expected = "one{0}two".FormatWith(Environment.NewLine); var actual = File.ReadAllText(file.Info.FullName); Assert.Equal(expected, actual); } }
public void op_Item_string_stringEmpty_FileModeCreate_FileAccessReadWrite_FileShareWrite() { using (var file = new TempFile()) { file.Info.Delete(); using (var obj = new StreamWriterDictionary()) { obj.Item(file.Info.FullName, string.Empty, FileMode.Create, FileAccess.ReadWrite, FileShare.Write); } var expected = Environment.NewLine; var actual = File.ReadAllText(file.Info.FullName); Assert.Equal(expected, actual); } }
public void op_Item_string_caseInsensitive() { using (var temp = new TempDirectory()) { var lower = temp.Info.ToFile("abc"); var upper = temp.Info.ToFile("ABC"); using (var obj = new StreamWriterDictionary()) { obj.Item(lower.FullName).Write("example"); obj.Item(upper.FullName).Write("example"); } const int expected = 1; var actual = temp.Info.GetFiles().Length; Assert.Equal(expected, actual); } }
public int Create(IEnumerable <KeyStringDictionary> data) { if (null == data) { throw new ArgumentNullException("data"); } if (Destination.Exists) { throw new IOException("\"{0}\" already exists.".FormatWith(Destination.FullName)); } Count = 0; Stopwatch = new Stopwatch(); Stopwatch.Start(); using (var temp = new TempFile(CurrentTempDirectory.Location)) { using (var writers = new StreamWriterDictionary()) { foreach (var entry in data) { Count++; if (null == writers.FirstLine) { writers.FirstLine = Csv.Header(entry); } writers.Item(temp.Info).WriteLine(Csv.Line(entry)); } } if (Count.IsNot(0)) { temp.Info.CopyTo(Destination); Destination.SetDate(Modified); } } Stopwatch.Stop(); return(Count); }
public TempCsvFile(IEnumerable <KeyStringDictionary> data) : base(CurrentTempDirectory.Location) { if (null == data) { throw new ArgumentNullException("data"); } using (var writers = new StreamWriterDictionary()) { foreach (var entry in data) { if (null == writers.FirstLine) { writers.FirstLine = Csv.Header(entry); } writers.Item(Info).WriteLine(Csv.Line(entry)); } } }
public void op_Item_string_string_FileModeAppend_FileAccessWrite_FileShareWrite_whenCalledAgain() { using (var file = new TempFile()) { file.Info.Delete(); using (var obj = new StreamWriterDictionary("example")) { obj.Item(file.Info.FullName, "one", FileMode.Append, FileAccess.Write, FileShare.Write).WriteLine("two"); } using (var obj = new StreamWriterDictionary("example")) { obj.Item(file.Info.FullName, "one", FileMode.Append, FileAccess.Write, FileShare.Write).Write("three"); } var expected = "one{0}two{0}three".FormatWith(Environment.NewLine); var actual = File.ReadAllText(file.Info.FullName); Assert.Equal(expected, actual); } }