public void TestCleanUp() { if (File.Exists(FileMocks.FileThatDoesNotExist())) { File.Delete(FileMocks.FileThatDoesNotExist()); } }
public void Writes_InnerException_To_File() { Exception outer = null; Exception inner = null; using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { try { throw new Exception("This is the inner exception message"); } catch (Exception caught) { inner = caught; } try { throw new Exception("This is the outer exception message", inner); } catch (Exception caught) { outer = caught; } logger.Write("Exception occured!", outer); } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining(inner.Message).And.StringContaining(inner.StackTrace) ); }
public void New_Creates_NonExistent_File() { Assert.False(File.Exists(FileMocks.FileThatDoesNotExist())); using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { Assert.True(File.Exists(FileMocks.FileThatDoesNotExist())); } }
public void New_Writes_Log_Header() { using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { //no-op } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining("Log Start").IgnoreCase ); }
public void Writes_Blank_Line_To_File() { using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { logger.WriteLine(); } Assert.That( File.ReadAllLines(FileMocks.FileThatDoesNotExist()).Length, Is.EqualTo(2) ); }
public void Writes_Simple_Message_To_File() { string message = "This is a log message"; using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { logger.WriteLine(message); } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining(message) ); }
public void Writes_Format_Message_To_File() { string format = "This is a log format with 2 params {0} {1}"; string param1 = "param1"; string param2 = "param2"; using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { logger.WriteLine(format, param1, param2); } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining(param1).And.StringContaining(param2) ); }
public void TestInitialize() { simpleEntities = new[] { new SimpleEntityMock(foo, bar) }; if (File.Exists(FileMocks.FileThatDoesNotExist(".csv"))) { File.Delete(FileMocks.FileThatDoesNotExist(".csv")); } if (File.Exists(FileMocks.FileThatDoesNotExist(".tsv"))) { File.Delete(FileMocks.FileThatDoesNotExist(".tsv")); } if (File.Exists(FileMocks.FileThatDoesNotExist(".json"))) { File.Delete(FileMocks.FileThatDoesNotExist(".json")); } }
public void New_ReThrows_Target_File_Exceptions() { //make sure the target file exists File.WriteAllText(FileMocks.FileThatDoesNotExist(), String.Empty); //open the target file in exclusive mode using (var exclusive = File.Open(FileMocks.FileThatDoesNotExist(), FileMode.Open, FileAccess.Read, FileShare.None)) { Assert.That( () => { using (var shouldFail = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { //no-op } }, Throws.InstanceOf <IOException>() ); } }
public void TestInitialize() { Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; simpleEntities = new[] { new SimpleEntityMock(foo, bar) }; if (File.Exists(FileMocks.FileThatDoesNotExist(".csv"))) { File.Delete(FileMocks.FileThatDoesNotExist(".csv")); } if (File.Exists(FileMocks.FileThatDoesNotExist(".tsv"))) { File.Delete(FileMocks.FileThatDoesNotExist(".tsv")); } if (File.Exists(FileMocks.FileThatDoesNotExist(".json"))) { File.Delete(FileMocks.FileThatDoesNotExist(".json")); } }
public void Writes_Exception_To_File() { Exception ex = null; using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { try { throw new Exception("This is the exception message"); } catch (Exception caught) { ex = caught; } logger.Write("Exception occured!", ex); } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Does.Contain(ex.Message).And.Contains(ex.StackTrace) ); }
public void New_Rolls_Log_After_MaximumLogSize() { //create some test data that is just larger than the MaximumLogSize byte[] data = Enumerable.Range(1, SimpleFileLogger.DefaultMaximumLogBytes + 1) .Select(i => Convert.ToByte(i % 255)) .ToArray(); File.WriteAllBytes(FileMocks.FileThatDoesNotExist(), data); using (var logger = new SimpleFileLogger(FileMocks.FileThatDoesNotExist())) { //no-op } Assert.That( File.ReadAllText(FileMocks.FileThatDoesNotExist()), Is.StringContaining("Log Rollover").IgnoreCase ); Assert.That( File.ReadAllBytes(FileMocks.FileThatDoesNotExist()).LongLength, Is.LessThan(SimpleFileLogger.DefaultMaximumLogBytes + 1) ); }
public void ExportCSV_Creates_NonExistent_File() { Assert.False(File.Exists(FileMocks.FileThatDoesNotExist(".csv"))); DataFileExporter.ExportCSV(simpleEntities, FileMocks.FileThatDoesNotExist(".csv")); Assert.True(File.Exists(FileMocks.FileThatDoesNotExist(".csv"))); }