/// <summary> /// The assert pass. /// </summary> /// <param name="testStep"> /// The test step. /// </param> /// <param name="message"> /// The Message. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool AssertPass(string testStep, string message) { AssertLogger.LogPass(testStep, message); Stats.AssertPassCount++; return(true); }
/// <summary> /// Reset all statistics for Error, Warning, pass, fail, and inconclusive. Typically used when retry'ing stuff /// </summary> /// <returns>Success if able to reset stats</returns> public bool ResetStatistics() { Stats = new AssertStats(); AssertLogger.LogTrace("Statistics resat as requested"); AssertLogger.NumberOfLoglevelMessages[StfLogLevel.Error] = 0; AssertLogger.NumberOfLoglevelMessages[StfLogLevel.Warning] = 0; AssertLogger.NumberOfLoglevelMessages[StfLogLevel.Inconclusive] = 0; AssertLogger.NumberOfLoglevelMessages[StfLogLevel.Fail] = 0; AssertLogger.NumberOfLoglevelMessages[StfLogLevel.Pass] = 0; return(true); }
/// <summary> /// The is inconclusive. /// </summary> /// <param name="testStep"> /// The test Step. /// </param> /// <param name="message"> /// The message. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool IsInconclusive(string testStep, string message) { AssertLogger.LogInconclusive(testStep, message); Stats.AssertInconclusiveCount++; if (!enableNegativeTesting) { throw new AssertInconclusiveException(message); } return(true); }
/// <summary> /// The string contains. /// </summary> /// <param name="testStep"> /// The test step. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="substring"> /// The substring. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool StringContains(string testStep, string value, string substring) { var retVal = WrapperStringAsserts(StringAssertFunction.Contains, value, substring); if (retVal == null) { var message = string.Format("[{0}] contains [{1}]", value, substring); AssertLogger.LogPass(testStep, message); } else { AssertLogger.LogFail(testStep, retVal); } return(retVal == null); }
/// <summary> /// The string does not match. /// </summary> /// <param name="testStep"> /// The test step. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="pattern"> /// The pattern. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool StringDoesNotMatch(string testStep, string value, string pattern) { var retVal = WrapperStringAsserts(StringAssertFunction.DoesNotMatch, value, pattern); if (retVal == null) { var message = string.Format("[{0}] is not matched by [{1}]", value, pattern); AssertLogger.LogPass(testStep, message); } else { AssertLogger.LogFail(testStep, retVal); } return(retVal == null); }
/// <summary> /// Asserts that a string is Not (Null or Empty) /// </summary> /// <param name="testStep"> /// Name of the test step in the test script /// </param> /// <param name="actual"> /// Value that was actually experienced /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool StringNotEmpty(string testStep, string actual) { var retVal = !string.IsNullOrEmpty(actual); if (retVal) { var message = string.Format("String is not NullOrEmpty"); AssertLogger.LogPass(testStep, message); } else { var message = string.Format("[{0}] IS NullOrEmpty", actual); AssertLogger.LogFail(testStep, message); } return(retVal); }
/// <summary> /// Asserts that two values not are equal /// </summary> /// <param name="testStep"> /// Name of the test step in the test script /// </param> /// <param name="expected"> /// Value <c>expected</c> for the assert /// </param> /// <param name="actual"> /// Value that was actually experienced /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool StringNotEquals(string testStep, string expected, string actual) { bool retVal = expected != actual; if (retVal) { var message = string.Format("[{0}] is NOT equal to [{1}]", expected, actual); AssertLogger.LogPass(testStep, message); } else { var message = string.Format("[{0}] is equal to [{1}]", expected, actual); AssertLogger.LogFail(testStep, message); } return(retVal); }
/// <summary> /// The string does not ends with. /// </summary> /// <param name="testStep"> /// The test step. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="substring"> /// The substring. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool StringDoesNotEndsWith(string testStep, string value, string substring) { var retVal = WrapperStringAsserts(StringAssertFunction.EndsWith, value, substring); if (retVal != null) { var message = string.Format("[{0}] doesn't ends with [{1}]", value, substring); AssertLogger.LogPass(testStep, message); } else { var message = string.Format("[{0}] do ends with [{1}]", value, substring); AssertLogger.LogFail(testStep, message); } return(retVal != null); }
/// <summary> /// The assert fail. /// </summary> /// <param name="testStep"> /// The test step. /// </param> /// <param name="message"> /// The Message. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool AssertFail(string testStep, string message) { if (TreatFailsAsWarning) { AssertLogger.LogWarning(testStep, "TreatFailsAsWarning is true, so this AssertFail is not included in the error stats"); } else { Stats.AssertFailedCount++; } AssertLogger.LogFail(testStep, message); if (!EnableNegativeTesting) { throw new AssertFailedException(message); } return(true); }
/// <summary> /// The assert comare to. /// </summary> /// <param name="leftHandSide"> /// The left hand side. /// </param> /// <param name="rightHandSide"> /// The right hand side. /// </param> /// <param name="msg"> /// The msg. /// </param> /// <param name="compareVal"> /// The compare val. /// </param> /// <typeparam name="T1"> /// Type of the lefthandside /// </typeparam> /// <typeparam name="T2"> /// Type of the righthandside /// </typeparam> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool AssertCompareTo <T1, T2>(T1 leftHandSide, T2 rightHandSide, ref string msg, ref int compareVal) where T1 : IConvertible, IComparable where T2 : IConvertible, IComparable { if (msg == null) { return(false); } try { // convert val2 to type of val1. var rhsAsLhs = (T1)Convert.ChangeType(rightHandSide, typeof(T1)); compareVal = leftHandSide.CompareTo(rhsAsLhs); msg = string.Empty; return(true); } catch (Exception ex) { AssertLogger.LogTrace(ex.Message); } // if T2 cant convert to T1 perhaps T1 can convert to T2 try { // convert val1 to type of val2. var lhsAsRhs = (T2)Convert.ChangeType(leftHandSide, typeof(T2)); compareVal = rightHandSide.CompareTo(lhsAsRhs); msg = string.Empty; return(true); } catch (Exception ex) { msg = ex.Message; } return(false); }
public void TestMethod1() { AssertLogger.AssertWithLogs(() => Assert.IsTrue(false)); }