/// <inheritdoc /> public IAndContentTestBuilder Content(Func <string, bool> predicate) { var contentResult = InvocationResultValidator.GetInvocationResult <ContentResult>(this.TestContext); var actualContent = contentResult.Content; if (!predicate(actualContent)) { throw ContentResultAssertionException.ForPredicate( this.TestContext.ExceptionMessagePrefix, actualContent); } return(new ContentTestBuilder(this.TestContext)); }
/// <inheritdoc /> public IAndContentTestBuilder Content(string content) { var contentResult = InvocationResultValidator.GetInvocationResult <ContentResult>(this.TestContext); var actualContent = contentResult.Content; if (content != contentResult.Content) { throw ContentResultAssertionException.ForEquality( this.TestContext.ExceptionMessagePrefix, content, actualContent); } return(new ContentTestBuilder(this.TestContext)); }
/// <summary> /// Tests whether the <see cref="Microsoft.AspNetCore.Mvc.ContentResult"/> /// has content passing the given predicate. /// </summary> /// <param name="contentTestBuilder"> /// Instance of <see cref="IContentTestBuilder"/> type. /// </param> /// <param name="predicate">Predicate testing the content.</param> /// <returns>The same <see cref="IAndContentTestBuilder"/>.</returns> public static IAndContentTestBuilder WithContent( this IContentTestBuilder contentTestBuilder, Func <string, bool> predicate) { var actualBuilder = (ContentTestBuilder)contentTestBuilder; var actualContent = actualBuilder.ActionResult.Content; if (!predicate(actualContent)) { throw ContentResultAssertionException.ForPredicate( actualBuilder.TestContext.ExceptionMessagePrefix, actualContent); } return(actualBuilder); }
/// <summary> /// Tests whether the <see cref="Microsoft.AspNetCore.Mvc.ContentResult"/> /// has the same content as the provided one. /// </summary> /// <param name="contentTestBuilder"> /// Instance of <see cref="IContentTestBuilder"/> type. /// </param> /// <param name="content">Expected content as string.</param> /// <returns>The same <see cref="IAndContentTestBuilder"/>.</returns> public static IAndContentTestBuilder WithContent( this IContentTestBuilder contentTestBuilder, string content) { var actualBuilder = (ContentTestBuilder)contentTestBuilder; var actualContent = actualBuilder.ActionResult.Content; if (content != actualContent) { throw ContentResultAssertionException.ForEquality( actualBuilder.TestContext.ExceptionMessagePrefix, content, actualContent); } return(actualBuilder); }