Synergex.TestFramework.Assert

WSupported on Windows

 

 

 

namespace Synergex.TestFramework
public static class Assert

The Synergex.TestFramework.Assert class includes methods you can use to test various conditions in unit tests for traditional Synergy projects. If the condition being tested by an Assert method call is not met, an exception is thrown (Synergex.TestFramework.AssertFailedException or Synergex.TestFramework.AssertInconclusiveException). The Synergex.TestFramework.Assert class is modeled after Microsoft’s Assert class (see learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.assert), but there are differences. Note the following:

Assert.AreEqual(string1, string2, "Message takes {0} arguments [{1},{2}]. {3,10}", 4, 2, 3, "fourth")

See Unit testing for traditional Synergy for more information on traditional Synergy unit testing.

Methods

AreEqual

public static AreEqual(expectedObj, actualObj)
public static AreEqual(expectedObj, actualObj, message[, parameters]) 
public static AreEqual(expectedNum, actualNum)
public static AreEqual(expectedNum, actualNum, delta)
public static AreEqual(expectedNum, actualNum, delta, message[, parameters])
public static AreEqual(expectedStr, actualStr, ignoreCase)
public static AreEqual(expectedStr, actualStr, ignoreCase, message[, parameters])

Tests whether the specified objects, numbers, or strings are equal or whether specified numbers are within an allowed difference (delta) of each other. An exception is thrown if the test fails—i.e., if they are not equal or within the allowed difference. If the test fails, a message is displayed in the test results. If message is passed, that string is used for the failure message.

expectedObj, expectedNum, expectedStr

The object, numeric value, or string that the test expects. (@Object, n, System.String)

actualObj, actualNum, actualStr

The object, numeric value, or string that the tested code produces. (@Object, n, System.String)

message

A string that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used (for example, “Objects are not equal”). (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

delta

A numeric value specifying the required accuracy of a numeric comparison (i.e., an allowed difference between expectedNum and actualNum). For example, if delta is 2, the values 8 and 6 are considered equal, but 8 and 5 are not. If delta is 0, the test succeeds only if the values are equal. (n)

ignoreCase

A Boolean value specifying case-insensitive (true) or case-sensitive (false) comparison. (boolean)

AreNotEqual

public static AreNotEqual(notExpectedObj, actualObj) 
public static AreNotEqual(notExpectedObj, actualObj, message[, parameters]) 
public static AreNotEqual(notExpectedNum, actualNum) 
public static AreNotEqual(notExpectedNum, actualNum, delta) 
public static AreNotEqual(notExpectedNum, actualNum, delta, message[, parameters])
public static AreNotEqual(notExpectedStr, actualStr, ignorecase)
public static AreNotEqual(notExpectedStr, actualStr, ignorecase, message[, parameters]) 

Tests whether the specified objects, numbers, or strings are not equal or whether specified numbers are not within an allowed difference (delta) of each other. An exception is thrown if the test fails—i.e., if they are equal or within the allowed difference. If the test fails, a message is displayed in the test results. If message is passed, that string is used for the failure message.

notExpectedObj, notExpectedNum, notExpectedStr

The object, numeric value, or string that is expected to be different than actualObj, actualNum, or actualStr. (@Object, n, System.String)

actualObj, actualNum, actualStr

The object, numeric value, or string that the tested code produces. (@Object, n, System.String)

message

A message that is displayed in unit test results if the test fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

delta

A numeric value specifying the required accuracy (i.e., an allowed difference) between notExpectedNum and actualNum. For example, if delta is 2, the values 8 and 6 are considered equal, but 8 and 5 are not. If delta is 0, the test succeeds only if the values are equal. (n)

ignoreCase

A Boolean value specifying case-insensitive (true) or case-sensitive (false) comparison. (boolean)

AreNotSame

public static AreNotSame(notExpectedObj, actualObj) 
public static AreNotSame(notExpectedObj, actualObj, message[, parameters]) 

Tests whether the specified object variables refer to different objects. If they refer to the same object, the test fails. If the test fails, an exception is thrown and a message is displayed in the test results. If message is passed, that string is used for the failure message.

notExpectedObj

The object that is expected to be different than actualObj. (@Object)

actualObj

The object that the tested code produces. (@Object)

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

AreSame

public static AreSame(expectedObj, actualObj) 
public static AreSame(expectedObj, actualObj, message[, parameters]) 

Tests whether the specified object variables refer to the same object. The assertion fails if they refer to different objects. If the assertion fails, an exception is thrown and a message is displayed in the test results. If message is passed, that string is used for the failure message.

expectedObj

The object that is expected to be the same as actualObj. (@Object)

actualObj

The object that the tested code produces. (@Object)

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

Fail

public static Fail()
public static Fail(message[, parameters])

Throws AssertFailedException without any test (without checking conditions) and displays a failure message in test results. If message is passed, that string is used for the failure message.

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

Inconclusive

public static Inconclusive() 
public static Inconclusive(message[, parameters]) 

Throws AssertInconclusiveException without any test (without checking conditions) and displays a failure message in test results. If message is passed, that string is used for the failure message.

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

IsFalse

public static IsFalse(condition) 
public static IsFalse(condition, message[, parameters]) 

Tests whether the specified condition is false. If the condition is true, the test fails, an exception is thrown, and a message is displayed in test results. If message is passed, that string is used for the failure message.

condition

The condition to test. (boolean)

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

IsNotNull

public static IsNotNull(object) 
public static IsNotNull(object, message[, parameters]) 

Tests whether the specified object is not null. If it is null, the test fails, an exception is thrown, and a message is displayed in the test results. If message is passed, that string is used for the failure message.

object

An object. (@Object)

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

IsNull

public static IsNull(object) 
public static IsNull(object, message[, parameters]) 

Tests whether the specified object is null. If it is not null, the test fails, an exception is thrown, and a message is displayed in test results. If message is passed, that string is used for the failure message.

object

An object. (@Object)

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)

ReplaceNullChars

public static ReplaceNullChars(originalString), System.String

Replaces null characters (‘\0’) in a string with “\\0” and returns the resulting string (System.String).

originalString

The string whose null characters (‘\0’) will be converted to “\\0”. (System.String)

IsTrue

public static IsTrue(condition) 
public static IsTrue(condition, message[, parameters]) 

Tests whether the specified condition is true. If the condition is false, the test fails, an exception is thrown, and a message is displayed in test results. If message is passed, that string is used for the failure message.

condition

The condition to test. (boolean)

message

A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)

parameters

String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)