Assert.Scope Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a new assertion scope that collects assertion failures instead of throwing them immediately. When the returned scope is disposed, all collected failures are thrown as a single AssertFailedException.
public static IDisposable Scope();
[System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")]
public static IDisposable Scope();
static member Scope : unit -> IDisposable
[<System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")>]
static member Scope : unit -> IDisposable
Public Shared Function Scope () As IDisposable
Returns
An IDisposable representing the assertion scope.
- Attributes
Examples
using (Assert.Scope())
{
Assert.AreEqual(1, 2); // collected, not thrown
Assert.IsTrue(false); // collected, not thrown
}
// AssertFailedException is thrown here with all collected failures.