# Assertions

Kind: Class · Namespace: Sansar.Script.Testing · Assembly: Sansar.Script.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Script.Testing">Namespace <a href="/scripting/api/sansar.script.testing"><code>Sansar.Script.Testing</code></a></span>
</div>

<span id="T:Sansar.Script.Testing.Assertions"></span>

Contains various test methods which throw exceptions if the conditions are false.

```csharp
public static class Assertions
```

## Remarks

This class is restricted and may not be included in scripts for sale in the marketplace. All APIs are subject to change.

## Members at a glance

| Kind | Members |
|---|---|
| **Properties** | [LogSuccessful](#logsuccessful) |
| **Methods** | [AlmostEqual](#almostequal) · [Equal](#equal) · [Fail](#fail) · [Greater](#greater) · [NotEqual](#notequal) · [NotNull](#notnull) · [Null](#null) · [NullOrMissing](#nullormissing) · [True](#true) · [Type](#type) |

## Properties

### LogSuccessful

<div class="api-card">
<span id="P:Sansar.Script.Testing.Assertions.LogSuccessful"></span>

```csharp signature
public static bool LogSuccessful { get; set; }
```

Enables or disables logging of successful assertion diagnostic messages.

<details class="api-remarks"><summary>Remarks</summary>

This can be used to trace test execution.

</details>

</div>


## Methods

### AlmostEqual

<div class="api-card" id="almostequal-quaternion-quaternion-int32-string-string-string-int32">
<span id="M:Sansar.Script.Testing.Assertions.AlmostEqual(Sansar.Quaternion,Sansar.Quaternion,System.Int32,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void AlmostEqual(
    Sansar.Quaternion a,
    Sansar.Quaternion b,
    int significantFigures,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the two Quaternions are not approximately equal.

| Parameter | Type | Description |
|---|---|---|
| `a` | [Sansar.Quaternion](/scripting/api/sansar/quaternion) | The first Quaternion to check. |
| `b` | [Sansar.Quaternion](/scripting/api/sansar/quaternion) | The second Quaternion to check. |
| `significantFigures` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of significant digits to compare |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

<div class="api-card" id="almostequal-vector-vector-int32-string-string-string-int32">
<span id="M:Sansar.Script.Testing.Assertions.AlmostEqual(Sansar.Vector,Sansar.Vector,System.Int32,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void AlmostEqual(
    Sansar.Vector a,
    Sansar.Vector b,
    int significantFigures,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the two vectors are not approximately equal.

| Parameter | Type | Description |
|---|---|---|
| `a` | [Sansar.Vector](/scripting/api/sansar/vector) | The first vector to check. |
| `b` | [Sansar.Vector](/scripting/api/sansar/vector) | The second vector to check. |
| `significantFigures` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of significant digits to compare |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

<div class="api-card" id="almostequal-single-single-int32-string-string-string-int32">
<span id="M:Sansar.Script.Testing.Assertions.AlmostEqual(System.Single,System.Single,System.Int32,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void AlmostEqual(
    float a,
    float b,
    int significantFigures,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the two floats are not approximately equal.

| Parameter | Type | Description |
|---|---|---|
| `a` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The first float to check. |
| `b` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The second float to check. |
| `significantFigures` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of significant digits to compare |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### Equal

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.Equal``1(``0,``0,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void Equal<T>(
    T a,
    T b,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
) where T : IComparable
```

Throws an exception if the passed objects do not compare as equal via [`IComparable.CompareTo`](https://learn.microsoft.com/dotnet/api/system.icomparable.compareto). Will NOT throw if both objects are null.

| Parameter | Type | Description |
|---|---|---|
| `a` | T | The first object to check. |
| `b` | T | The second object to check. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

**Type parameters:** `T`: The type of the objects.

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### Fail

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.Fail(System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void Fail(
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception always.

| Parameter | Type | Description |
|---|---|---|
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### Greater

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.Greater``1(``0,``0,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void Greater<T>(
    T a,
    T b,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
) where T : IComparable
```

Throws an exception if the first object does not compare as greater via [`IComparable.CompareTo`](https://learn.microsoft.com/dotnet/api/system.icomparable.compareto).

| Parameter | Type | Description |
|---|---|---|
| `a` | T | The first object to check. |
| `b` | T | The second object to check. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

**Type parameters:** `T`: The type of the objects.

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### NotEqual

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.NotEqual``1(``0,``0,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void NotEqual<T>(
    T a,
    T b,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
) where T : IComparable
```

Throws an exception if the passed objects compare as equal via [`IComparable.CompareTo`](https://learn.microsoft.com/dotnet/api/system.icomparable.compareto).

| Parameter | Type | Description |
|---|---|---|
| `a` | T | The first object to check. |
| `b` | T | The second object to check. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

**Type parameters:** `T`: The type of the objects.

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### NotNull

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.NotNull(System.Object,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void NotNull(
    object val,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the passed argument is not null.

| Parameter | Type | Description |
|---|---|---|
| `val` | [object](https://learn.microsoft.com/dotnet/api/system.object) | The value that must be null. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### Null

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.Null(System.Object,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void Null(
    object val,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the passed argument is not null.

| Parameter | Type | Description |
|---|---|---|
| `val` | [object](https://learn.microsoft.com/dotnet/api/system.object) | The value that must be null. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### NullOrMissing

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.NullOrMissing(System.String,System.String,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void NullOrMissing(
    string message,
    string contents,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the message is non-null and contains the contents substring.

| Parameter | Type | Description |
|---|---|---|
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to check. |
| `contents` | [string](https://learn.microsoft.com/dotnet/api/system.string) | A substring to check. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### True

<div class="api-card">
<span id="M:Sansar.Script.Testing.Assertions.True(System.Boolean,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void True(
    bool val,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the passed argument is false.

| Parameter | Type | Description |
|---|---|---|
| `val` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | The value that must be true. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

### Type

<div class="api-card" id="type-string-object-string-string-string-int32">
<span id="M:Sansar.Script.Testing.Assertions.Type(System.String,System.Object,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void Type(
    string typename,
    object obj,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the [`Type.FullName`](https://learn.microsoft.com/dotnet/api/system.type.fullname) of the passed object does not match the passed typename.

| Parameter | Type | Description |
|---|---|---|
| `typename` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The expected typename. |
| `obj` | [object](https://learn.microsoft.com/dotnet/api/system.object) | The object to check. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>

<div class="api-card" id="type-object-string-string-string-int32">
<span id="M:Sansar.Script.Testing.Assertions.Type``1(System.Object,System.String,System.String,System.String,System.Int32)"></span>

```csharp signature
public static void Type<T>(
    object obj,
    string diagnostic,
    [System.Runtime.CompilerServices.CallerMemberName] string memberName,
    [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath,
    [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber
)
```

Throws an exception if the passed type is not of the same type as the type param or if the obj is null.

| Parameter | Type | Description |
|---|---|---|
| `obj` | [object](https://learn.microsoft.com/dotnet/api/system.object) | The object to check. |
| `diagnostic` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Optional string to show with a faulure exception. |
| `memberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceFilePath` | [string](https://learn.microsoft.com/dotnet/api/system.string) | generated by the compiler |
| `sourceLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | generated by the compiler |

**Type parameters:** `T`: The type to confirm.

<details class="api-remarks"><summary>Remarks</summary>

The method is restricted. The method is subject to change or removal at any time and may not be included in scripts for sale in the marketplace.

</details>

</div>




<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>