Class TypeBehavior
Xunit test assertions that may be helpful in testing generic type behavior.
Inheritance
Namespace: LaunchDarkly.TestHelpers
Assembly: LaunchDarkly.TestHelpers.dll
Syntax
public static class TypeBehavior : Object
Methods
AssertEqual<T>(T, T)
Asserts that the values are commutatively equal with Equal(), and that their hash codes are equal.
Declaration
public static void AssertEqual<T>(T a, T b)
Parameters
| Type | Name | Description |
|---|---|---|
| T | a | a value |
| T | b | another value |
Type Parameters
| Name | Description |
|---|---|
| T | the type of the values |
AssertNotEqual<T>(T, T)
Asserts that the values are commutatively unequal with Equal(). The hash codes do not have to be unequal.
Declaration
public static void AssertNotEqual<T>(T a, T b)
Parameters
| Type | Name | Description |
|---|---|---|
| T | a | a value |
| T | b | another value |
Type Parameters
| Name | Description |
|---|---|
| T | the type of the values |
CheckEqualsAndHashCode<T>(Func<T>[])
Implements a standard test suite for custom implementations of Equals()
and GetHashCode().
Declaration
public static void CheckEqualsAndHashCode<T>(params Func<T>[] valueFactories)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Func<T>[] | valueFactories | list of factories for distinct values |
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
The valueFactories parameter is a list of value factories. Each
factory must produce only instances that are equal to each other, and not equal to
the instances produced by any of the other factories. The test suite verifies the
following:
ValueFactoryFromInstances<T>(T[])
Creates a factory that returns the specified instances in order each time it is called. After all instances are used, it starts over at the first.
Declaration
public static Func<T> ValueFactoryFromInstances<T>(params T[] values)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | values | instances of the value |
Returns
| Type | Description |
|---|---|
| System.Func<T> | a factory function |
Type Parameters
| Name | Description |
|---|---|
| T | the value type |
Remarks
This is for use with CheckEqualsAndHashCode<T>(Func<T>[]).