public void AreEqual <T>(Expression <Func <T> > propertyExpression, T expectedValue) { if (propertyExpression == null) { throw new ArgumentNullException(nameof(propertyExpression)); } var expressionPath = ExpressionPath.Create(propertyExpression.Body); var actualValue = (T)(expressionPath.Result); if (!EqualityComparer <T> .Default.Equals(actualValue, expectedValue)) { var message = string.Format(ToStringFormatter, NotEqualMessagePattern, _pathManager.GetPath(expressionPath), expectedValue, actualValue); Assert.Fail(message); } }
public void IsNotNull <T>(Expression <Func <T> > propertyExpression) where T : class { if (propertyExpression == null) { throw new ArgumentNullException(nameof(propertyExpression)); } var expressionPath = ExpressionPath.Create(propertyExpression.Body); var actualValue = (T)(expressionPath.Result); if (actualValue == null) { var message = string.Format(ToStringFormatter, IsNullPattern, _pathManager.GetPath(expressionPath)); Assert.Fail(message); } }
public T StepInto <T>(Expression <Func <T> > propertyExpression, bool assertNotNull = true) { if (propertyExpression == null) { throw new ArgumentNullException(nameof(propertyExpression)); } _pathManager.Add(ExpressionPath.Create(propertyExpression.Body)); var result = (T)_pathManager.Result; if (assertNotNull && EqualityComparer <T> .Default.Equals(result, default(T))) { Assert.Fail(IsNullPattern, _pathManager.GetPath(null)); } return(result); }