StringAssert.Matches 方法 (String, Regex, String, array<Object )

验证指定的字符串是否与正则表达式匹配。 断言失败时将显示一则消息,并向该消息应用指定的格式。

命名空间:  Microsoft.VisualStudio.TestTools.UnitTesting
程序集:  Microsoft.VisualStudio.QualityTools.UnitTestFramework(在 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 中)

语法

声明
Public Shared Sub Matches ( _
    value As String, _
    pattern As Regex, _
    message As String, _
    ParamArray parameters As Object() _
)
public static void Matches(
    string value,
    Regex pattern,
    string message,
    params Object[] parameters
)
public:
static void Matches(
    String^ value, 
    Regex^ pattern, 
    String^ message, 
    ... array<Object^>^ parameters
)
static member Matches : 
        value:string * 
        pattern:Regex * 
        message:string * 
        parameters:Object[] -> unit 
public static function Matches(
    value : String, 
    pattern : Regex, 
    message : String, 
    ... parameters : Object[]
)

参数

  • value
    类型:System.String
    应与 pattern 匹配的字符串。
  • message
    类型:System.String
    断言失败时显示的消息。在单元测试结果中可以看到此消息。
  • parameters
    类型:array<System.Object[]
    设置 message 格式时使用的参数的数组。

异常

异常 条件
AssertFailedException

value 与 pattern 不匹配。

备注

如果字符串与表达式不匹配,则断言失败。

.NET Framework 安全性

请参见

参考

StringAssert 类

Matches 重载

Microsoft.VisualStudio.TestTools.UnitTesting 命名空间