public static AndConstraint <ObjectAssertions> BeView(this ObjectAssertions assertions, Expression <Func <ViewResult, bool> > predicate = null) { var result = assertions.BeOfType <ViewResult>(); AssertViewResult(assertions, predicate); return(result); }
public static ExceptionAssertions <TException> Be <TException> (this ObjectAssertions objectAssertions) where TException : Exception { objectAssertions.BeOfType <TException>(); return(new ExceptionAssertions <TException>(new[] { (TException)objectAssertions.Subject })); }
public static object Model(this ObjectAssertions assertions) { assertions.BeOfType <ViewResult>(); var actionResult = (ViewResult)assertions.Subject; return(actionResult.Model); }
internal static void MatchLiteralValueOf(this ObjectAssertions statement, string expectedValue, Iri expectedDataType = null) { var isStatement = statement.BeOfType <Statement>(); isStatement.Which.Value.Should().Be(expectedValue); isStatement.Which.DataType.Should().Be(expectedDataType); }
public static AndConstraint <ObjectAssertions> HaveModelTypeOf <T>(this ObjectAssertions assertions) { var result = assertions.BeOfType <ViewResult>(); var actionResult = (ViewResult)assertions.Subject; actionResult.Model.Should().BeOfType <T>(); return(result); }
public static AndConstraint <ObjectAssertions> AssertViewDataType(this ObjectAssertions assertions, Func <ViewDataDictionary, bool> viewDataAssert) { var result = assertions.BeOfType <ViewResult>(); var actionResult = (ViewResult)assertions.Subject; viewDataAssert(actionResult.ViewData).Should().BeTrue(); return(result); }
public static AndConstraint <ObjectAssertions> BeRedirectToResult(this ObjectAssertions assertions, string redirect) { var result = assertions.BeOfType <RedirectResult>(); var actionResult = (RedirectResult)assertions.Subject; actionResult.Url.Should().Be(redirect); return(result); }
public static AndWhichConstraint <ObjectAssertions, KnownExpression> BeKnownExpression(this ObjectAssertions assertions, ExpressionType expressionType) { using var _ = new AssertionScope(); var result = assertions.BeOfType <KnownExpression>(); result.Subject.ExpressionType.Should().Be(expressionType); return(result); }
public static AndWhichConstraint <ObjectAssertions, Status> MatchModel(this ObjectAssertions assertions, Status expected) { using var _ = new AssertionScope(); var result = assertions.BeOfType <Status>(); result.Subject.Name.Should().Be(expected.Name); result.Subject.LastChecked.Should().Be(expected.LastChecked); return(result); }
public static AndWhichConstraint <ObjectAssertions, GeneratedAlwaysAsIdentity> MatchModel(this ObjectAssertions assertions, GeneratedAlwaysAsIdentity expected, int?num1 = null, int?num2 = null) { using var _ = new AssertionScope(); var result = assertions.BeOfType <GeneratedAlwaysAsIdentity>(); result.Subject.Num1.Should().Be(num1 ?? expected.Num1); result.Subject.Num2.Should().Be(num2 ?? expected.Num2); return(result); }
public static AndWhichConstraint <ObjectAssertions, Book> MatchModel(this ObjectAssertions assertions, Book expected) { using var _ = new AssertionScope(); var result = assertions.BeOfType <Book>(); result.Subject.Name.Should().Be(expected.Name); result.Subject.Genres.Should().Equal(expected.Genres); return(result); }
public static AndWhichConstraint <ObjectAssertions, ComputedColumn> MatchModel(this ObjectAssertions assertions, ComputedColumn expected, int?num2 = null, int?num3 = null) { using var _ = new AssertionScope(); var result = assertions.BeOfType <ComputedColumn>(); result.Subject.Num1.Should().Be(expected.Num1); result.Subject.Num2.Should().Be(num2 ?? expected.Num2); result.Subject.Num3.Should().Be(num3 ?? expected.Num3); return(result); }
public static void BeSuccessfullProcessResult(this ObjectAssertions assertions) { assertions.BeOfType <ProcessResult>(); var result = (ProcessResult)assertions.Subject; if (!result.IsSuccess) { throw new Exception($"Executable {result.ExecutablePath} returned code {result.Code}. Output: {result.Output}"); } }
public static void BeErrorResultWithMessages(this ObjectAssertions x, HttpStatusCode statusCode, params string[] errors) { var jsonResult = x.BeOfType <JsonResult>().Subject; jsonResult.Value.Should().BeEquivalentTo(new { messages = errors }); jsonResult.StatusCode.Should().Be((int)statusCode); }
public static AndWhichConstraint <ObjectAssertions, TestEntity> MatchModel(this ObjectAssertions assertions, TestEntity expected, int?num1 = null, int?num2 = null, int?numNullable = null, string text1 = null, string text2 = null) { using var _ = new AssertionScope(); var result = assertions.BeOfType <TestEntity>(); result.Subject.Num1.Should().Be(num1 ?? expected.Num1); result.Subject.Num2.Should().Be(num2 ?? expected.Num2); result.Subject.NumNullable1.Should().Be(numNullable ?? expected.NumNullable1); result.Subject.Text1.Should().Be(text1 ?? expected.Text1); result.Subject.Text2.Should().Be(text2 ?? expected.Text2); return(result); }
public static AndWhichConstraint <ObjectAssertions, PageVisit> MatchModel(this ObjectAssertions assertions, PageVisit expected, bool compareFirstVisit = true, int?expectedVisits = null) { using var _ = new AssertionScope(); var result = assertions.BeOfType <PageVisit>(); result.Subject.UserID.Should().Be(expected.UserID); result.Subject.Date.Should().Be(expected.Date); result.Subject.Visits.Should().Be(expectedVisits ?? expected.Visits); if (compareFirstVisit) { result.Subject.FirstVisit.Should().Be(expected.FirstVisit); } result.Subject.LastVisit.Should().Be(expected.LastVisit); return(result); }
public static AndWhichConstraint <ObjectAssertions, Country> MatchModel(this ObjectAssertions assertions, Country expected, bool compareCreated = true, bool compareUpdated = true) { using var _ = new AssertionScope(); var result = assertions.BeOfType <Country>(); result.Subject.ISO.Should().Be(expected.ISO); result.Subject.Name.Should().Be(expected.Name); if (compareCreated) { result.Subject.Created.Should().Be(expected.Created); } if (compareUpdated) { result.Subject.Updated.Should().Be(expected.Updated); } return(result); }
public static AndConstraint <ObjectAssertions> BeRedirectToAction(this ObjectAssertions assertions, string actionName, string controllerName = null, string area = null) { var result = assertions.BeOfType <RedirectToRouteResult>(); var actionResult = (RedirectToRouteResult)assertions.Subject; actionResult.RouteValues.Should().ContainKey("action"); actionResult.RouteValues["action"].Should().Be(actionName); if (controllerName != null) { actionResult.RouteValues.Should().ContainKey("controller"); actionResult.RouteValues["controller"].Should().Be(controllerName); } if (area != null) { actionResult.RouteValues.Should().ContainKey("area"); actionResult.RouteValues["area"].Should().Be(area); } return(result); }
public static void BeOkObjectEquivalentTo(this ObjectAssertions assertions, object expectation) { assertions.BeOfType <OkObjectResult>().Which.Value.Should().BeEquivalentTo(expectation); }
/// <summary> /// Safe cast object to {T}. /// </summary> public static T IsType <T>(this ObjectAssertions assert) { return(assert.BeOfType <T>().And.Subject.As <T>()); }
public static T CastTo <T>(this ObjectAssertions assertion) { assertion.BeOfType <T>(); return((T)assertion.Subject); }
public static void BeCreatedTokenResponse(this ObjectAssertions assertions) { assertions.BeOfType <CreatedResult>().Which.Value.ToString().Should().BeJwtToken(); }