public void TestMethodAssertLessThan() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAssertLessThan.html" }; var myAsserts = new StfAssert(myLogger); var obj1 = new DateTime(42); var obj2 = new DateTime(4242); myAsserts.EnableNegativeTesting = true; Assert.IsFalse(myAsserts.AssertLessThan("2 < 1", 2, 1)); Assert.IsFalse(myAsserts.AssertLessThan("2.0 < 1", 2.0, 1)); Assert.IsTrue(myAsserts.AssertLessThan("1 < \"2\"", 1, "2")); Assert.IsFalse(myAsserts.AssertLessThan("1 < \"1.0\"", 1, "1.0")); Assert.IsFalse(myAsserts.AssertLessThan("\"\" < \"\"", string.Empty, string.Empty)); Assert.IsTrue(myAsserts.AssertLessThan("\"\" < \" \"", string.Empty, " ")); Assert.IsFalse(myAsserts.AssertLessThan("\" \" < \" \"", " ", string.Empty)); Assert.IsTrue(myAsserts.AssertLessThan("\"a\" < \"A\"", "a", "A")); Assert.IsFalse(myAsserts.AssertLessThan("\"A\" < \"a\"", "A", "a")); Assert.IsFalse(myAsserts.AssertLessThan("\"string\" < \"string\"", "string", "string")); Assert.IsFalse(myAsserts.AssertLessThan("obj1 < obj1", obj1, obj1)); Assert.IsTrue(myAsserts.AssertLessThan("obj1 < obj2", obj1, obj2)); Assert.IsFalse(myAsserts.AssertLessThan("obj2 < obj1", obj2, obj1)); // fail scenarios Assert.IsFalse(myAsserts.AssertLessThan("obj1 = 1", obj1, 1)); // a bit funky - the object obj1 is converted to string, and then the strings are compared. Assert.IsFalse(myAsserts.AssertLessThan("obj1 = \"string\"", obj1, "string")); }
public void TestMethodAssertFileExists() { const string UnitTestFile = @"c:\temp\TestMethodAssertFileContains.txt"; var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_AssertFileExists.html" }; var myAsserts = new StfAssert(myLogger); myAsserts.EnableNegativeTesting = true; if (File.Exists(UnitTestFile)) { File.Delete(UnitTestFile); } Assert.IsFalse(myAsserts.AssertFileExists("TestStepName 1", @"c:\DoNotExists.nope")); Assert.IsFalse(myAsserts.AssertFileExists("TestStepName 2", UnitTestFile)); var testFile = File.CreateText(UnitTestFile); testFile.WriteLine("one line of test data"); testFile.Close(); Assert.IsTrue(myAsserts.AssertFileExists("TestStepName 3", UnitTestFile)); }
public void TestMethodAssertEquals() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAssertEquals.html" }; var myAsserts = new StfAssert(myLogger); var obj1 = new DateTime(42); var obj2 = new DateTime(4242); myAsserts.EnableNegativeTesting = true; Assert.IsTrue(myAsserts.AssertEquals("1 = 1", 1, 1)); Assert.IsFalse(myAsserts.AssertEquals("1 = 1.0", 1, 1.0)); Assert.IsFalse(myAsserts.AssertEquals("1 = \"1\"", 1, "1")); Assert.IsFalse(myAsserts.AssertEquals("1 = \"1.0\"", 1, "1.0")); Assert.IsTrue(myAsserts.AssertEquals("\"\" == \"\"", string.Empty, string.Empty)); Assert.IsFalse(myAsserts.AssertEquals("\"\" == \" \"", string.Empty, " ")); Assert.IsFalse(myAsserts.AssertEquals("\" \" == \" \"", " ", string.Empty)); Assert.IsFalse(myAsserts.AssertEquals("\"A\" == \"a\"", "A", "a")); Assert.IsTrue(myAsserts.AssertEquals("\"string\" == \"string\"", "string", "string")); Assert.IsTrue(myAsserts.AssertEquals("obj1 = obj1", obj1, obj1)); Assert.IsFalse(myAsserts.AssertEquals("obj1 = obj2", obj1, obj2)); // fail scenarios Assert.IsFalse(myAsserts.AssertEquals("obj1 = 1", obj1, 1)); Assert.IsFalse(myAsserts.AssertEquals("obj1 = \"string\"", obj1, "string")); }
public void TestMethodInit() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodInit.html" }; myLogger.CloseLogFile(); }
public void TestMethodKeyValues() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodKeyValues.html", LogLevel = LogLevel.Internal }; myLogger.LogKeyValue("Bent", "42", "First value for Bent"); myLogger.LogKeyValue("Bent", "43", "Second value for Bent - this is the only one that should be shown in the list"); }
public void TestMethodAssertFalse() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_AssertFalse.html" }; var myAsserts = new StfAssert(myLogger); myAsserts.EnableNegativeTesting = true; Assert.IsFalse(myAsserts.AssertFalse("true", true)); Assert.IsTrue(myAsserts.AssertFalse("false", false)); }
public void TestLogScreenshot() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestLogScreenshot.html", LogLevel = LogLevel.Internal }; myLogger.LogTrace("Just before a screenshot is taken"); myLogger.LogScreenshot(LogLevel.Info, "Grabbed screenshot"); myLogger.LogTrace("right after a screenshot is taken"); }
public void TestLogFileWriter() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestLogFileWriter.html" }; myLogger.FileName = @"c:\temp\unittestlogger.html"; myLogger.FileName = @"c:\temp\unittestlogger2.html"; myLogger.FileName = @"c:\temp\unittestlogger3.html"; myLogger.CloseLogFile(); }
public void TestLogAllWindows() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestLogAllWindows.html", LogLevel = LogLevel.Internal }; myLogger.LogTrace("Just before logging all windows"); myLogger.LogAllWindows(LogLevel.Info, "Grabbed all windows"); myLogger.LogTrace("right after logging all windows"); }
public void TestMethodAssertStrings() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAssertStrings.html" }; var myAsserts = new StfAssert(myLogger); Assert.IsTrue(myAsserts.StringContains("TestStepName 1", "Hejsa", "Hej")); Assert.IsFalse(myAsserts.StringContains("TestStepName 2", "Hejsa", "Bent")); Assert.IsTrue(myAsserts.StringDoesNotContain("TestStepName 3", "Hejsa", "Bent")); Assert.IsFalse(myAsserts.StringDoesNotContain("TestStepName 4", "Hejsa", "Hej")); Assert.IsTrue(myAsserts.StringMatches("TestStepName 5", "Hejsa", "^He.*")); Assert.IsFalse(myAsserts.StringMatches("TestStepName 6", "Hejsa", "Nix.*")); Assert.IsTrue(myAsserts.StringDoesNotMatch("TestStepName 7", "Hejsa", "Nix.*")); Assert.IsFalse(myAsserts.StringDoesNotMatch("TestStepName 8", "Hejsa", "^He.*")); Assert.IsTrue(myAsserts.StringStartsWith("TestStepName 9", "Hejsa", "He")); Assert.IsFalse(myAsserts.StringStartsWith("TestStepName 10", "Hejsa", "hej")); Assert.IsTrue(myAsserts.StringDoesNotStartWith("TestStepName 11", "Hejsa", "hej")); Assert.IsFalse(myAsserts.StringDoesNotStartWith("TestStepName 12", "Hejsa", "He")); Assert.IsTrue(myAsserts.StringEndsWith("TestStepName 13", "Hejsa", "jsa")); Assert.IsFalse(myAsserts.StringEndsWith("TestStepName 14", "Hejsa", "Hej")); Assert.IsTrue(myAsserts.StringDoesNotEndsWith("TestStepName 15", "Hejsa", "Bent")); Assert.IsFalse(myAsserts.StringDoesNotEndsWith("TestStepName 16", "Hejsa", "ejsa")); Assert.IsTrue(myAsserts.StringEquals("TestStepName 17", "Hejsa", "Hejsa")); Assert.IsFalse(myAsserts.StringEquals("TestStepName 18", "Hejsa", "hejsa")); Assert.IsTrue(myAsserts.StringNotEquals("TestStepName 19", "Hejsa", "hejsa")); Assert.IsFalse(myAsserts.StringNotEquals("TestStepName 20", "Hejsa", "Hejsa")); Assert.IsTrue(myAsserts.StringEqualsCi("TestStepName 21", "Hejsa", "hejsa")); Assert.IsFalse(myAsserts.StringEqualsCi("TestStepName 22", "Hejsa", "hej")); Assert.IsTrue(myAsserts.StringNotEqualsCi("TestStepName 23", "Hejsa", "hejs")); Assert.IsFalse(myAsserts.StringNotEqualsCi("TestStepName 24", "Hejsa", "hejsa")); Assert.IsTrue(myAsserts.StringEmpty("TestStepName 25", string.Empty)); Assert.IsFalse(myAsserts.StringEmpty("TestStepName 26", "Hejsa")); Assert.IsTrue(myAsserts.StringNotEmpty("TestStepName 27", "Hejsa")); Assert.IsFalse(myAsserts.StringNotEmpty("TestStepName 28", string.Empty)); }
public void TestMethodAssertIsObject() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAssertIsObject.html" }; var myAsserts = new StfAssert(myLogger); myAsserts.EnableNegativeTesting = true; Assert.IsFalse(myAsserts.AssertIsObject("An integer", 1)); Assert.IsTrue(myAsserts.AssertIsObject("A string", "1")); Assert.IsTrue(myAsserts.AssertIsObject("An object", new object())); Assert.IsTrue(myAsserts.AssertIsObject("An object", myAsserts)); Assert.IsFalse(myAsserts.AssertIsObject("null", null)); }
public void TestMethodLotsOfEntries() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodLotsOfEntries.html", LogLevel = LogLevel.Internal }; for (int i = 0; i < 75; i++) { myLogger.LogInfo(string.Format("LogInfo Nr {0}", i)); } myLogger.CloseLogFile(); }
public void TestMethodCallStack() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodCallStack.html", LogLevel = LogLevel.Internal }; myLogger.LogInfo("NameOfFunction_L0A"); myLogger.LogInfo("NameOfFunction_L0B"); myLogger.LogFunctionEnter(LogLevel.Info, "Int", "NameOfFunction_L1"); myLogger.LogInfo("NameOfFunction_L1A"); myLogger.LogInfo("NameOfFunction_L1B"); myLogger.LogFunctionEnter(LogLevel.Info, "Int", "NameOfFunction_L2"); myLogger.LogInfo("NameOfFunction_L2A"); myLogger.LogInfo("NameOfFunction_L2B"); myLogger.LogFunctionEnter(LogLevel.Info, "Int", "NameOfFunction_L3"); myLogger.LogInfo("NameOfFunction_L3A"); myLogger.LogInfo("NameOfFunction_L3B"); myLogger.LogFunctionExit(LogLevel.Info, "NameOfFunction_L3"); myLogger.LogInfo("NameOfFunction_L2A"); myLogger.LogInfo("NameOfFunction_L2B"); myLogger.LogFunctionExit(LogLevel.Info, "NameOfFunction_L2"); myLogger.LogInfo("NameOfFunction_L1A"); myLogger.LogInfo("NameOfFunction_L1B"); myLogger.LogFunctionEnter(LogLevel.Info, "Int", "NameOfFunction_L2"); myLogger.LogInfo("NameOfFunction_L2A"); myLogger.LogInfo("NameOfFunction_L2B"); myLogger.LogFunctionExit(LogLevel.Info, "NameOfFunction_L2"); myLogger.LogInfo("NameOfFunction_L1A"); myLogger.LogInfo("NameOfFunction_L1B"); myLogger.LogFunctionExit(LogLevel.Info, "NameOfFunction_L1"); myLogger.LogInfo("NameOfFunction_L0A"); myLogger.LogInfo("NameOfFunction_L0B"); }
public void TestMethodAssertFolderNotExists() { const string UnitTestDir = @"c:\temp\TestMethodAssertFolderNotExists"; var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_AssertFolderNotExists.html" }; var myAsserts = new StfAssert(myLogger); myAsserts.EnableNegativeTesting = true; if (Directory.Exists(UnitTestDir)) { Directory.Delete(UnitTestDir); } Assert.IsTrue(myAsserts.AssertFolderNotExists("TestStepName 1", UnitTestDir)); var testDir = Directory.CreateDirectory(UnitTestDir); Assert.IsFalse(myAsserts.AssertFolderNotExists("TestStepName 2", UnitTestDir)); }
public void TestMethodAllLogType() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAllLogType.html", LogLevel = LogLevel.Internal }; myLogger.LogError("LogError"); myLogger.LogWarning("LogWarning"); myLogger.LogInfo("LogInfo"); myLogger.LogDebug("LogDebug"); // normal logging functions - models and adapters myLogger.LogTrace("LogTrace"); myLogger.LogInternal("LogInternal"); // Header logging functions - testscripts myLogger.LogHeader("LogHeader"); myLogger.LogSubHeader("LogSubHeader"); myLogger.LogFunctionEnter(LogLevel.Info, "Int", "NameOfFunction", new[] { "arg1", "arg2" }, new object[] { null }); myLogger.LogFunctionExit(LogLevel.Info, "NameOfFunction", 42); myLogger.LogFunctionEnter(LogLevel.Info, "Int", "NameOfFunctionShort"); myLogger.LogFunctionExit(LogLevel.Info, "NameOfFunctionShort"); // used solely by Assert functions myLogger.LogPass("testStepName LogPass", "LogPass"); myLogger.LogFail("testStepName LogFail", "LogFail"); myLogger.LogKeyValue("SomeKey", "SomeValue", "LogKeyValue"); myLogger.LogGet(LogLevel.Info, "MyTestProperty", myLogger); myLogger.LogSet(LogLevel.Info, "MyTestProperty", myLogger); myLogger.LogAutomationIdObject(LogLevel.Internal, myLogger, "Using myLogger as AID for test"); myLogger.SetRunStatus(); }
public void TestMethodAssertIsInstanceOf() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAssertIsInstanceOf.html" }; var myAsserts = new StfAssert(myLogger); myAsserts.EnableNegativeTesting = true; Assert.IsFalse(myAsserts.AssertIsInstanceOf("An integer", 1, Type.GetType("int"))); Assert.IsTrue(myAsserts.AssertIsInstanceOf("A string", "1", Type.GetType(typeof(string).FullName))); Assert.IsTrue(myAsserts.AssertIsInstanceOf("An object", new object(), Type.GetType(typeof(object).FullName))); Assert.IsFalse(myAsserts.AssertIsInstanceOf("null", null, null)); /* * TODO: Have no idea why this fails? * Assert.IsTrue(myAsserts.AssertIsInstanceOf("An object", myAsserts, Type.GetType(typeof(StfAssert).FullName))); * * typeof(StfAssert).FullName returns null? * */ }
public void TestMethodAsserts() { var myLogger = new Stf.Utilities.StfLogger { FileName = @"c:\temp\unittestlogger_TestMethodAsserts.html", LogLevel = LogLevel.Internal }; var myAsserter = new StfAssert { AssertLogger = myLogger, EnableNegativeTesting = true }; myAsserter.AssertTrue("True Value for AssertTrue", true); myAsserter.AssertTrue("False Value for AssertTrue", false); myAsserter.AssertTrue("2 > 3 Value for AssertTrue", 2 > 3); myAsserter.AssertTrue("3 > 2 Value for AssertTrue", 3 > 2); myAsserter.AssertFalse("True Value for AssertFalse", true); myAsserter.AssertFalse("False Value for AssertFalse", false); myAsserter.AssertFalse("2 > 3 Value for AssertFalse", 2 > 3); myAsserter.AssertFalse("3 > 2 Value for AssertFalse", 3 > 2); }
/// <summary> /// Initializes a new instance of the <see cref="StfAssert"/> class. /// </summary> /// <param name="logger"> /// The logger. /// </param> public StfAssert(StfLogger logger) : this() { AssertLogger = logger; }
public void TestConstructor() { var myLoggerByConstructor = new Stf.Utilities.StfLogger(@"c:\temp\unittestlogger_TestLogFileWriterByConstructor.html"); myLoggerByConstructor.CloseLogFile(); }