public void DatadrivenLoggerTest() { var iteration = (int)TestContext.DataRow["Iteration"]; var message = (string)TestContext.DataRow["Message"]; StfLogger.LogInfo($"Iteration [{iteration}]: {message}"); // need to close the logfile, in order to check the content of the logfile... StfLogger.CloseLogFile(); // we want to fail, if FileContains fails StfAssert.EnableNegativeTesting = false; StfAssert.FileContains(iteration.ToString(), StfLogger.FileName, message); }
public void TestMethodAssertFilesDiffer01() { const string UnitTestFile1 = @"TestData\TestMethodAssertFileNotExists1.xml"; const string UnitTestFile2 = @"TestData\TestMethodAssertFileNotExists2.xml"; Assert.IsTrue(StfAssert.FilesDoDiffer("TestStepName 1", UnitTestFile1, UnitTestFile2)); Assert.IsFalse(StfAssert.FilesDoNotDiffer("TestStepName 1", UnitTestFile1, UnitTestFile2)); // null and empty strings returns false Assert.IsFalse(StfAssert.FileContains("filename1 null, filename2 Null", null, null)); Assert.IsFalse(StfAssert.FileContains("filename1 null, filename2 Empty", null, string.Empty)); Assert.IsFalse(StfAssert.FileContains("filename1 null, filename2 notNull", null, UnitTestFile1)); Assert.IsFalse(StfAssert.FileContains("filename1 Empty, filename2 Null", string.Empty, null)); Assert.IsFalse(StfAssert.FileContains("filename1 Empty, filename2 Empty", string.Empty, string.Empty)); Assert.IsFalse(StfAssert.FileContains("filename1 Empty, filename2 notNull", string.Empty, UnitTestFile1)); Assert.IsFalse(StfAssert.FileContains("filename1 null, filename2 Null", UnitTestFile1, null)); Assert.IsFalse(StfAssert.FileContains("filename1 null, filename2 Empty", UnitTestFile1, string.Empty)); Assert.IsFalse(StfAssert.FileContains("filename1 null, filename2 notNull", UnitTestFile1, "A string")); }
public void TestMethodAssertFileContains() { const string UnitTestFile = @"c:\temp\TestMethodAssertFileContains.txt"; var testFile = File.CreateText(UnitTestFile); testFile.WriteLine("one line of test data"); testFile.Close(); // positive tests Assert.IsTrue(StfAssert.FileContains("TestStep litteral string", UnitTestFile, "test")); Assert.IsTrue(StfAssert.FileContains("TestStep regular regexp", UnitTestFile, "t[eE]st")); Assert.IsFalse(StfAssert.FileContains("TestStepName 1", @"c:\DoNotExists.nope", "A string")); Assert.IsFalse(StfAssert.FileContains("TestStepName 2", UnitTestFile, "Nothing Like it")); // null and empty strings returns false Assert.IsFalse(StfAssert.FileContains("filename null, searchstring notNull", null, "A string")); Assert.IsFalse(StfAssert.FileContains("filename null, searchstring Null", null, null)); Assert.IsFalse(StfAssert.FileContains("filename null, searchstring Empty", null, string.Empty)); Assert.IsFalse(StfAssert.FileContains("Not existing file, search string Null", @"c:\DoNotExists.nope", null)); Assert.IsFalse(StfAssert.FileContains("Not existing file, search string Empty ", @"c:\DoNotExists.nope", string.Empty)); Assert.IsFalse(StfAssert.FileContains("Existing file, search string Null", UnitTestFile, null)); Assert.IsFalse(StfAssert.FileContains("Existing file, search string Empty ", UnitTestFile, string.Empty)); }