Class StringConstraint
StringConstraint is the abstract base for constraints that operate on strings. It supports the IgnoreCase modifier for string operations.
Inheritance
Inherited Members
Namespace: NUnit.Framework.Constraints
Assembly: nunit.framework.dll
Syntax
public abstract class StringConstraint : Constraint, IConstraint, IResolveConstraint
Constructors
View SourceStringConstraint()
Constructs a StringConstraint without an expected value
Declaration
protected StringConstraint()
StringConstraint(string)
Constructs a StringConstraint given an expected value
Declaration
protected StringConstraint(string expected)
Parameters
| Type | Name | Description |
|---|---|---|
| string | expected | The expected value |
Fields
View SourcecaseInsensitive
Indicates whether tests should be case-insensitive
Declaration
protected bool caseInsensitive
Field Value
| Type | Description |
|---|---|
| bool |
descriptionText
Description of this constraint
Declaration
protected string descriptionText
Field Value
| Type | Description |
|---|---|
| string |
expected
The expected value
Declaration
protected readonly string expected
Field Value
| Type | Description |
|---|---|
| string |
Properties
View SourceDescription
The Description of what this constraint tests, for use in messages and in the ConstraintResult.
Declaration
public override string Description { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
View SourceIgnoreCase
Modify the constraint to ignore case in matching.
Declaration
public virtual StringConstraint IgnoreCase { get; }
Property Value
| Type | Description |
|---|---|
| StringConstraint |
Methods
View SourceApplyTo<TActual>(TActual)
Test whether the constraint is satisfied by a given value
Declaration
public override ConstraintResult ApplyTo<TActual>(TActual actual)
Parameters
| Type | Name | Description |
|---|---|---|
| TActual | actual | The value to be tested |
Returns
| Type | Description |
|---|---|
| ConstraintResult | True for success, false for failure |
Type Parameters
| Name | Description |
|---|---|
| TActual |
Overrides
View SourceMatches(string?)
Test whether the constraint is satisfied by a given string
Declaration
protected abstract bool Matches(string? actual)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to be tested |
Returns
| Type | Description |
|---|---|
| bool | True for success, false for failure |
Matches(string?, CultureInfo)
Test whether the constraint is satisfied by a given string with a specific culture
Declaration
protected virtual bool Matches(string? actual, CultureInfo cultureInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to be tested |
| CultureInfo | cultureInfo | The culture info to use for comparison |
Returns
| Type | Description |
|---|---|
| bool | True for success, false for failure |
Matches(string?, StringComparison)
Test whether the constraint is satisfied by a given string with a specific string comparison
Declaration
protected virtual bool Matches(string? actual, StringComparison stringComparison)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to be tested |
| StringComparison | stringComparison | The string comparison type to be used |
Returns
| Type | Description |
|---|---|
| bool | True for success, false for failure |
Using(CultureInfo)
Modify the constraint to use the specified culture info.
Declaration
public virtual StringConstraint Using(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| CultureInfo | culture |
Returns
| Type | Description |
|---|---|
| StringConstraint |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when a culture info was already set or when a comparison type was already set. |
Using(StringComparison)
Modify the constraint to use the specified comparison.
Declaration
public virtual StringConstraint Using(StringComparison comparisonType)
Parameters
| Type | Name | Description |
|---|---|---|
| StringComparison | comparisonType |
Returns
| Type | Description |
|---|---|
| StringConstraint |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when a comparison type was already set or when a culture info was already set. |