Example #1
0
        private static IEnumerable<string> GetSetups(string f, Fields x, FieldsSetups y)
        {
            var methodSymbol = x.MethodOrPropertySymbol as IMethodSymbol;

            if (methodSymbol != null)
            {
                //todo: determine the generic replacements correctly by semantic model from sut

                var returnType = GetReplacedType(methodSymbol.ReturnType, y.Substitutions, y.SutSubstitutions);

                return new[]
                {
                    f + ".#ToReplace#(x => x." +
                    GetMethodName(methodSymbol, y.Substitutions, y.SutSubstitutions) + "(" +
                    Join(", ", methodSymbol.Parameters.Select(z => "It.Is<" +
                                                                          GetReplacedType(z.Type, y.Substitutions,
                                                                              y.SutSubstitutions) +
                                                                          ">(" + z.Name + " => " + z.Name +
                                                                          " == default(" +
                                                                          GetReplacedType(z.Type, y.Substitutions,
                                                                              y.SutSubstitutions) +
                                                                          "))")) + "))" +
                    (methodSymbol.ReturnType.ToDisplayString() != "void" //todo: to rigth determine generic return type
                        ? ".Returns(default(" + returnType + "))"
                        : "")
                };
            }

            var propertySymbol = (IPropertySymbol)x.MethodOrPropertySymbol;

            var expressions = new List<string>();

            if (!propertySymbol.IsWriteOnly && !x.Expression.IsLeftSideOfAssignExpression())
            {
                var getExpression = f + ".#ToReplaceGet#(x => x." + propertySymbol.Name + ").Returns(default(" +
                                    GetReplacedType(propertySymbol.Type, y.Substitutions, y.SutSubstitutions) + "))";

                expressions.Add(getExpression);
            }

            if (propertySymbol.IsReadOnly || !x.Expression.IsLeftSideOfAssignExpression()) return expressions;

            var setExpression = f + ".#ToReplaceSet#(x => x." + propertySymbol.Name + " = default(" +
                                GetReplacedType(propertySymbol.Type, y.Substitutions, y.SutSubstitutions) + "))";

            expressions.Add(setExpression);

            return expressions;
        }
Example #2
0
 private static bool IsExistInSetups(Fields fields, IEnumerable<TreeNode<DependencyField>> injectedFields)
 {
     return injectedFields.Any(x => x.FindTreeNodes(y => y.Parent != null
                                                         && IsMemberEquals(fields.MethodOrPropertySymbol, y.Data.SetupIdentifierNode?.Name)
                                                         && fields.FieldsToSetup.Any(z => z.Field.Any(w => y.Parent.Data.Field.Declaration.Variables.Any(t => t.Identifier.Text == w)))).Any());
 }