Exemple #1
0
        private ConditionType?GetAssertionConditionAnnotationConditionType(IParameter parameter)
        {
            var assertionConditionType = _assertionConditionAnnotationProvider.GetInfo(parameter);

            switch (assertionConditionType)
            {
            case AssertionConditionType.IS_TRUE:
            case AssertionConditionType.IS_FALSE: return(ConditionType.TrueOrFalseCheck);

            case AssertionConditionType.IS_NULL:
            case AssertionConditionType.IS_NOT_NULL: return(ConditionType.NullEqualityCheck);
            }

            return(null);
        }
        public static AssertionStatement TryFromInvocationExpression(
            [NotNull] IInvocationExpression invocationExpression,
            [NotNull] AssertionMethodAnnotationProvider assertionMethodAnnotationProvider,
            [NotNull] AssertionConditionAnnotationProvider assertionConditionAnnotationProvider)
        {
            if (invocationExpression.Reference.Resolve().DeclaredElement is IMethod method && assertionMethodAnnotationProvider.GetInfo(method))
            {
                foreach (var parameter in method.Parameters)
                {
                    Debug.Assert(parameter != null);

                    var parameterAssertionCondition = assertionConditionAnnotationProvider.GetInfo(parameter);

                    if (parameterAssertionCondition == null && parameter.Type.IsBool())
                    {
                        parameterAssertionCondition = AssertionConditionType.IS_TRUE;
                    }

                    if (parameterAssertionCondition != null)
                    {
                        var argument = invocationExpression.ArgumentList?.Arguments.FirstOrDefault(
                            a =>
                        {
                            Debug.Assert(a != null);
                            return(a.MatchingParameter != null && a.MatchingParameter.Element.ShortName == parameter.ShortName);
                        });
                        if (argument?.Value != null)
                        {
                            return(new AssertionStatement(invocationExpression, (AssertionConditionType)parameterAssertionCondition, argument.Value));
                        }
                    }
                }
            }

            return(null);
        }