Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }